Skip to content

Commit

Permalink
Logger [4959] (#77)
Browse files Browse the repository at this point in the history
* Refs #4961. Add spdlog submodule.

* Refs #4961. Add logget functions.

* Refs #4961. Add log to UDP server in Linux.

* Refs #4961. Add log to ProxyClient and Root.

* Refs #4961. Add log to AgentDiscoverer and DiscoveyServer.

* Ref #4961. Replace Logger function by macros.

* Refs #4961. Add hexadecimal output to Logger.

* Refs #4961. Add log to InputMessage.

* Refs #4961. Add log to OutputMessage.

* Refs #4961. Add log to UDPServerLinux.

* Refs #4961. Add log warnings to Root.

* Refs #4961. Add warnings to ProxyClient.

* Refs #4961. Remove unused functions in InputMessage.

* Refs #4961. Remove log in InputMessage and OutputMessage headers.

* Refs #4961. Add operator<< to EndPoint.

* Refs #4961. Add session log to server.

* Refs #4961. Add Logger class.

* Refs #4961. Change log message format and add Color class to utils.

* Refs #4961. Adapt logs to new format.

* Refs #4861. Add write and read log.

* Refs #4961. Implement logs message macro.

* Refs #4961. Clean Logger class.

* Refs #4961. Remove unnecessary check at ProxyClient.

* Refs #4961. Add create object log in ProxyClient.

* Refs #4961. Add log patterns.

* Refs #4961. Modify object_id policy in Agent API.

* Refs #4961. Add delete object function to Agent API.

* Refs #4961. Modify object to raw convertion policy.

* Refs #4961. Add log to TCP server on Linux.

* Refs #4961. Add log to Serial server on Linux.

* Refs #4961. Fix Windows compilation errors.

* Refs #4961. Add decorate macro for logger messages.

* Refs #4961. Add suffix to object_ids in logger.

* Refs #4959. Remove unnecessary comments.

* Refs 4959. Fix memcheck errors.

* Refs #4959. Fix rebase errors.

* Logger PR review (#82)

* Add Doxygen comments.
Fix typo.

* Add write documentation.

* Remove redundant variables.

* Refactor payload deserialize.

* Improve logger macro API.

* Add QTCreator files to .gitignore.

* Refs #4949. Fix doc comments and message's logging. (#83)

* Update src/cpp/Root.cpp

Co-Authored-By: Borja Outerelo <[email protected]>

* Refs #4959. Attend pull request comments.
  • Loading branch information
julionce authored and BorjaOuterelo committed May 24, 2019
1 parent c5926a2 commit a24ab71
Show file tree
Hide file tree
Showing 63 changed files with 1,768 additions and 735 deletions.
35 changes: 32 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Created by https://www.gitignore.io/api/c,vim,c++,linux,cmake,eclipse,windows,sublimetext,visualstudio,visualstudiocode
# Created by https://www.gitignore.io/api/c,vim,c++,linux,cmake,eclipse,windows,sublimetext,visualstudio,visualstudiocode,qtcreator
# Edit at https://www.gitignore.io/?templates=c,vim,c++,linux,cmake,eclipse,windows,sublimetext,visualstudio,visualstudiocode,qtcreator

### C ###
# Prerequisites
Expand Down Expand Up @@ -531,4 +531,33 @@ __pycache__/
# By default, sensitive information, such as encrypted password
# should be stored in the .pubxml.user file.

# End of https://www.gitignore.io/api/c,vim,c++,linux,cmake,eclipse,windows,sublimetext,visualstudio,visualstudiocode
### QtCreator ###
# gitignore for Qt Creator like IDE for pure C/C++ project without Qt
#
# Reference: http://doc.qt.io/qtcreator/creator-project-generic.html



# Qt Creator autogenerated files


# A listing of all the files included in the project
*.files

# Include directories
*.includes

# Project configuration settings like predefined Macros
*.config

# Qt Creator settings
*.creator

# User project settings
*.creator.user*

# Qt Creator backups
*.autosave


# End of https://www.gitignore.io/api/c,vim,c++,linux,cmake,eclipse,windows,sublimetext,visualstudio,visualstudiocode,qtcreator
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "thirdparty/uxrclient"]
path = thirdparty/uxrclient
url = https://github.com/eProsima/Micro-XRCE-DDS-Client.git
[submodule "thirdparty/spdlog"]
path = thirdparty/spdlog
url = https://github.com/gabime/spdlog.git
26 changes: 22 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ option(PROFILE_FAST_MIDDLEWARE "Activate the FastMiddleware profile." ON)
option(PROFILE_CED_MIDDLEWARE "Activate the CedMiddleware profile." ON)
option(PROFILE_DISCOVERY "Activate the Discovery profile." ON)
option(PROFILE_P2P "Activate the P2P discovery profile." ON)
option(PROFILE_LOGGER "Active logger profile." ON)

# Create source files with the define
configure_file(${PROJECT_SOURCE_DIR}/include/uxr/agent/config.hpp.in
Expand All @@ -108,9 +109,16 @@ configure_file(${PROJECT_SOURCE_DIR}/include/uxr/agent/config.hpp.in
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake/modules)
include(${PROJECT_SOURCE_DIR}/cmake/common/eprosima_libraries.cmake)
eprosima_find_package(fastcdr REQUIRED)
eprosima_find_package(fastrtps REQUIRED)
eprosima_find_package(uxrclient REQUIRED)
eprosima_find_thirdparty(Asio asio)
if(PROFILE_P2P)
eprosima_find_package(uxrclient)
endif()
if(PROFILE_FAST_MIDDLEWARE)
eprosima_find_package(fastrtps REQUIRED)
endif()
if(PROFILE_LOGGER)
eprosima_find_package(spdlog REQUIRED)
endif()

###############################################################################
# Targets
Expand Down Expand Up @@ -150,6 +158,8 @@ set(SRCS
src/cpp/types/XRCETypes.cpp
src/cpp/types/MessageHeader.cpp
src/cpp/types/SubMessageHeader.cpp
src/cpp/message/InputMessage.cpp
src/cpp/message/OutputMessage.cpp
$<$<BOOL:${VERBOSE}>:src/cpp/libdev/MessageOutput.cpp>
src/cpp/transport/Server.cpp
src/cpp/transport/udp/UDPServerBase.cpp
Expand All @@ -169,14 +179,16 @@ set(SRCS
$<$<BOOL:${PROFILE_P2P}>:src/cpp/p2p/InternalClient.cpp>
)

# Executable
# Library
add_library(${PROJECT_NAME} ${SRCS})
target_link_libraries(${PROJECT_NAME}
PUBLIC
fastcdr
PRIVATE
$<$<BOOL:${PROFILE_FAST_MIDDLEWARE}>:fastrtps>
$<$<BOOL:${PROFILE_LOGGER}>:spdlog::spdlog>
microxrcedds_client
$<$<PLATFORM_ID:Linux>:pthread>
)
target_include_directories(${PROJECT_NAME}
PUBLIC
Expand All @@ -187,8 +199,14 @@ target_include_directories(${PROJECT_NAME}
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/cpp>
${ASIO_INCLUDE_DIR}
)

# Executable
add_executable(MicroXRCEAgent microxrce_agent.cpp)
target_link_libraries(MicroXRCEAgent PRIVATE ${PROJECT_NAME})
target_link_libraries(MicroXRCEAgent
PRIVATE
${PROJECT_NAME}
$<$<BOOL:${PROFILE_LOGGER}>:spdlog::spdlog>
)

# XML default profile used to launch exec in the building folder
file(COPY ${PROJECT_SOURCE_DIR}/agent.refs
Expand Down
100 changes: 80 additions & 20 deletions include/uxr/agent/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ class Agent
DATAREADER_OBJK = 0x06
};

/**
* @brief Generates an XRCEObject identifier from a prefix and an ObjectKind identifier.
* @param prefix The XRCEObject's prefix.
* @param object_kind The XRCEObject's kind.
* @return The XRCEObject's identifier.
*/
static uint16_t get_object_id(uint16_t prefix, ObjectKind object_kind)
{
return uint16_t((uint16_t(prefix) << 4) + object_kind);
}

Agent() = delete;
~Agent() = delete;

Expand Down Expand Up @@ -171,6 +160,19 @@ class Agent
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes the Participant from the ProxyClient.
* This operation removes all the participant hiearchy.
* @param client_key The identifier of the ProxyClient to delete from.
* @param participant_id The identifier of the Participant to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_participant(
uint32_t client_key,
uint16_t participant_id,
OpResult& op_result);

/**
* @brief Creates a Topic from a reference in the ProxyClient identified by the client_key.
* The Topic is associated with the Participant identifier by the participant_id.
Expand Down Expand Up @@ -209,6 +211,19 @@ class Agent
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes the Topic from the ProxyClient.
* This operation removes all the DataWriters or DataReaders associated with the Topic.
* @param client_key The identifier of the ProxyClient to delete from.
* @param topic_id The identifier of the Topic to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_topic(
uint32_t client_key,
uint16_t topic_id,
OpResult& op_result);

/**
* @brief Creates a Publisher from an XML in the ProxyClient identified by the client_key.
* The Publisher is associated with the Participant identifier by the participant_id.
Expand All @@ -228,6 +243,19 @@ class Agent
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes the publisher from a ProxyClient.
* This operation removes all the DataWriters associated with the Publisher.
* @param client_key The identifier of the ProxyClient to delete from.
* @param publisher_id The identifier of the Publisher to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_publisher(
uint32_t client_key,
uint16_t publisher_id,
OpResult& op_result);

/**
* @brief Creates a Subscriber from an XML in the ProxyClient identified by the client_key.
* The Subscriber is associated with the Participant identifier by the participant_id.
Expand All @@ -247,6 +275,20 @@ class Agent
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes the subscriber from a ProxyClient.
* This operation removes all the DataReaders associated with the Subscriber.
* @param client_key The identifier of the ProxyClient to delete from.
* @param client_key The identifier of the ProxyClient to delete from.
* @param subscriber_id The identifier of the Subscriber to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_subscriber(
uint32_t client_key,
uint16_t subscriber_id,
OpResult& op_result);

/**
* @brief Creates a DataWriter from a reference in the ProxyClient identified by the client_key.
* The DataWriter is associated with a Publisher identified by publisher_id.
Expand Down Expand Up @@ -285,6 +327,18 @@ class Agent
uint8_t flag,
OpResult& op_result);

/**
* @brief Deletes the DataWriter from a ProxyClient.
* @param client_key The identifier of the ProxyClient to delete from.
* @param datawriter_id The identifier of the DataWriter to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_datawriter(
uint32_t client_key,
uint16_t datawriter_id,
OpResult& op_result);

/**
* @brief Creates a DataReader from a reference in the ProxyClient identified by the client_key.
* The DataReader is associated with a Subscriber identified by subscriber_id.
Expand Down Expand Up @@ -324,18 +378,15 @@ class Agent
OpResult& op_result);

/**
* @brief Deletes an entity identified by the object_id and all its associated entities
* in a ProxyClient identified by the client_key.
* For example, if a Participant is deleted,
* its associated Topics, Publishers, Subscribers, DataWriters and DataReaders will be deleted also.
* @param client_key The identifier of the ProxyClient.
* @param object_id The identifier of the entity to be deleted.
* @brief Deletes the DataReader from a ProxyClient.
* @param client_key The identifier of the ProxyClient to delete from.
* @param datareader_id The identifier of the DataReader to delete.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool delete_object(
UXR_AGENT_EXPORT static bool delete_datareader(
uint32_t client_key,
uint16_t object_id,
uint16_t datareader_id,
OpResult& op_result);

/**
Expand All @@ -356,6 +407,15 @@ class Agent
/**********************************************************************************************
* Write Data.
**********************************************************************************************/
/**
* @brief Writes data using the DataWriter of the ProxyClient.
* @param client_key The identifier of the ProxyClient.
* @param datawriter_id The identifier of the DataWriter to write with.
* @param buf Raw buffer of data to write.
* @param len Lengh to write.
* @param op_result The result status of the operation.
* @return true in case of success and false in other case.
*/
UXR_AGENT_EXPORT static bool write(
uint32_t client_key,
uint16_t datawriter_id,
Expand Down
25 changes: 16 additions & 9 deletions include/uxr/agent/client/ProxyClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ProxyClient
ProxyClient& operator=(ProxyClient&&) = delete;
ProxyClient& operator=(const ProxyClient&) = delete;

dds::xrce::ResultStatus create(
dds::xrce::ResultStatus create_object(
const dds::xrce::CreationMode& creation_mode,
const dds::xrce::ObjectPrefix& objectid_prefix,
const dds::xrce::ObjectVariant& object_representation);
Expand All @@ -62,34 +62,41 @@ class ProxyClient
private:
bool create_object(
const dds::xrce::ObjectId& object_id,
const dds::xrce::ObjectVariant& representation);
const dds::xrce::ObjectVariant& representation,
dds::xrce::ResultStatus& result_status);

bool create_participant(
const dds::xrce::ObjectId& object_id,
const dds::xrce::OBJK_PARTICIPANT_Representation& representation);
const dds::xrce::OBJK_PARTICIPANT_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_topic(
const dds::xrce::ObjectId& object_id,
const dds::xrce::OBJK_TOPIC_Representation& representation);
const dds::xrce::OBJK_TOPIC_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_publisher(
const dds::xrce::ObjectId& object_id,
const dds::xrce::OBJK_PUBLISHER_Representation& representation);
const dds::xrce::OBJK_PUBLISHER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_subscriber(
const dds::xrce::ObjectId& object_id,
const dds::xrce::OBJK_SUBSCRIBER_Representation& representation);
const dds::xrce::OBJK_SUBSCRIBER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_datawriter(
const dds::xrce::ObjectId& object_id,
const dds::xrce::DATAWRITER_Representation& representation);
const dds::xrce::DATAWRITER_Representation& representation,
dds::xrce::ResultStatus& result_status);

bool create_datareader(
const dds::xrce::ObjectId& object_id,
const dds::xrce::DATAREADER_Representation& representation);
const dds::xrce::DATAREADER_Representation& representation,
dds::xrce::ResultStatus& result_status);

private:
dds::xrce::CLIENT_Representation representation_;
const dds::xrce::CLIENT_Representation representation_;
std::unique_ptr<Middleware> middleware_;
std::mutex mtx_;
XRCEObject::ObjectContainer objects_;
Expand Down
1 change: 1 addition & 0 deletions include/uxr/agent/config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace uxr {
#cmakedefine PROFILE_CED_MIDDLEWARE
#cmakedefine PROFILE_DISCOVERY
#cmakedefine PROFILE_P2P
#cmakedefine PROFILE_LOGGER

const uint16_t DISCOVERY_PORT = 7400;
const char* const DISCOVERY_IP = "239.255.0.2";
Expand Down
Loading

0 comments on commit a24ab71

Please sign in to comment.