Skip to content

Commit

Permalink
Services (#132)
Browse files Browse the repository at this point in the history
* Refs #6840. Fix test due to XML parser modifications.

* Refs #6978. Add Requester and Replier types.

* Refs #6978. Add Requester and Replier entities without implementation.

* Refs #6978. Add Requester and Replier functions to Middleware.

* Refs #6978. Implement basic methods for Requester and Replier entities.

* Refs #6978. Add FastRequester and FastReplier declaration.

* Refs #6978. Add FastRequester entity.

* Refs #6978. Implement FastMiddleware::create_requester_by_ref and add related tests.

* Refs #6978. Implement FastRequester onMatched functions.

* Refs #6978. Add FastReplier entity.

* Refs #6978. Implement Requester and Replier API functions.

* Refs #6978. Add Requester and Replier headers entities.

* Implement Middleware::write_request and Middleware::write_reply for Fast middleware.

* Refs #6978. Modify write function for Requester entity.

* Refs #6978. Isolate Reader from DataReader.

* Refs #6978. Implement reading at Replier.

* Refs #6978. Implement reading at Requester.

* Refs #6978. Remove CedMiddleware warning and unnecessary includes at FastEntities.

* Refs #6978. Modify includes in xmlobjects.

* Refs #6978. Add include directories for packages.

* Refs #6978. Implement match functions for Requester and Replier entities.

* Refs #6978. Change Fast RTPS version to 1.8.3.

* Fix rebase.

* Fix CI warning and Windows errors.

* Fix Valgrind warnings.

* Modify FastRequester and FastReplier implementation.

* Udate Fast RTPS and Micro XRCE-DDS Client branches.

Co-authored-by: Borja Outerelo <[email protected]>
  • Loading branch information
Julián Bermúdez Ortega and BorjaOuterelo committed Dec 23, 2019
1 parent 26ad8f4 commit eee265d
Show file tree
Hide file tree
Showing 31 changed files with 3,691 additions and 223 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ if(UAGENT_P2P_PROFILE)
endif()

if(UAGENT_FAST_PROFILE)
set(_fastrtps_version 1.8.2)
set(_fastrtps_tag v1.8.2)
set(_fastrtps_version 1.8.3)
set(_fastrtps_tag b257a33)
list(APPEND _deps "fastrtps\;${_fastrtps_version}")
endif()

Expand All @@ -90,7 +90,7 @@ endif()
###############################################################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
if(NOT UAGENT_SUPERBUILD)
project(microxrcedds_agent VERSION "1.2.0" LANGUAGES C CXX)
project(microxrcedds_agent VERSION "1.3.0" LANGUAGES C CXX)
else()
project(uagent_superbuild NONE)
include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake)
Expand Down Expand Up @@ -170,6 +170,8 @@ set(SRCS
src/cpp/subscriber/Subscriber.cpp
src/cpp/datawriter/DataWriter.cpp
src/cpp/datareader/DataReader.cpp
src/cpp/requester/Requester.cpp
src/cpp/replier/Replier.cpp
src/cpp/object/XRCEObject.cpp
src/cpp/types/XRCETypes.cpp
src/cpp/types/MessageHeader.cpp
Expand Down Expand Up @@ -272,13 +274,18 @@ target_link_libraries(${PROJECT_NAME}
$<$<PLATFORM_ID:Linux>:pthread>
)

target_include_directories(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME} BEFORE
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}>
$<TARGET_PROPERTY:fastcdr,INTERFACE_INCLUDE_DIRECTORIES>
PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/cpp>
$<$<BOOL:${UAGENT_FAST_PROFILE}>:$<TARGET_PROPERTY:fastrtps,INTERFACE_INCLUDE_DIRECTORIES>>
$<$<BOOL:${UAGENT_LOGGER_PROFILE}>:$<TARGET_PROPERTY:spdlog::spdlog,INTERFACE_INCLUDE_DIRECTORIES>>
$<$<BOOL:${UAGENT_P2P_PROFILE}>:$<TARGET_PROPERTY:microxrcedds_client,INTERFACE_INCLUDE_DIRECTORIES>>
$<$<BOOL:${UAGENT_P2P_PROFILE}>:$<TARGET_PROPERTY:microcdr,INTERFACE_INCLUDE_DIRECTORIES>>
)

# Executable
Expand Down Expand Up @@ -460,7 +467,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()

