Skip to content

Commit af7e373

Browse files
committed
Update configuration
Signed-off-by: zesk1999 <[email protected]>
1 parent 6ea6dd5 commit af7e373

20 files changed

+19997
-65
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
exception InternalError
2+
{
3+
};
4+
5+
// 1. AppRequirements
6+
interface AppRequirementsService
7+
{
8+
string update_configuration(in string configuration) raises (InternalError);
9+
string send_data(in string data) raises (InternalError);
10+
};
11+
12+
// 2. HWConstraints
13+
interface HWConstraintsService
14+
{
15+
string update_configuration(in string configuration) raises (InternalError);
16+
string send_data(in string data) raises (InternalError);
17+
};
18+
19+
// 3. HWResources
20+
interface HWResourcesService
21+
{
22+
string update_configuration(in string configuration) raises (InternalError);
23+
string send_data(in string data) raises (InternalError);
24+
};
25+
26+
// 4. CarbonFootprint
27+
interface CarbonFootprintService
28+
{
29+
string update_configuration(in string configuration) raises (InternalError);
30+
string send_data(in string data) raises (InternalError);
31+
};
32+
33+
// 5. MLModelMetadata
34+
interface MLModelMetadataService
35+
{
36+
string update_configuration(in string configuration) raises (InternalError);
37+
string send_data(in string data) raises (InternalError);
38+
};
39+
40+
// 6. MLModel
41+
interface MLModelService
42+
{
43+
string update_configuration(in string configuration) raises (InternalError);
44+
string send_data(in string data) raises (InternalError);
45+
};

sustainml_cpp/include/sustainml_cpp/orchestrator/OrchestratorNode.hpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,14 @@ namespace dds {
3535
class DomainParticipant;
3636
class Topic;
3737
class Publisher;
38+
class Subscriber;
3839
class DataWriter;
3940

4041
} // namespace dds
4142
} // namespace fastdds
4243
} // namespace eprosima
4344

