Skip to content

Commit

Permalink
Improved seat massager sample
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbeitz committed Mar 1, 2024
1 parent af28d1a commit d468089
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
8 changes: 1 addition & 7 deletions dtdl-tools/src/dtdl-validator/DtdlValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static string ConvertToDTMI(string dtdlFilePath, string dtdlDirPath, string exte
// Strip off the directory path and the extension.
string dtmiPath = dtdlFilePath.Substring(dtdlDirPath.Length + 1, dtdlFilePath.Length - dtdlDirPath.Length - extension.Length - 2);
// Replace each directory separator with a colon and the hyphen with a semicolon.
string dtmi = dtmiPath.Replace('/', ':').Replace('-', ';');
string dtmi = dtmiPath.Replace(Path.DirectorySeparatorChar, ':').Replace('-', ';');
return dtmi;
}

Expand Down Expand Up @@ -92,12 +92,6 @@ static int ValidateDtdl(DirectoryInfo dtdlDirectory, String extension)
}
failureOccured = true;
}
catch (ResolutionException ex)
{
Console.WriteLine($"{file} - failed");
Console.WriteLine($" {ex.ToString()}");
failureOccured = true;
}
catch (Exception ex)
{
Console.WriteLine($"{file} - failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class ModelsRepositoryClientExtensions
/// </summary>
/// <param name="modelRepoClient">The models repository client.</param>
/// <param name="dtmis"></param>
/// <param name="cancellationToken">The cancellation topken.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The model definitions for the provided DTMIs.</returns>
public static async IAsyncEnumerable<string> ParserDtmiResolverAsync(
this ModelsRepositoryClient modelRepoClient, IReadOnlyCollection<Dtmi> dtmis,
Expand Down
9 changes: 4 additions & 5 deletions samples/seat_massager/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ use serde_derive::{Deserialize, Serialize};

/// A targeted payload.
/// The targeting details helps on the receiver's side to dispatch the request.
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Debug)]
pub struct TargetedPayload {
/// The instance id for the target entity.
pub instance_id: String,
/// The path within the target enttity to member that we are targetting.
/// The path within the target entity to member that we are targeting.
pub member_path: String,
/// The operation to be performed on the target entity's member.
pub operation: String,
/// The operation's payload.
pub payload: String,
}


/// Status codes and messages.
/// Status codes and messages.
pub mod status {
pub mod ok {
pub const CODE: i32 = 200;
pub const MESSAGE: &str = "Ok";
}
}
}
20 changes: 11 additions & 9 deletions samples/seat_massager/provider/src/request_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT

use digital_twin_model::sdv_v2 as sdv;
use log::{debug, info, warn};
use log::{debug, error, info, warn};
use parking_lot::Mutex;
use samples_protobuf_data_access::async_rpc::v1::request::{
request_server::Request, AskRequest, AskResponse, NotifyRequest, NotifyResponse,
Expand Down Expand Up @@ -41,14 +41,15 @@ impl Request for RequestImpl {
info!("respond_uri: {respond_uri}");
info!("ask_id: {ask_id}");

let targetted_payload_json: TargetedPayload = serde_json::from_str(&payload).unwrap();
info!("instance_id: {}", targetted_payload_json.instance_id);
info!("member_path: {}", targetted_payload_json.member_path);
info!("operation: {}", targetted_payload_json.operation);
info!("inner payload: {}", targetted_payload_json.payload);
let targeted_payload_json: TargetedPayload = serde_json::from_str(&payload).unwrap();

info!("instance_id: {}", targeted_payload_json.instance_id);
info!("member_path: {}", targeted_payload_json.member_path);
info!("operation: {}", targeted_payload_json.operation);
info!("inner payload: {}", targeted_payload_json.payload);

let request_payload_json: serde_json::Value =
serde_json::from_str(&targetted_payload_json.payload)
serde_json::from_str(&targeted_payload_json.payload)
.map_err(|error| tonic::Status::invalid_argument(error.to_string()))?;

let type_id_json: serde_json::Value = request_payload_json.get("@type").unwrap().clone();
Expand All @@ -63,7 +64,7 @@ impl Request for RequestImpl {
tokio::spawn(async move {
let client_result = RespondClient::connect(respond_uri).await;
if let Err(error_message) = client_result {
warn!("Unable to connect due to {error_message}");
error!("Unable to connect due to {error_message}");
return;
}
let mut client = client_result.unwrap();
Expand All @@ -84,7 +85,8 @@ impl Request for RequestImpl {
tonic::Request::new(AnswerRequest { ask_id, payload: response_payload_json });
let response = client.answer(answer_request).await;
if let Err(status) = response {
warn!("Answer failed: {status:?}");
error!("Answer failed: {status:?}");
return;
}
});

Expand Down

0 comments on commit d468089

Please sign in to comment.