# Install dependencies.
message(WARNING ${UAGENT_DEPENDS})
if(EXISTS ${CMAKE_BINARY_DIR}/temp_install/)
file(GLOB dependencies RELATIVE ${CMAKE_BINARY_DIR}/temp_install ${CMAKE_BINARY_DIR}/temp_install/*)
foreach(dependency ${dependencies})
Expand Down
10 changes: 10 additions & 0 deletions agent.refs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@
<name>Square</name>
<dataType>ShapeType</dataType>
</topic>
<requester profile_name="shapetype_requester"
service_name="shapetype_service"
request_type="request_type"
reply_type="reply_type">
</requester>
<replier profile_name="shapetype_replier"
service_name="shapetype_service"
request_type="request_type"
reply_type="reply_type">
</replier>
</profiles>
112 changes: 111 additions & 1 deletion include/uxr/agent/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ class Agent
/** Identifies a DataWriter. */
DATAWRITER_OBJK = 0x05,
/** Identifies a DataReader. */
DATAREADER_OBJK = 0x06
DATAREADER_OBJK = 0x06,
/** Identifies a Requester. */
REQUESTER_OBJK = 0x07,
/** Identifies a Replier. */
REPLIER_OBJK = 0x08
};

UXR_AGENT_EXPORT Agent();
Expand Down Expand Up @@ -391,6 +395,112 @@ class Agent
uint16_t datareader_id,
OpResult& op_result);

/**
* @brief Creates a Requester from a reference in the ProxyClient identified by the client_key.
* The Requester is associated with a Participant identified by participant_id.
*
* @param client_key The identifier of the ProxyClient.
* @param requester_id The identifier of the Requester to be created.
* @param participant_id The identifier of the Participant associated with the Requester.
* @param ref The reference of the Requester.
* @param flag The flag tha determines the creation mode.
* @param op_result The result status of the operation.
* @return true in case of successful creation and false in other case.
*/
UXR_AGENT_EXPORT bool create_requester_by_ref(
uint32_t client_key,
uint16_t requester_id,
uint16_t participant_id,
const char* ref,
uint8_t flag,
OpResult& op_result);

/**
* @brief Creates a Requester from an XML in the ProxyClient identified by the client_key.
* The Requester is associated with a Participant identified by participant_id.
*
* @param client_key The identifier of the ProxyClient.
* @param requester_id The identifier of the Requester to be created.
* @param participant_id The identifier of the Participant associated with the Requester.
* @param xml The XML that describes the Requester.
* @param flag The flag tha determines the creation mode.
* @param op_result The result status of the operation.
* @return true in case of successful creation and false in other case.
*/
UXR_AGENT_EXPORT bool create_requester_by_xml(
uint32_t client_key,
uint16_t requester_id,
uint16_t participant_id,
const char* xml,
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes a Requester from a ProxyClient.
*
* @param client_key The identifier of the ProxyClient to delete from.
* @param requester_id The identifier of the Requester to delete.
* @param op_result The result status of the operation.
* @return true in case of successful deletion and false in other case.
*/
UXR_AGENT_EXPORT bool delete_requester(
uint32_t client_key,
uint16_t requester_id,
OpResult& op_result);

/**
* @brief Creates a Replier from a reference in the ProxyClient identified by the client_key.
* The Replier is associated with a Participant identified by participant_id.
*
* @param client_key The identifier of the ProxyClient.
* @param replier_id The identifier of the Replier to be created.
* @param participant_id The identifier of the Participant associated with the Replier.
* @param ref The reference of the Replier.
* @param flag The flag tha determines the creation mode.
* @param op_result The result status of the operation.
* @return true in case of successful creation and false in other case.
*/
UXR_AGENT_EXPORT bool create_replier_by_ref(
uint32_t client_key,
uint16_t replier_id,
uint16_t participant_id,
const char* ref,
uint8_t flag,
OpResult& op_result);

/**
* @brief Creates a Replier from an XML in the ProxyClient identified by the client_key.
* The Replier is associated with a Participant identified by participant_id.
*
* @param client_key The identifier of the ProxyClient.
* @param replier_id The identifier of the Replier to be created.
* @param participant_id The identifier of the Participant associated with the Replier.
* @param xml The XML that describes the Requester.
* @param flag The flag tha determines the creation mode.
* @param op_result The result status of the operation.
* @return true in case of successful creation and false in other case.
*/
UXR_AGENT_EXPORT bool create_replier_by_xml(
uint32_t client_key,
uint16_t requester_id,
uint16_t participant_id,
const char* xml,
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes a Replier from a ProxyClient.
*
* @param client_key The identifier of the ProxyClient to delete from.
* @param requester_id The identifier of the Replier to delete.
* @param op_result The result status of the operation.
* @return true in case of successful creation and false in other case.
*/
UXR_AGENT_EXPORT bool delete_replier(
uint32_t client_key,
uint16_t replier_id,
OpResult& op_result);

/**
* @brief Loads a configuration file which provides the references use to create XRCE object by reference.
* This file shall use the
Expand Down
10 changes: 10 additions & 0 deletions include/uxr/agent/client/ProxyClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ class ProxyClient : public std::enable_shared_from_this<ProxyClient>
const dds::xrce::DATAREADER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_requester(
const dds::xrce::ObjectId& object_id,
const dds::xrce::REQUESTER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_replier(
const dds::xrce::ObjectId& object_id,
const dds::xrce::REPLIER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool delete_object_unlock(
const dds::xrce::ObjectId& object_id);

Expand Down
45 changes: 8 additions & 37 deletions include/uxr/agent/datareader/DataReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
#define UXR_AGENT_DATAREADER_DATAREADER_HPP_

#include <uxr/agent/object/XRCEObject.hpp>

#include <condition_variable>
#include <mutex>
#include <thread>
#include <functional>
#include <atomic>
#include <uxr/agent/reader/Reader.hpp>

namespace eprosima {
namespace uxr {
Expand All @@ -30,20 +25,6 @@ class ProxyClient;
class Subscriber;
class Topic;

/**
* Callback data structure.
*/
struct ReadCallbackArgs
{
std::shared_ptr<ProxyClient> client;
dds::xrce::ClientKey client_key;
dds::xrce::StreamId stream_id;
dds::xrce::ObjectId object_id;
dds::xrce::RequestId request_id;
};

typedef const std::function<bool (const ReadCallbackArgs&, std::vector<uint8_t>, std::chrono::milliseconds)> read_callback;

/**
* @brief The DataReader class
*/
Expand Down Expand Up @@ -71,36 +52,26 @@ class DataReader : public XRCEObject

bool read(
const dds::xrce::READ_DATA_Payload& read_data,
read_callback read_cb,
const ReadCallbackArgs& cb_args);
Reader<bool>::WriteFn write_fn,
WriteFnArgs& cb_args);

private:
DataReader(
const dds::xrce::ObjectId& object_id,
const std::shared_ptr<Subscriber>& subscriber,
const std::shared_ptr<Topic>& topic);

bool start_read(
const dds::xrce::DataDeliveryControl& delivery_control,
read_callback read_cb,
const ReadCallbackArgs& cb_args);

bool stop_read();

void read_task(
dds::xrce::DataDeliveryControl delivery_control,
read_callback read_cb,
ReadCallbackArgs cb_args);
bool read_fn(
bool,
std::vector<uint8_t>& data,
std::chrono::milliseconds timeout);

private:
std::shared_ptr<Subscriber> subscriber_;
std::shared_ptr<Topic> topic_;
std::atomic<bool> running_cond_;
std::thread read_thread_;
std::mutex mtx_;
Reader<bool> reader_;
};


} // namespace uxr
} // namespace eprosima

