Skip to content

Commit

Permalink
Uncrust test
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 16, 2025
1 parent 934a201 commit 4de5353
Show file tree
Hide file tree
Showing 22 changed files with 1,131 additions and 67 deletions.
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
150 changes: 84 additions & 66 deletions sustainml_cpp/src/cpp/core/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,78 +26,96 @@ using namespace eprosima::fastdds::dds;
namespace sustainml {
namespace core {

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

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

Node::~Node()
{
delete impl_;
}

void Node::spin()
{
impl_->spin();
}

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

Node::Node(
const std::string& name,
const Options& opts)
{
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_;
}

void Node::spin()
{
impl_->spin();
}

bool Node::initialize_subscription(
const char* topic_name,
const char* type_name,
eprosima::fastdds::dds::DataReaderListener* listener,
const Options &opts)
{
return impl_->initialize_subscription(topic_name, type_name, listener, opts);
}
const Options& opts)
{
return impl_->initialize_subscription(topic_name, type_name, listener, opts);
}

bool Node::initialize_publication(
bool Node::initialize_publication(
const char* topic_name,
const char* type_name,
const Options &opts)
{
return impl_->initialize_publication(topic_name, type_name, opts);
}

void Node::publish_node_status()
{
impl_->publish_node_status();
}

void Node::terminate()
{
NodeImpl::terminate();
}

const std::string& Node::name()
{
return impl_->node_status_.node_name();
}

const Status& Node::status()
{
return impl_->node_status_.node_status();
}

void Node::status(const Status &status)
{
impl_->node_status_.node_status(status);
}

std::weak_ptr<Dispatcher> Node::get_dispatcher()
{
return impl_->get_dispatcher();
}

const std::vector<eprosima::fastdds::dds::DataWriter*>& Node::writers()
{
return impl_->writers_;
}
const Options& opts)
{
return impl_->initialize_publication(topic_name, type_name, opts);
}

void Node::publish_node_status()
{
impl_->publish_node_status();
}

void Node::terminate()
{
NodeImpl::terminate();
}

const std::string& Node::name()
{
return impl_->node_status_.node_name();
}

const Status& Node::status()
{
return impl_->node_status_.node_status();
}

void Node::status(
const Status& status)
{
impl_->node_status_.node_status(status);
}

std::weak_ptr<Dispatcher> Node::get_dispatcher()
{
return impl_->get_dispatcher();
}

const std::vector<eprosima::fastdds::dds::DataWriter*>& Node::writers()
{
return impl_->writers_;
}

} // namespace core
} // namespace sustainml
Loading

0 comments on commit 4de5353

Please sign in to comment.