Skip to content

Commit

Permalink
Test on RequestReplyListener for all Nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Gil Aviles <[email protected]>
  • Loading branch information
Javgilavi committed Jan 15, 2025
1 parent 934a201 commit c0460e3
Show file tree
Hide file tree
Showing 22 changed files with 1,060 additions and 1 deletion.
10 changes: 10 additions & 0 deletions sustainml_cpp/include/sustainml_cpp/core/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace core {
class NodeImpl;
class NodeControlListener;
class Dispatcher;
class RequestReplyListener;
struct Options;

/**
Expand All @@ -76,6 +77,15 @@ class Node
const std::string& name,
const Options& opts);

SUSTAINML_CPP_DLL_API Node(
const std::string& name,
RequestReplyListener& req_res_listener);

SUSTAINML_CPP_DLL_API Node(
const std::string& name,
const Options& opts,
RequestReplyListener& req_res_listener);

SUSTAINML_CPP_DLL_API virtual ~Node();

/**
Expand Down
68 changes: 68 additions & 0 deletions sustainml_cpp/include/sustainml_cpp/core/RequestReplyListener.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @file RequestReplyListener.hpp
*/

#ifndef SUSTAINMLCPP_CORE_REQUESTREPLEIR_HPP
#define SUSTAINMLCPP_CORE_REQUESTREPLEIR_HPP

#include <sustainml_cpp/types/types.hpp>

namespace sustainml {
namespace core {

/**
* @brief This class implement a virtual function for the configuration of each node.
* Each node will need to inherit it and implement their own.
* End user to implement specific callbacks to certain actions.
*
*/
class RequestReplyListener{

public:

/**
* @brief Constructor
*/
RequestReplyListener()
{
}

/**
* @brief Destructor
*/
~RequestReplyListener()
{
}

/**
* Virtual method to be called when a configuration request is received.
*
* @param req The request message
* @param res The response message to send
*/
virtual void on_configuration_request(
types::RequestType& req,
types::ResponseType& res)
{
}

};

} // namespace core
} // namespace sustainml

#endif // SUSTAINMLCPP_CORE_REQUESTREPLEIR_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ class AppRequirementsNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API AppRequirementsNode(
AppRequirementsTaskListener& user_listener);

SUSTAINML_CPP_DLL_API AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER

SUSTAINML_CPP_DLL_API virtual ~AppRequirementsNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ class CarbonFootprintNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API CarbonFootprintNode(
CarbonFootprintTaskListener& listener);