Expand Down
6 changes: 6 additions & 0 deletions include/uxr/agent/logger/Logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#define UXR_SUBSCRIBER_ID_STR "subscriber_id"
#define UXR_DATAWRITER_ID_STR "datawriter_id"
#define UXR_DATAREADER_ID_STR "datareader_id"
#define UXR_REQUESTER_ID_STR "requester_id"
#define UXR_REPLIER_ID_STR "replier_id"
#define UXR_LEN_STR "len"
#define UXR_DATA_STR "data"

Expand All @@ -61,6 +63,8 @@
#define UXR_SUBSCRIBER_ID_FORMAT "0x{:03X}(4)"
#define UXR_DATAWRITER_ID_FORMAT "0x{:03X}(5)"
#define UXR_DATAREADER_ID_FORMAT "0x{:03X}(6)"
#define UXR_REQUESTER_ID_FORMAT "0x{:03X}(7)"
#define UXR_REPLIER_ID_FORMAT "0x{:03X}(8)"
#define UXR_LEN_FORMAT "{}"
#define UXR_DATA_FORMAT "{:X}"
#define UXR_STATUS_FORMAT "{:<30} | "
Expand All @@ -81,6 +85,8 @@
#define UXR_CREATE_SUBSCRIBER_PATTERN UXR_CREATE_FORMAT_BASE(SUBSCRIBER_ID) UXR_ADD_FIELD(PARTICIPANT_ID)
#define UXR_CREATE_DATAWRITER_PATTERN UXR_CREATE_FORMAT_BASE(DATAWRITER_ID) UXR_ADD_FIELD(PUBLISHER_ID)
#define UXR_CREATE_DATAREADER_PATTERN UXR_CREATE_FORMAT_BASE(DATAREADER_ID) UXR_ADD_FIELD(SUBSCRIBER_ID)
#define UXR_CREATE_REQUESTER_PATTERN UXR_CREATE_FORMAT_BASE(REQUESTER_ID) UXR_ADD_FIELD(PARTICIPANT_ID)
#define UXR_CREATE_REPLIER_PATTERN UXR_CREATE_FORMAT_BASE(REPLIER_ID) UXR_ADD_FIELD(PARTICIPANT_ID)
#define UXR_MESSAGE_PATTERN UXR_FIELD(CLIENT_KEY) UXR_ADD_FIELD(LEN)
#define UXR_MESSAGE_WITH_DATA_PATTERN UXR_MESSAGE_PATTERN UXR_ADD_FIELD(DATA)

Expand Down
Loading

0 comments on commit eee265d

Please sign in to comment.