diff --git a/.gitignore b/.gitignore index 3066ef569f0272800ddb902222d19d5d738ac67b..48ab192130a8c3994cf4f013ea5c57ad7cb4e00b 100644 --- a/.gitignore +++ b/.gitignore @@ -246,3 +246,4 @@ ModelManifest.xml /Simulator/MODELS/ /MC_Backend_Win/MODELS /MC_Backend_Win/MODELI/Sample +/MC_Backend_Win/fd9a-e8c9-6abb-2f17 diff --git a/CreatedGrpc/ModeliRpc.pb.cc b/CreatedGrpc/ModeliRpc.pb.cc index e606e288a3b7326f0438ce0e32a87b0941f5dd8d..d24dc9ce3fbe36b4befe91aad90b080ec794794a 100644 --- a/CreatedGrpc/ModeliRpc.pb.cc +++ b/CreatedGrpc/ModeliRpc.pb.cc @@ -955,6 +955,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUT ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::ModeliRpc::AddFmuRequest, instance_name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::ModeliRpc::AddFmuRequest, chunk_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::ModeliRpc::AddFmuRequest, total_size_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::ModeliRpc::AddFmuResponse, _internal_metadata_), ~0u, // no _extensions_ @@ -1118,29 +1119,29 @@ static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROT { 44, -1, sizeof(::ModeliRpc::StopRequest)}, { 49, -1, sizeof(::ModeliRpc::StopResponse)}, { 55, -1, sizeof(::ModeliRpc::AddFmuRequest)}, - { 62, -1, sizeof(::ModeliRpc::AddFmuResponse)}, - { 68, -1, sizeof(::ModeliRpc::RemoveFmuRequest)}, - { 74, -1, sizeof(::ModeliRpc::RemoveFmuResponse)}, - { 80, -1, sizeof(::ModeliRpc::AddChannelLinkRequest)}, - { 86, -1, sizeof(::ModeliRpc::AddChannelLinkResponse)}, - { 92, -1, sizeof(::ModeliRpc::RemoveChannelLinkRequest)}, - { 98, -1, sizeof(::ModeliRpc::RemoveChannelLinkResponse)}, - { 104, -1, sizeof(::ModeliRpc::IntValues)}, - { 111, -1, sizeof(::ModeliRpc::SetIntRequest)}, - { 118, -1, sizeof(::ModeliRpc::SetIntResponse)}, - { 124, -1, sizeof(::ModeliRpc::RealValues)}, - { 131, -1, sizeof(::ModeliRpc::SetRealRequest)}, - { 138, -1, sizeof(::ModeliRpc::SetRealResponse)}, - { 144, -1, sizeof(::ModeliRpc::BoolValues)}, - { 151, -1, sizeof(::ModeliRpc::SetBoolRequest)}, - { 158, -1, sizeof(::ModeliRpc::SetBoolResponse)}, - { 164, -1, sizeof(::ModeliRpc::StringValues)}, - { 171, -1, sizeof(::ModeliRpc::SetStringRequest)}, - { 178, -1, sizeof(::ModeliRpc::SetStringResponse)}, - { 184, -1, sizeof(::ModeliRpc::NewValuesRequest)}, - { 189, -1, sizeof(::ModeliRpc::NewValuesResponse)}, - { 200, -1, sizeof(::ModeliRpc::LogRequest)}, - { 205, -1, sizeof(::ModeliRpc::LogResponse)}, + { 63, -1, sizeof(::ModeliRpc::AddFmuResponse)}, + { 69, -1, sizeof(::ModeliRpc::RemoveFmuRequest)}, + { 75, -1, sizeof(::ModeliRpc::RemoveFmuResponse)}, + { 81, -1, sizeof(::ModeliRpc::AddChannelLinkRequest)}, + { 87, -1, sizeof(::ModeliRpc::AddChannelLinkResponse)}, + { 93, -1, sizeof(::ModeliRpc::RemoveChannelLinkRequest)}, + { 99, -1, sizeof(::ModeliRpc::RemoveChannelLinkResponse)}, + { 105, -1, sizeof(::ModeliRpc::IntValues)}, + { 112, -1, sizeof(::ModeliRpc::SetIntRequest)}, + { 119, -1, sizeof(::ModeliRpc::SetIntResponse)}, + { 125, -1, sizeof(::ModeliRpc::RealValues)}, + { 132, -1, sizeof(::ModeliRpc::SetRealRequest)}, + { 139, -1, sizeof(::ModeliRpc::SetRealResponse)}, + { 145, -1, sizeof(::ModeliRpc::BoolValues)}, + { 152, -1, sizeof(::ModeliRpc::SetBoolRequest)}, + { 159, -1, sizeof(::ModeliRpc::SetBoolResponse)}, + { 165, -1, sizeof(::ModeliRpc::StringValues)}, + { 172, -1, sizeof(::ModeliRpc::SetStringRequest)}, + { 179, -1, sizeof(::ModeliRpc::SetStringResponse)}, + { 185, -1, sizeof(::ModeliRpc::NewValuesRequest)}, + { 190, -1, sizeof(::ModeliRpc::NewValuesResponse)}, + { 201, -1, sizeof(::ModeliRpc::LogRequest)}, + { 206, -1, sizeof(::ModeliRpc::LogResponse)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -1210,69 +1211,70 @@ void AddDescriptorsImpl() { "\n\004time\030\001 \001(\001\"\"\n\020PlayFastResponse\022\016\n\006stat" "us\030\001 \001(\005\"\016\n\014PauseRequest\"\017\n\rPauseRespons" "e\"\r\n\013StopRequest\"\036\n\014StopResponse\022\016\n\006stat" - "us\030\001 \001(\005\"5\n\rAddFmuRequest\022\025\n\rinstance_na" - "me\030\001 \001(\t\022\r\n\005chunk\030\002 \001(\014\"!\n\016AddFmuRespons" - "e\022\017\n\007success\030\001 \001(\010\")\n\020RemoveFmuRequest\022\025" - "\n\rinstance_name\030\001 \001(\t\"$\n\021RemoveFmuRespon" - "se\022\017\n\007success\030\001 \001(\010\"E\n\025AddChannelLinkReq" - "uest\022,\n\014channel_link\030\001 \001(\0132\026.ModeliRpc.C" - "hannelLink\")\n\026AddChannelLinkResponse\022\017\n\007" - "success\030\001 \001(\010\"H\n\030RemoveChannelLinkReques" - "t\022,\n\014channel_link\030\001 \001(\0132\026.ModeliRpc.Chan" - "nelLink\",\n\031RemoveChannelLinkResponse\022\017\n\007" - "success\030\001 \001(\010\"(\n\tIntValues\022\013\n\003vrs\030\001 \003(\r\022" - "\016\n\006values\030\002 \003(\005\"L\n\rSetIntRequest\022\025\n\rinst" - "ance_name\030\001 \001(\t\022$\n\006values\030\002 \001(\0132\024.Modeli" - "Rpc.IntValues\" \n\016SetIntResponse\022\016\n\006statu" - "s\030\001 \001(\005\")\n\nRealValues\022\013\n\003vrs\030\001 \003(\r\022\016\n\006va" - "lues\030\002 \003(\001\"N\n\016SetRealRequest\022\025\n\rinstance" - "_name\030\001 \001(\t\022%\n\006values\030\002 \001(\0132\025.ModeliRpc." - "RealValues\"!\n\017SetRealResponse\022\016\n\006status\030" - "\001 \001(\005\")\n\nBoolValues\022\013\n\003vrs\030\001 \003(\r\022\016\n\006valu" - "es\030\002 \003(\005\"N\n\016SetBoolRequest\022\025\n\rinstance_n" - "ame\030\001 \001(\t\022%\n\006values\030\002 \001(\0132\025.ModeliRpc.Bo" - "olValues\"!\n\017SetBoolResponse\022\016\n\006status\030\001 " - "\001(\005\"+\n\014StringValues\022\013\n\003vrs\030\001 \003(\r\022\016\n\006valu" - "es\030\002 \003(\t\"R\n\020SetStringRequest\022\025\n\rinstance" - "_name\030\001 \001(\t\022\'\n\006values\030\002 \001(\0132\027.ModeliRpc." - "StringValues\"#\n\021SetStringResponse\022\016\n\006sta" - "tus\030\001 \001(\005\"\022\n\020NewValuesRequest\"\357\001\n\021NewVal" - "uesResponse\022\021\n\ttimestamp\030\001 \001(\001\022(\n\nint_va" - "lues\030\002 \001(\0132\024.ModeliRpc.IntValues\022*\n\013real" - "_values\030\003 \001(\0132\025.ModeliRpc.RealValues\022*\n\013" - "bool_values\030\004 \001(\0132\025.ModeliRpc.BoolValues" - "\022.\n\rstring_values\030\005 \001(\0132\027.ModeliRpc.Stri" - "ngValues\022\025\n\rinstance_name\030\006 \001(\t\"\014\n\nLogRe" - "quest\"E\n\013LogResponse\022\025\n\rinstance_name\030\001 " - "\001(\t\022\016\n\006status\030\002 \001(\005\022\017\n\007message\030\003 \001(\t2\317\007\n" - "\rModeliBackend\0227\n\004Play\022\026.ModeliRpc.PlayR" - "equest\032\027.ModeliRpc.PlayResponse\022C\n\010PlayF" - "ast\022\032.ModeliRpc.PlayFastRequest\032\033.Modeli" - "Rpc.PlayFastResponse\022:\n\005Pause\022\027.ModeliRp" - "c.PauseRequest\032\030.ModeliRpc.PauseResponse" - "\0227\n\004Stop\022\026.ModeliRpc.StopRequest\032\027.Model" - "iRpc.StopResponse\022\?\n\006AddFmu\022\030.ModeliRpc." - "AddFmuRequest\032\031.ModeliRpc.AddFmuResponse" - "(\001\022F\n\tRemoveFmu\022\033.ModeliRpc.RemoveFmuReq" - "uest\032\034.ModeliRpc.RemoveFmuResponse\022U\n\016Ad" - "dChannelLink\022 .ModeliRpc.AddChannelLinkR" - "equest\032!.ModeliRpc.AddChannelLinkRespons" - "e\022^\n\021RemoveChannelLink\022#.ModeliRpc.Remov" - "eChannelLinkRequest\032$.ModeliRpc.RemoveCh" - "annelLinkResponse\022=\n\006SetInt\022\030.ModeliRpc." - "SetIntRequest\032\031.ModeliRpc.SetIntResponse" - "\022@\n\007SetReal\022\031.ModeliRpc.SetRealRequest\032\032" - ".ModeliRpc.SetRealResponse\022@\n\007SetBool\022\031." - "ModeliRpc.SetBoolRequest\032\032.ModeliRpc.Set" - "BoolResponse\022F\n\tSetString\022\033.ModeliRpc.Se" - "tStringRequest\032\034.ModeliRpc.SetStringResp" - "onse\022H\n\tNewValues\022\033.ModeliRpc.NewValuesR" - "equest\032\034.ModeliRpc.NewValuesResponse0\001\0226" - "\n\003Log\022\025.ModeliRpc.LogRequest\032\026.ModeliRpc" - ".LogResponse0\001b\006proto3" + "us\030\001 \001(\005\"I\n\rAddFmuRequest\022\025\n\rinstance_na" + "me\030\001 \001(\t\022\r\n\005chunk\030\002 \001(\014\022\022\n\ntotal_size\030\003 " + "\001(\003\"!\n\016AddFmuResponse\022\017\n\007success\030\001 \001(\010\")" + "\n\020RemoveFmuRequest\022\025\n\rinstance_name\030\001 \001(" + "\t\"$\n\021RemoveFmuResponse\022\017\n\007success\030\001 \001(\010\"" + "E\n\025AddChannelLinkRequest\022,\n\014channel_link" + "\030\001 \001(\0132\026.ModeliRpc.ChannelLink\")\n\026AddCha" + "nnelLinkResponse\022\017\n\007success\030\001 \001(\010\"H\n\030Rem" + "oveChannelLinkRequest\022,\n\014channel_link\030\001 " + "\001(\0132\026.ModeliRpc.ChannelLink\",\n\031RemoveCha" + "nnelLinkResponse\022\017\n\007success\030\001 \001(\010\"(\n\tInt" + "Values\022\013\n\003vrs\030\001 \003(\r\022\016\n\006values\030\002 \003(\005\"L\n\rS" + "etIntRequest\022\025\n\rinstance_name\030\001 \001(\t\022$\n\006v" + "alues\030\002 \001(\0132\024.ModeliRpc.IntValues\" \n\016Set" + "IntResponse\022\016\n\006status\030\001 \001(\005\")\n\nRealValue" + "s\022\013\n\003vrs\030\001 \003(\r\022\016\n\006values\030\002 \003(\001\"N\n\016SetRea" + "lRequest\022\025\n\rinstance_name\030\001 \001(\t\022%\n\006value" + "s\030\002 \001(\0132\025.ModeliRpc.RealValues\"!\n\017SetRea" + "lResponse\022\016\n\006status\030\001 \001(\005\")\n\nBoolValues\022" + "\013\n\003vrs\030\001 \003(\r\022\016\n\006values\030\002 \003(\005\"N\n\016SetBoolR" + "equest\022\025\n\rinstance_name\030\001 \001(\t\022%\n\006values\030" + "\002 \001(\0132\025.ModeliRpc.BoolValues\"!\n\017SetBoolR" + "esponse\022\016\n\006status\030\001 \001(\005\"+\n\014StringValues\022" + "\013\n\003vrs\030\001 \003(\r\022\016\n\006values\030\002 \003(\t\"R\n\020SetStrin" + "gRequest\022\025\n\rinstance_name\030\001 \001(\t\022\'\n\006value" + "s\030\002 \001(\0132\027.ModeliRpc.StringValues\"#\n\021SetS" + "tringResponse\022\016\n\006status\030\001 \001(\005\"\022\n\020NewValu" + "esRequest\"\357\001\n\021NewValuesResponse\022\021\n\ttimes" + "tamp\030\001 \001(\001\022(\n\nint_values\030\002 \001(\0132\024.ModeliR" + "pc.IntValues\022*\n\013real_values\030\003 \001(\0132\025.Mode" + "liRpc.RealValues\022*\n\013bool_values\030\004 \001(\0132\025." + "ModeliRpc.BoolValues\022.\n\rstring_values\030\005 " + "\001(\0132\027.ModeliRpc.StringValues\022\025\n\rinstance" + "_name\030\006 \001(\t\"\014\n\nLogRequest\"E\n\013LogResponse" + "\022\025\n\rinstance_name\030\001 \001(\t\022\016\n\006status\030\002 \001(\005\022" + "\017\n\007message\030\003 \001(\t2\317\007\n\rModeliBackend\0227\n\004Pl" + "ay\022\026.ModeliRpc.PlayRequest\032\027.ModeliRpc.P" + "layResponse\022C\n\010PlayFast\022\032.ModeliRpc.Play" + "FastRequest\032\033.ModeliRpc.PlayFastResponse" + "\022:\n\005Pause\022\027.ModeliRpc.PauseRequest\032\030.Mod" + "eliRpc.PauseResponse\0227\n\004Stop\022\026.ModeliRpc" + ".StopRequest\032\027.ModeliRpc.StopResponse\022\?\n" + "\006AddFmu\022\030.ModeliRpc.AddFmuRequest\032\031.Mode" + "liRpc.AddFmuResponse(\001\022F\n\tRemoveFmu\022\033.Mo" + "deliRpc.RemoveFmuRequest\032\034.ModeliRpc.Rem" + "oveFmuResponse\022U\n\016AddChannelLink\022 .Model" + "iRpc.AddChannelLinkRequest\032!.ModeliRpc.A" + "ddChannelLinkResponse\022^\n\021RemoveChannelLi" + "nk\022#.ModeliRpc.RemoveChannelLinkRequest\032" + "$.ModeliRpc.RemoveChannelLinkResponse\022=\n" + "\006SetInt\022\030.ModeliRpc.SetIntRequest\032\031.Mode" + "liRpc.SetIntResponse\022@\n\007SetReal\022\031.Modeli" + "Rpc.SetRealRequest\032\032.ModeliRpc.SetRealRe" + "sponse\022@\n\007SetBool\022\031.ModeliRpc.SetBoolReq" + "uest\032\032.ModeliRpc.SetBoolResponse\022F\n\tSetS" + "tring\022\033.ModeliRpc.SetStringRequest\032\034.Mod" + "eliRpc.SetStringResponse\022H\n\tNewValues\022\033." + "ModeliRpc.NewValuesRequest\032\034.ModeliRpc.N" + "ewValuesResponse0\001\0226\n\003Log\022\025.ModeliRpc.Lo" + "gRequest\032\026.ModeliRpc.LogResponse0\001b\006prot" + "o3" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 2742); + descriptor, 2762); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "ModeliRpc.proto", &protobuf_RegisterTypes); } @@ -3485,6 +3487,7 @@ void AddFmuRequest::InitAsDefaultInstance() { #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int AddFmuRequest::kInstanceNameFieldNumber; const int AddFmuRequest::kChunkFieldNumber; +const int AddFmuRequest::kTotalSizeFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 AddFmuRequest::AddFmuRequest() @@ -3508,12 +3511,14 @@ AddFmuRequest::AddFmuRequest(const AddFmuRequest& from) if (from.chunk().size() > 0) { chunk_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.chunk_); } + total_size_ = from.total_size_; // @@protoc_insertion_point(copy_constructor:ModeliRpc.AddFmuRequest) } void AddFmuRequest::SharedCtor() { instance_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); chunk_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + total_size_ = GOOGLE_LONGLONG(0); _cached_size_ = 0; } @@ -3558,6 +3563,7 @@ void AddFmuRequest::Clear() { instance_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); chunk_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + total_size_ = GOOGLE_LONGLONG(0); _internal_metadata_.Clear(); } @@ -3599,6 +3605,20 @@ bool AddFmuRequest::MergePartialFromCodedStream( break; } + // int64 total_size = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { + + DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< + ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( + input, &total_size_))); + } else { + goto handle_unusual; + } + break; + } + default: { handle_unusual: if (tag == 0) { @@ -3641,6 +3661,11 @@ void AddFmuRequest::SerializeWithCachedSizes( 2, this->chunk(), output); } + // int64 total_size = 3; + if (this->total_size() != 0) { + ::google::protobuf::internal::WireFormatLite::WriteInt64(3, this->total_size(), output); + } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); @@ -3673,6 +3698,11 @@ void AddFmuRequest::SerializeWithCachedSizes( 2, this->chunk(), target); } + // int64 total_size = 3; + if (this->total_size() != 0) { + target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(3, this->total_size(), target); + } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); @@ -3704,6 +3734,13 @@ size_t AddFmuRequest::ByteSizeLong() const { this->chunk()); } + // int64 total_size = 3; + if (this->total_size() != 0) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::Int64Size( + this->total_size()); + } + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = cached_size; @@ -3741,6 +3778,9 @@ void AddFmuRequest::MergeFrom(const AddFmuRequest& from) { chunk_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.chunk_); } + if (from.total_size() != 0) { + set_total_size(from.total_size()); + } } void AddFmuRequest::CopyFrom(const ::google::protobuf::Message& from) { @@ -3769,6 +3809,7 @@ void AddFmuRequest::InternalSwap(AddFmuRequest* other) { using std::swap; instance_name_.Swap(&other->instance_name_); chunk_.Swap(&other->chunk_); + swap(total_size_, other->total_size_); _internal_metadata_.Swap(&other->_internal_metadata_); swap(_cached_size_, other->_cached_size_); } diff --git a/CreatedGrpc/ModeliRpc.pb.h b/CreatedGrpc/ModeliRpc.pb.h index 38a1387e9c9710b4cd858cc1e3825890da48da9a..d14ab6e3ce4e5c05217a98338af72346f547c57b 100644 --- a/CreatedGrpc/ModeliRpc.pb.h +++ b/CreatedGrpc/ModeliRpc.pb.h @@ -1273,12 +1273,19 @@ class AddFmuRequest : public ::google::protobuf::Message /* @@protoc_insertion_p ::std::string* release_chunk(); void set_allocated_chunk(::std::string* chunk); + // int64 total_size = 3; + void clear_total_size(); + static const int kTotalSizeFieldNumber = 3; + ::google::protobuf::int64 total_size() const; + void set_total_size(::google::protobuf::int64 value); + // @@protoc_insertion_point(class_scope:ModeliRpc.AddFmuRequest) private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::ArenaStringPtr instance_name_; ::google::protobuf::internal::ArenaStringPtr chunk_; + ::google::protobuf::int64 total_size_; mutable int _cached_size_; friend struct ::protobuf_ModeliRpc_2eproto::TableStruct; friend void ::protobuf_ModeliRpc_2eproto::InitDefaultsAddFmuRequestImpl(); @@ -4181,6 +4188,20 @@ inline void AddFmuRequest::set_allocated_chunk(::std::string* chunk) { // @@protoc_insertion_point(field_set_allocated:ModeliRpc.AddFmuRequest.chunk) } +// int64 total_size = 3; +inline void AddFmuRequest::clear_total_size() { + total_size_ = GOOGLE_LONGLONG(0); +} +inline ::google::protobuf::int64 AddFmuRequest::total_size() const { + // @@protoc_insertion_point(field_get:ModeliRpc.AddFmuRequest.total_size) + return total_size_; +} +inline void AddFmuRequest::set_total_size(::google::protobuf::int64 value) { + + total_size_ = value; + // @@protoc_insertion_point(field_set:ModeliRpc.AddFmuRequest.total_size) +} + // ------------------------------------------------------------------- // AddFmuResponse diff --git a/Files/FmuFile.cpp b/Files/FmuFile.cpp index 3dcd957c12a4c8249c366c2bdd84fcfe5e55a6bb..88c3592ce246cb89d7d66fb594c8aed2bb9d47fc 100644 --- a/Files/FmuFile.cpp +++ b/Files/FmuFile.cpp @@ -12,16 +12,15 @@ namespace Files void FmuFile::unzip_and_load(std::function<void(std::string unzipPath)> unzipAction) { // Unzip the fmu - _unzippedPath = fs::unique_path().generic_string(); - unzipAction(_unzippedPath); + m_unzippedPath = fs::unique_path().generic_string(); + unzipAction(m_unzippedPath); // Parse the model description - std::string xmlPath = _unzippedPath + "/modelDescription.xml"; + std::string xmlPath = m_unzippedPath + "/modelDescription.xml"; pt::ptree md; pt::read_xml(xmlPath, md); - _modelName = md.get<std::string>("fmiModelDescription.CoSimulation.<xmlattr>.modelIdentifier"); - _guid = md.get<std::string>("fmiModelDescription.<xmlattr>.guid"); - load_value_refs(md); - + m_modelName = md.get<std::string>("fmiModelDescription.CoSimulation.<xmlattr>.modelIdentifier"); + m_guid = md.get<std::string>("fmiModelDescription.<xmlattr>.guid"); + load_value_refs(md); } void FmuFile::load_value_refs(const boost::property_tree::ptree & xmlRoot) @@ -39,16 +38,16 @@ namespace Files } else { - vr_vector.push_back(scalar_var.second.get<unsigned int>("valueReference ")); + vr_vector.push_back(scalar_var.second.get<unsigned int>("<xmlattr>.valueReference")); return true; } }; // C++ pattern matching of the variable type - if (!check_and_add("Real", real_vr_)) { ; } - else if (!check_and_add("Integer", int_vr_)) { ; } - else if (!check_and_add("Boolean", bool_vr_)) { ; } - else if (check_and_add("String", string_vr_)) { ; } - else if (check_and_add("Enumeration", int_vr_)) { ; } + if (!check_and_add("Real", m_real_vrs)) { ; } + else if (!check_and_add("Integer", m_int_vrs)) { ; } + else if (!check_and_add("Boolean", m_bool_vrs)) { ; } + else if (check_and_add("String", m_string_vrs)) { ; } + else if (check_and_add("Enumeration", m_int_vrs)) { ; } } } @@ -61,7 +60,7 @@ namespace Files } FmuFile::FmuFile(const std::vector<unsigned char>& buffer) { - unzip_and_load([buffer](std::string unzipPath) + unzip_and_load([&](std::string unzipPath) { Unzipper::Unzip(buffer, unzipPath); }); @@ -69,13 +68,13 @@ namespace Files FmuFile::~FmuFile() { - fs::remove_all(_unzippedPath); + fs::remove_all(m_unzippedPath); } std::string FmuFile::GetBinaryPath() { // The pathToFmu of the binary depends on the system - fs::path binaryPath = _unzippedPath; + fs::path binaryPath = m_unzippedPath; binaryPath /= "binaries"; #if __linux__ #if __arm__ @@ -92,7 +91,7 @@ namespace Files #else #error system ist not supported #endif - binaryPath /= _modelName; + binaryPath /= m_modelName; // Return canonical (absolute) pathToFmu. // Don not use relative paths for dynamic library loading (security)! return fs::weakly_canonical(binaryPath).generic_string(); @@ -100,15 +99,31 @@ namespace Files std::string FmuFile::GetGUID() { - return _guid; + return m_guid; } std::string FmuFile::GetResourceUri() { // Create prefix std::string prefix = "file:///"; // mandatory according to the fmi doc // Create pathToFmu object - std::string resourceDir = _unzippedPath + "/resources"; + std::string resourceDir = m_unzippedPath + "/resources"; // Append absolute pathToFmu of the mod return prefix + resourceDir; } + std::vector<unsigned int> FmuFile::get_int_vrs() + { + return m_int_vrs; + } + std::vector<unsigned int> FmuFile::get_real_vrs() + { + return m_real_vrs; + } + std::vector<unsigned int> FmuFile::get_bool_vrs() + { + return m_bool_vrs; + } + std::vector<unsigned int> FmuFile::get_string_vrs() + { + return m_string_vrs; + } } \ No newline at end of file diff --git a/Files/FmuFile.hpp b/Files/FmuFile.hpp index e78319f68eb30d39754c3b9394d435a033324538..65dc802ddbded84e574184c83926c2396d2f46c3 100644 --- a/Files/FmuFile.hpp +++ b/Files/FmuFile.hpp @@ -13,15 +13,15 @@ namespace Files { private: // FMU info - std::string _modelName; - std::string _guid; + std::string m_modelName; + std::string m_guid; // The path where the extracted fmu is stored - std::string _unzippedPath; + std::string m_unzippedPath; // ValueReferences for each type - std::vector<unsigned int> int_vr_; - std::vector<unsigned int> real_vr_; - std::vector<unsigned int> bool_vr_; - std::vector<unsigned int> string_vr_; + std::vector<unsigned int> m_int_vrs; + std::vector<unsigned int> m_real_vrs; + std::vector<unsigned int> m_bool_vrs; + std::vector<unsigned int> m_string_vrs; /// Unzips the fmu and loads the modelDescription /// The unzip action must be passed in. @@ -43,5 +43,10 @@ namespace Files std::string GetGUID(); /// Create an URI to the resource dir. The uri is "file:///" + absolutePath of modelDir std::string GetResourceUri(); + + std::vector<unsigned int> get_int_vrs(); + std::vector<unsigned int> get_real_vrs(); + std::vector<unsigned int> get_bool_vrs(); + std::vector<unsigned int> get_string_vrs(); }; } \ No newline at end of file diff --git a/Main/main.cpp b/Main/main.cpp index 38f5738ca360342ac7c910dcff22e2cfd875a49f..fe0c80e66bd9f2ab56ad615179ca8075175312bf 100644 --- a/Main/main.cpp +++ b/Main/main.cpp @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) } // Configuration for rpc ModeliGrpcServer service(std::move(fmuEngine)); - std::string targetUri = "0.0.0.0:" + port; + std::string targetUri = "0.0.0.0:" + std::to_string(port); // Start the server grpc::ServerBuilder builder; builder.AddListeningPort(targetUri, grpc::InsecureServerCredentials()); @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) std::unique_ptr<Server> server(builder.BuildAndStart()); std::cout << "Started listening to: " + targetUri << std::endl; - std::cout << "Simply kill the process to shutdown." << std::endl; + std::cout << "Kill the process to shutdown." << std::endl; // Block until process is killed server->Wait(); } diff --git a/Simulation/FmuEntity.cpp b/Simulation/FmuEntity.cpp index 85784512a3b4c7d57a5a891ed2a268a471381b61..36ee58781d5c3b320d7e13e2bc04764b6420f11f 100644 --- a/Simulation/FmuEntity.cpp +++ b/Simulation/FmuEntity.cpp @@ -11,7 +11,10 @@ namespace Simulation m_logger(logger) { m_fmu = std::make_shared<NativeFmu::CoSimFmu>(); - + m_fmu->SetBooleanVr(m_file->get_bool_vrs()); + m_fmu->SetIntegerVr(m_file->get_int_vrs()); + m_fmu->SetRealVr(m_file->get_real_vrs()); + m_fmu->SetStringVr(m_file->get_string_vrs()); } std::string FmuEntity::GetInstanceName() @@ -21,7 +24,7 @@ namespace Simulation std::shared_ptr<NativeFmu::CoSimFmu> FmuEntity::GetCoSimFmu() { - return std::shared_ptr<NativeFmu::CoSimFmu>(); + return m_fmu; } bool FmuEntity::InstantiateFmu() diff --git a/Simulation/IEngineObserver.hpp b/Simulation/IEngineObserver.hpp deleted file mode 100644 index 924034c23351c68a3322076c6171266f546c44b2..0000000000000000000000000000000000000000 --- a/Simulation/IEngineObserver.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once -#include <string> -#include <vector> - -namespace Simulation -{ - /// All methods must be executed non blocking. - /// Otherwise the simulation gets slowed down. - class IEngineObserver - { - public: - /// Gets Called when new values have been calculated - virtual void ValuesArrived( - std::string instanceName, ///< The instanceName of the FMU - double timestamp, ///< Timestamp (current time) - std::vector<unsigned int> intVrs, - std::vector<int> intValues, - std::vector<unsigned int> realVrs, - std::vector<double> realValues, - std::vector<unsigned int> boolVrs, - std::vector<int> boolValues, - std::vector<unsigned int> stringVrs, - std::vector<const char*> stringValues) = 0; - - /// Log from the engine and Fmus - virtual void LogArrived( - std::string instanceName, ///< The instanceName of the FMU - int status, ///< Fmi2Status of the message - std::string category, ///< Category of the message - std::string message ///< The message that has been logged - ) = 0; - }; -} \ No newline at end of file diff --git a/Simulation/ModeliGrpcServer.cpp b/Simulation/ModeliGrpcServer.cpp index 43ea965de80ed022c2f325ca60808d4e09edc5cf..0dd9deb7b7f2f3b9554ba4bbaef8a3412f788d19 100644 --- a/Simulation/ModeliGrpcServer.cpp +++ b/Simulation/ModeliGrpcServer.cpp @@ -4,8 +4,14 @@ #include "Simulator.hpp" #include "CoSimFmu.h" +namespace ph = std::placeholders; + ModeliGrpcServer::ModeliGrpcServer(std::unique_ptr<Simulation::Simulator> simulator) :m_simulator(std::move(simulator)) { + // Register the callbacks + m_simulator->RegisterLogCallback(std::bind(&ModeliGrpcServer::LogArrived, this, ph::_1, ph::_2, ph::_3, ph::_4)); + m_simulator->RegisterNewValuesCallback(std::bind(&ModeliGrpcServer::ValuesArrived, this, + ph::_1, ph::_2, ph::_3, ph::_4, ph::_5, ph::_6, ph::_7, ph::_8, ph::_9, ph::_10)); } ModeliGrpcServer::~ModeliGrpcServer() @@ -45,12 +51,17 @@ Status ModeliGrpcServer::AddFmu(ServerContext * context, ServerReader<::ModeliRp // Read the chunks while (reader->Read(&request)) { - // Do not reassign it on every chunk + // Intial assignments + if (buffer.size() == 0) + { + buffer.reserve(request.total_size()); + } if (instanceName == "") { instanceName = request.instance_name(); } - std::copy(request.chunk().begin(), request.chunk().end(), std::back_inserter(buffer)); + // Insert recceived data + buffer.insert(buffer.end(), request.chunk().begin(), request.chunk().end()); } // Try to add the fmu response->set_success(m_simulator->AddFmu(std::make_unique<Files::FmuFile>(buffer), instanceName)); @@ -152,7 +163,7 @@ Status ModeliGrpcServer::Log(ServerContext * context, const::ModeliRpc::LogReque return Status::OK; } -void ModeliGrpcServer::ValuesArrived(const std::string instanceName, double timestamp, const std::vector<unsigned int> intVrs, const std::vector<int> intValues, const std::vector<unsigned int> realVrs, const std::vector<double> realValues, const std::vector<unsigned int> boolVrs, const std::vector<int> boolValues, const std::vector<unsigned int> stringVrs, const std::vector<const char*> stringValues) +void ModeliGrpcServer::ValuesArrived(const std::string instanceName, double timestamp, const std::vector<unsigned int> intVrs, const std::vector<int> intValues, const std::vector<unsigned int> realVrs, const std::vector<double> realValues, const std::vector<unsigned int> boolVrs, const std::vector<int> boolValues, const std::vector<unsigned int> stringVrs, const std::vector<std::string> stringValues) { ModeliRpc::NewValuesResponse response; response.set_instance_name(instanceName); @@ -189,6 +200,7 @@ void ModeliGrpcServer::LogArrived(std::string instanceName, int status, std::str ModeliRpc::LogResponse response; response.set_instance_name(instanceName); response.set_status(status); + response.set_message("Category: " + category + " Message: " + message); // Buffer the logs so the simulation does not get blocked m_logs.push(response); } diff --git a/Simulation/ModeliGrpcServer.h b/Simulation/ModeliGrpcServer.h index 6ef8a132eea9360c2b47e1493548e9bca66964b4..435732896967da95988d03cef57bafb18c90803a 100644 --- a/Simulation/ModeliGrpcServer.h +++ b/Simulation/ModeliGrpcServer.h @@ -1,7 +1,6 @@ #pragma once #include "ModeliRpc.grpc.pb.h" #include "ConcurrentQueue.h" -#include "IEngineObserver.hpp" using grpc::Status; using grpc::ServerContext; @@ -16,7 +15,7 @@ namespace Simulation /// This class implements the server side of the grpc definition. /// It is in charge of controlling the simulation and sending feedback to the frontend. -class ModeliGrpcServer final : public ModeliRpc::ModeliBackend::Service, Simulation::IEngineObserver +class ModeliGrpcServer final : public ModeliRpc::ModeliBackend::Service { public: ModeliGrpcServer(std::unique_ptr<Simulation::Simulator> unique_ptr); @@ -64,7 +63,7 @@ public: std::vector<unsigned int> boolVrs, std::vector<int> boolValues, std::vector<unsigned int> stringVrs, - std::vector<const char*> stringValues); + std::vector<std::string> stringValues); /// Observer callback virtual void LogArrived( diff --git a/Simulation/Simulation.vcxitems b/Simulation/Simulation.vcxitems index dc0d511db1869ac9662030b0def56179c5f33d1b..eb9707efcab43dcdea67fc2777c1c7e975964758 100644 --- a/Simulation/Simulation.vcxitems +++ b/Simulation/Simulation.vcxitems @@ -22,7 +22,6 @@ <ClInclude Include="$(MSBuildThisFileDirectory)FmuEntity.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)ModeliGrpcServer.h" /> <ClInclude Include="$(MSBuildThisFileDirectory)Simulator.hpp" /> - <ClInclude Include="$(MSBuildThisFileDirectory)IEngineObserver.hpp" /> </ItemGroup> <ItemGroup> <ClCompile Include="$(MSBuildThisFileDirectory)ChannelLink.cpp" /> diff --git a/Simulation/Simulation.vcxitems.filters b/Simulation/Simulation.vcxitems.filters index 2d7534b5f5c28b703e77bc2fa2bff3a77f4fe737..f57aa2e167c19d273f35fbd70914b068d2bdf9c0 100644 --- a/Simulation/Simulation.vcxitems.filters +++ b/Simulation/Simulation.vcxitems.filters @@ -20,9 +20,6 @@ <ClInclude Include="$(MSBuildThisFileDirectory)fmi2TypesPlatform.h"> <Filter>Header</Filter> </ClInclude> - <ClInclude Include="$(MSBuildThisFileDirectory)IEngineObserver.hpp"> - <Filter>Header</Filter> - </ClInclude> <ClInclude Include="$(MSBuildThisFileDirectory)ModeliGrpcServer.h"> <Filter>Header</Filter> </ClInclude> diff --git a/Simulation/Simulator.cpp b/Simulation/Simulator.cpp index 8f1ea5fd04d11701e0b7fd7db3f05a9f625ab00c..e874a0fb635d52a91840628b47a27524afd622f2 100644 --- a/Simulation/Simulator.cpp +++ b/Simulation/Simulator.cpp @@ -76,6 +76,8 @@ namespace Simulation void Simulator::simulation_loop() { + // If playFast is activated the timer will have an offset (it doesn't run as fast) + double timer_offset = 0; // CPU timer is steady on windows, linux and mac boost::timer::cpu_timer timer; timer.start(); @@ -103,16 +105,20 @@ namespace Simulation // Dispatch work depending on mode if (m_play_fast_for > 0) { + // Stop timer so we don't have to wait forever + timer.stop(); m_play_fast_for -= STEP_SIZE; + timer_offset += STEP_SIZE; // Dispatch one new workload m_dispatcher.execute_one(); } else { + // Resume timer for realtime execution after playfast + timer.resume(); // Keep up / wait for realtime - std::chrono::nanoseconds elaps{ timer.elapsed().wall }; - std::chrono::duration<double> calc{ m_sim_time }; - while (elaps < calc) + std::chrono::duration<double> sim_time_with_offset{ m_sim_time - timer_offset }; + while (std::chrono::nanoseconds{ timer.elapsed().wall } < sim_time_with_offset) { // Time to dispatch work if (!m_dispatcher.execute_one()) @@ -157,26 +163,6 @@ namespace Simulation } } - void Simulator::AddObserver(std::shared_ptr<IEngineObserver> observer) - { - // Must wait, otherwise undefined behaviour occurs: - // Observer destroyed before execution - m_dispatcher.dispatch_void([&]() - { - _observers.push_back(observer); - }).wait(); - } - - void Simulator::RemoveObserver(std::shared_ptr<IEngineObserver> observer) - { - // Must wait, otherwise undefined behaviour occurs: - // Observer destroyed before execution - m_dispatcher.dispatch_void([&]() - { - _observers.remove(observer); - }).wait(); - } - int Simulator::Play() { // Play infinite @@ -204,7 +190,7 @@ namespace Simulation // Dispatch pause m_dispatcher.dispatch_void([&]() { - m_pause = false; + m_pause = true; }).wait(); } @@ -255,25 +241,27 @@ namespace Simulation void Simulator::onValuesArrived(const std::string instanceName, double timestamp, const std::vector<unsigned int> intVrs, const std::vector<int> intValues, const std::vector<unsigned int> realVrs, const std::vector<double> realValues, const std::vector<unsigned int> boolVrs, const std::vector<int> boolValues, const std::vector<unsigned int> stringVrs, const std::vector<const char*> stringValues) { + // Convert strings + std::vector<std::string> string_vals(stringValues.begin(), stringValues.end()); // Invoke each observer - for (auto observer : _observers) - { - observer->ValuesArrived( - instanceName, timestamp, - intVrs, intValues, - realVrs, realValues, - boolVrs, boolValues, - stringVrs, stringValues); - } + m_values_callback( + instanceName, + timestamp, + intVrs, + intValues, + realVrs, + realValues, + boolVrs, + boolValues, + stringVrs, + string_vals + ); } void Simulator::onLog(std::string instanceName, int status, std::string category, std::string message) { // Invoke each observer - for (auto observer : _observers) - { - observer->LogArrived(instanceName, status, category, message); - } + m_log_callback(instanceName, status, category, message); } std::shared_ptr<NativeFmu::CoSimFmu> Simulator::get_fmu_or_log(std::string instance_name, std::string msg) @@ -309,7 +297,7 @@ namespace Simulation bool Simulator::AddFmu(std::unique_ptr<Files::FmuFile> fmuFile, std::string instance_name) { // Fail early if instance name exists (asking for state -> dispatch) - if (!m_dispatcher.dispatch_fn<bool>([&]() + if (m_dispatcher.dispatch_fn<bool>([&]() { return m_fmus->Contains(instance_name); }).get()) @@ -404,4 +392,12 @@ namespace Simulation return fmi2Warning; } } + void Simulator::RegisterNewValuesCallback(NewValuesCallback callback) + { + m_values_callback = callback; + } + void Simulator::RegisterLogCallback(LogCallback callback) + { + m_log_callback = callback; + } } \ No newline at end of file diff --git a/Simulation/Simulator.hpp b/Simulation/Simulator.hpp index ee0c9ba0e6c6c5f94adeccaff3f3b15a192d65cb..5d8d5dd205f2c40f1dc4ba629154d20b3b444648 100644 --- a/Simulation/Simulator.hpp +++ b/Simulation/Simulator.hpp @@ -1,8 +1,8 @@ #pragma once #include "ChannelLink.h" -#include "IEngineObserver.hpp" #include "QueueDispatcher.h" #include "boost/optional.hpp" +#include <functional> #include <list> #include <thread> #include <vector> @@ -21,6 +21,28 @@ namespace Simulation class FmuContainer; class ChannelLinkContainer; + // Huge signature but we must deliver all values at once + /// Use this signature for propagating new Values + typedef std::function<void( + std::string instanceName, ///< The fmu instance for the values + double timestamp, ///< The simulation time of the values + std::vector<unsigned int> int_vrs, + std::vector<int> int_values, + std::vector<unsigned int> real_vrs, + std::vector<double> real_values, + std::vector<unsigned int> bool_vrs, + std::vector<int> bool_values, + std::vector<unsigned int> string_vrs, + std::vector<std::string> string_values + )> NewValuesCallback; + /// Callback for logging to the frontend + typedef std::function<void( + std::string instanceName, ///< The instanceName of the FMU + int status, ///< Fmi2Status of the message + std::string category, ///< Category of the message + std::string message ///< The message that has been logged) + )> LogCallback; + class Simulator { public: @@ -29,10 +51,8 @@ namespace Simulation void operator=(const Simulator&) = delete; ~Simulator(); - /// The observer subscribes the callbacks - void AddObserver(std::shared_ptr<IEngineObserver> observer); - /// Unsubscribe the observer form the callbacks - void RemoveObserver(std::shared_ptr<IEngineObserver> observer); + /// Add callbacks for the server + /// Runs the simulation in realtime with endtime set to DBL_MAX int Play(); @@ -59,6 +79,11 @@ namespace Simulation int SetBoolean(std::string instance_name, std::vector<unsigned int> vr, std::vector<int> values); int SetString(std::string instance_name, std::vector<unsigned int> vr, std::vector<std::string> values); + /// When new values are available + void RegisterNewValuesCallback(NewValuesCallback callback); + /// When a new log messaage is available + void RegisterLogCallback(LogCallback callback); + private: // Container std::shared_ptr<FmuContainer> m_fmus; @@ -78,6 +103,10 @@ namespace Simulation const double STEP_SIZE = 0.01; double m_sim_time = 0; + // Not observable, just callbacks because the simulator will be owned by one server + NewValuesCallback m_values_callback; + LogCallback m_log_callback; + /// Starts or resumes the simulation thread. /// Waits for the successfull execution from the queue. int start_simulation(); @@ -85,9 +114,7 @@ namespace Simulation void simulation_loop(); /// Gets current values and calls onValuesArrived void sendValues(double current_time); - - // Collection of observers - std::list<std::shared_ptr<IEngineObserver>> _observers; + // Spread the word: New Values arrived to all observers void onValuesArrived(const std::string instanceName, double timestamp, const std::vector<unsigned int> intVrs, const std::vector<int> intValues,