4445
namespace sustainml {
45-
namespace core {
46-
class RequestReplier;
47-
} // namespace core
4846
namespace orchestrator {
4947

5048
class ModuleNodeProxy;
@@ -251,17 +249,17 @@ class OrchestratorNode
251249
*/
252250
OrchestratorNodeHandle* handler_;
253251

254-
eprosima::fastdds::dds::DomainParticipant* participant_;
252+
eprosima::fastdds::dds::DomainParticipant* participant_{nullptr};
255253

256-
eprosima::fastdds::dds::Topic* control_topic_;
257-
eprosima::fastdds::dds::Topic* status_topic_;
258-
eprosima::fastdds::dds::Topic* user_input_topic_;
254+
eprosima::fastdds::dds::Topic* control_topic_{nullptr};
255+
eprosima::fastdds::dds::Topic* status_topic_{nullptr};
256+
eprosima::fastdds::dds::Topic* user_input_topic_{nullptr};
259257

260-
eprosima::fastdds::dds::Publisher* pub_;
261-
eprosima::fastdds::dds::Subscriber* sub_;
258+
eprosima::fastdds::dds::Publisher* pub_{nullptr};
259+
eprosima::fastdds::dds::Subscriber* sub_{nullptr};
262260

263-
eprosima::fastdds::dds::DataWriter* control_writer_;
264-
eprosima::fastdds::dds::DataWriter* user_input_writer_;
261+
eprosima::fastdds::dds::DataWriter* control_writer_{nullptr};
262+
eprosima::fastdds::dds::DataWriter* user_input_writer_{nullptr};
265263

266264
std::array<ModuleNodeProxy*, (size_t)NodeID::MAX> node_proxies_;
267265
std::mutex proxies_mtx_;
@@ -276,8 +274,8 @@ class OrchestratorNode
276274
std::atomic_bool terminated_{false};
277275
std::condition_variable initialization_cv_;
278276

279-
types::ResponseType res_;
280-
sustainml::core::RequestReplier* req_res_;
277+
// Opaque holder for per-service RPC clients (defined in OrchestratorNode.cpp)
278+
void* rpc_client_holder_{nullptr};
281279

282280
/**
283281
* @brief This class implements the callbacks for the DomainParticipant
@@ -312,4 +310,3 @@ class OrchestratorNode
312310
} // namespace sustainml
313311

314312
#endif // SUSTAINMLCPP_ORCHESTRATOR_ORCHESTRATORNODE_HPP
315-
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2025 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @file GenericServiceNode.cpp
17+
*/
18+
19+
#ifndef SUSTAINML_CORE_GENERICSERVICENODEIMPL_HPP
20+
#define SUSTAINML_CORE_GENERICSERVICENODEIMPL_HPP
21+
22+
#include <string>
23+
#include <iostream>
24+
25+
#include <core/NodeImpl.hpp>
26+
#include <types/types.hpp>
27+
#include <types/SustainMLServiceServer.hpp>
28+
29+
namespace eprosima {
30+
namespace fastdds {
31+
namespace dds {
32+
namespace rpc {
33+
class RpcRequest;
34+
} // namespace rpc
35+
} // namespace dds
36+
} // namespace fastdds
37+
} // namespace eprosima
38+
39+
namespace sustainml {
40+
namespace core {
41+
42+
template <typename ServerBase>
43+
class GenericServiceNodeImpl : public ServerBase
44+
{
45+
public:
46+
GenericServiceNodeImpl(NodeImpl& node, const char* tag)
47+
: node_(node)
48+
, tag_(tag)
49+
{
50+
}
51+
52+
std::string update_configuration(
53+
const eprosima::fastdds::dds::rpc::RpcRequest& /*info*/,
54+
const std::string& configuration) override
55+
{
56+
std::cout << "[RPC SERVER/" << tag_ << "] update_configuration cfg='"
57+
<< configuration << "'\n";
58+
59+
types::RequestType req;
60+
types::ResponseType res;
61+
62+
req.configuration(configuration);
63+
64+
try
65+
{
66+
node_.request_listener().on_configuration_request(req, res);
67+
}
68+
catch (const std::exception& e)
69+
{
70+
throw ::InternalError(std::string("update_configuration: ") + e.what());
71+
}
72+
catch (...)
73+
{
74+
throw ::InternalError("update_configuration: unknown error");
75+
}
76+
77+
// If your listener reports failures via res.success():
78+
if (!res.success())
79+
{
80+
// If you have an error string field, put it here. If not:
81+
throw ::InternalError("update_configuration: res.success==false");
82+
}
83+
84+
return res.configuration();
85+
}
86+
87+
std::string send_data(
88+
const eprosima::fastdds::dds::rpc::RpcRequest& /*info*/,
89+
const std::string& data) override
90+
{
91+
(void)data;
92+
93+
// If not implemented yet, raise InternalError (matches IDL)
94+
throw ::InternalError("send_data not implemented");
95+
}
96+
97+
private:
98+
NodeImpl& node_;
99+
const char* tag_;
100+
};
101+
102+
using AppRequirementsServiceNodeImpl =
103+
GenericServiceNodeImpl<AppRequirementsServiceServer_IServerImplementation>;
104+
using HWConstraintsServiceNodeImpl =
105+
GenericServiceNodeImpl<HWConstraintsServiceServer_IServerImplementation>;
106+
using HWResourcesServiceNodeImpl =
107+
GenericServiceNodeImpl<HWResourcesServiceServer_IServerImplementation>;
108+
using CarbonFootprintServiceNodeImpl =
109+
GenericServiceNodeImpl<CarbonFootprintServiceServer_IServerImplementation>;
110+
using MLModelMetadataServiceNodeImpl =
111+
GenericServiceNodeImpl<MLModelMetadataServiceServer_IServerImplementation>;
112+
using MLModelServiceNodeImpl =
113+
GenericServiceNodeImpl<MLModelServiceServer_IServerImplementation>;
114+
115+
} // namespace core
116+
} // namespace sustainml
117+
118+
#endif // SUSTAINML_CORE_GENERICSERVICENODEIMPL_HPP

0 commit comments

Comments
 (0)