SUSTAINML_CPP_DLL_API CarbonFootprintNode(
CarbonFootprintTaskListener& listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API CarbonFootprintNode(
CarbonFootprintTaskListener& listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API CarbonFootprintNode(
CarbonFootprintTaskListener& listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER
SUSTAINML_CPP_DLL_API virtual ~CarbonFootprintNode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ class HardwareConstraintsNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API HardwareConstraintsNode(
HardwareConstraintsTaskListener& user_listener);

SUSTAINML_CPP_DLL_API HardwareConstraintsNode(
HardwareConstraintsTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API HardwareConstraintsNode(
HardwareConstraintsTaskListener& user_listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API HardwareConstraintsNode(
HardwareConstraintsTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER

SUSTAINML_CPP_DLL_API virtual ~HardwareConstraintsNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ class HardwareResourcesNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API HardwareResourcesNode(
HardwareResourcesTaskListener& user_listener);

SUSTAINML_CPP_DLL_API HardwareResourcesNode(
HardwareResourcesTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API HardwareResourcesNode(
HardwareResourcesTaskListener& user_listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API HardwareResourcesNode(
HardwareResourcesTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER

SUSTAINML_CPP_DLL_API virtual ~HardwareResourcesNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ class MLModelMetadataNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API MLModelMetadataNode(
MLModelMetadataTaskListener& user_listener);

SUSTAINML_CPP_DLL_API MLModelMetadataNode(
MLModelMetadataTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API MLModelMetadataNode(
MLModelMetadataTaskListener& user_listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API MLModelMetadataNode(
MLModelMetadataTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER

SUSTAINML_CPP_DLL_API virtual ~MLModelMetadataNode();
Expand Down
9 changes: 9 additions & 0 deletions sustainml_cpp/include/sustainml_cpp/nodes/MLModelNode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,19 @@ class MLModelNode : public ::sustainml::core::Node
SUSTAINML_CPP_DLL_API MLModelNode(
MLModelTaskListener& user_listener);

SUSTAINML_CPP_DLL_API MLModelNode(
MLModelTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener);

#ifndef SWIG_WRAPPER
SUSTAINML_CPP_DLL_API MLModelNode(
MLModelTaskListener& user_listener,
sustainml::core::Options opts);

SUSTAINML_CPP_DLL_API MLModelNode(
MLModelTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener);
#endif // SWIG_WRAPPER

SUSTAINML_CPP_DLL_API virtual ~MLModelNode();
Expand Down
13 changes: 13 additions & 0 deletions sustainml_cpp/src/cpp/core/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ namespace core {
impl_ = new NodeImpl(this, name, opts);
}

Node::Node(const std::string &name,
RequestReplyListener& req_res_listener)
{
impl_ = new NodeImpl(this, name, req_res_listener);
}

Node::Node(const std::string &name,
const Options& opts,
RequestReplyListener& req_res_listener)
{
impl_ = new NodeImpl(this, name, opts, req_res_listener);
}

Node::~Node()
{
delete impl_;
Expand Down
39 changes: 39 additions & 0 deletions sustainml_cpp/src/cpp/core/NodeImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ NodeImpl::NodeImpl(
, publisher_(nullptr)
, subscriber_(nullptr)
, control_listener_(this)
, req_res_listener_(*new RequestReplyListener())
{
if (!init(name))
{
Expand All @@ -62,6 +63,44 @@ NodeImpl::NodeImpl(
, publisher_(nullptr)
, subscriber_(nullptr)
, control_listener_(this)
, req_res_listener_(*new RequestReplyListener())
{
if (!init(name, opts))
{
EPROSIMA_LOG_ERROR(NODE, "Initialization Failed with the provided Options");
}
}

NodeImpl::NodeImpl(
Node* node,
const std::string& name,
RequestReplyListener& req_res_listener)
: node_(node)
, dispatcher_(new Dispatcher(node_))
, participant_(nullptr)
, publisher_(nullptr)
, subscriber_(nullptr)
, control_listener_(this)
, req_res_listener_(req_res_listener)
{
if (!init(name))
{
EPROSIMA_LOG_ERROR(NODE, "Initialization Failed with the provided Options");
}
}

NodeImpl::NodeImpl(
Node* node,
const std::string& name,
const Options& opts,
RequestReplyListener& req_res_listener)
: node_(node)
, dispatcher_(new Dispatcher(node_))
, participant_(nullptr)
, publisher_(nullptr)
, subscriber_(nullptr)
, control_listener_(this)
, req_res_listener_(req_res_listener)
{
if (!init(name, opts))
{
Expand Down
15 changes: 15 additions & 0 deletions sustainml_cpp/src/cpp/core/NodeImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sustainml_cpp/types/types.hpp>

#include <core/Options.hpp>
#include <core/RequestReplyListener.hpp>
#include <types/typesImplPubSubTypes.hpp>

#include <utility>
Expand Down Expand Up @@ -52,6 +53,7 @@ namespace core {

class Dispatcher;
class Node;
class RequestReplyListener;
struct Options;

/**
Expand Down Expand Up @@ -81,6 +83,17 @@ class NodeImpl
const std::string& name,
const Options& opts);

NodeImpl(
Node* node,
const std::string& name,
RequestReplyListener& req_res_listener);

NodeImpl(
Node* node,
const std::string& name,
const Options& opts,
RequestReplyListener& req_res_listener);

~NodeImpl();

/**
Expand Down Expand Up @@ -153,6 +166,8 @@ class NodeImpl

NodeStatusImpl node_status_;

RequestReplyListener& req_res_listener_;

private:

/**
Expand Down
31 changes: 31 additions & 0 deletions sustainml_cpp/src/cpp/nodes/AppRequirementsNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <common/Common.hpp>
#include <core/Options.hpp>
#include <core/QueuedNodeListener.hpp>
#include <core/RequestReplyListener.hpp>
#include <types/typesImpl.hpp>

using namespace types;
Expand All @@ -49,6 +50,26 @@ AppRequirementsNode::AppRequirementsNode(
init(opts);
}

AppRequirementsNode::AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::RequestReplyListener& req_res_listener)
: Node(common::APP_REQUIREMENTS_NODE, req_res_listener)
, user_listener_(user_listener)
{
sustainml::core::Options opts;
opts.rqos.resource_limits().max_instances = 500;
opts.rqos.resource_limits().max_samples_per_instance = 1;
opts.rqos.durability().kind = eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS;
opts.rqos.reliability().kind = eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS;
opts.rqos.history().kind = eprosima::fastdds::dds::KEEP_LAST_HISTORY_QOS;
opts.rqos.history().depth = 1;

opts.wqos.resource_limits().max_instances = 500;
opts.wqos.resource_limits().max_samples_per_instance = 1;
opts.wqos.durability().kind = eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS;
init(opts);
}

AppRequirementsNode::AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::Options opts)
Expand All @@ -58,6 +79,16 @@ AppRequirementsNode::AppRequirementsNode(
init(opts);
}

AppRequirementsNode::AppRequirementsNode(
AppRequirementsTaskListener& user_listener,
sustainml::core::Options opts,
sustainml::core::RequestReplyListener& req_res_listener)
: Node(common::APP_REQUIREMENTS_NODE, opts, req_res_listener)
, user_listener_(user_listener)
{
init(opts);
}

AppRequirementsNode::~AppRequirementsNode()
{

Expand Down
Loading

0 comments on commit c0460e3

Please sign in to comment.