Skip to content

Commit

Permalink
sync-with-eclipse-ecal-2024-05-16-1
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed May 16, 2024
1 parent 95b27b8 commit 68cc1e3
Show file tree
Hide file tree
Showing 36 changed files with 1,238 additions and 307 deletions.
9 changes: 7 additions & 2 deletions ecal/core/src/service/ecal_service_client_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -751,7 +751,12 @@ namespace eCAL
const auto port_to_use = (protocol_version == 0 ? iter.tcp_port_v0 : iter.tcp_port_v1);

// Create the client and add it to the map
const auto new_client_session = client_manager->create_client(static_cast<uint8_t>(protocol_version), iter.hname, port_to_use, event_callback);
const std::vector<std::pair<std::string, uint16_t>> endpoint_list
{
{iter.hname, port_to_use},
{iter.hname + ".local", port_to_use}, // TODO: Make this configurable from the ecal.ini
};
const auto new_client_session = client_manager->create_client(static_cast<uint8_t>(protocol_version), endpoint_list, event_callback);
if (new_client_session)
m_client_map[iter.key] = new_client_session;
}
Expand Down
4 changes: 2 additions & 2 deletions ecal/core/src/service/ecal_service_singleton_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@ namespace eCAL
eCAL::Logging::Log(eCAL_Logging_eLogLevel::log_level_debug1, "[" + node_name + "] " + message);
break;
case LogLevel::Info:
eCAL::Logging::Log(eCAL_Logging_eLogLevel::log_level_info, "[" + node_name + "] " + message);
eCAL::Logging::Log(eCAL_Logging_eLogLevel::log_level_debug1, "[" + node_name + "] " + message);
break;
case LogLevel::Warning:
eCAL::Logging::Log(eCAL_Logging_eLogLevel::log_level_warning, "[" + node_name + "] " + message);
Expand Down
8 changes: 1 addition & 7 deletions ecal/core_pb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2019 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -69,10 +69,4 @@ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)

ecal_install_library(${PROJECT_NAME})

if(BUILD_PY_BINDING)
protobuf_generate_python_ext(python_sources ${PYTHON_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src ${ProtoFiles})
target_sources(${PROJECT_NAME} PRIVATE ${python_sources})
set_source_files_properties(${python_sources} PROPERTIES HEADER_FILE_ONLY TRUE)
endif()

set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER core)
5 changes: 3 additions & 2 deletions ecal/core_pb/src/ecal/core/pb/ecal.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,8 @@ message Content // topic content

enum eCmdType // command type
{
reserved 7 to 11;
// Reserved fields in enums are not supported in protobuf 3.0
// reserved 7 to 11;

bct_none = 0; // undefined command
bct_set_sample = 1; // set sample content
Expand Down
5 changes: 3 additions & 2 deletions ecal/core_pb/src/ecal/core/pb/layer.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,8 @@ message ConnnectionPar // connection parameter for read

enum eTLayerType // transport layer
{
reserved 2, 3, 42;
// Reserved fields in enums are not supported in protobuf 3.0
// reserved 2, 3, 42;

tl_none = 0; // undefined
tl_ecal_udp_mc = 1; // ecal udp multicast
Expand Down
11 changes: 8 additions & 3 deletions ecal/service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ========================= eCAL LICENSE =================================
#
# Copyright (C) 2016 - 2023 Continental Corporation
# Copyright (C) 2016 - 2024 Continental Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,15 +16,20 @@
#
# ========================= eCAL LICENSE =================================

cmake_minimum_required(VERSION 3.16)
project(ecal_service)

# Main library
add_subdirectory(ecal_service)

# Samples
if(ECAL_CORE_BUILD_SAMPLES)
add_subdirectory(sample)
add_subdirectory(samples/sample_client)
add_subdirectory(samples/sample_server)
add_subdirectory(samples/sample_standalone)
endif()

# Tests
if(ECAL_CORE_BUILD_TESTS)
add_subdirectory(test)
endif()
endif()
22 changes: 13 additions & 9 deletions ecal/service/ecal_service/include/ecal/service/client_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,16 @@
#include <cstdint>
#include <map>
#include <memory>

#include <ecal/service/client_session.h>
#include <mutex>
#include <string>
#include <utility>
#include <vector>

#include <asio.hpp>

#include <ecal/service/logger.h>

#include <ecal/service/client_session.h> // IWYU pragma: export

namespace eCAL
{
Expand Down Expand Up @@ -141,16 +147,14 @@ namespace eCAL
* stopped from this central place.
*
* @param protocol_version The protocol version to use for the client session. If 0, the legacy buggy protocol will be used.
* @param address The address of the server to connect to
* @param port The port of the server to connect to
* @param server_list A list of endpoints to connect to. Must not be empty. The endpoints will be tried in the given order until a working endpoint is found.
* @param event_callback The callback, that will be called, when the client has connected to the server or disconnected from it. The callback will be executed in the io_context thread.
*
* @return A shared_ptr to the newly created ClientSession instance
*/
std::shared_ptr<ClientSession> create_client(std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const ClientSession::EventCallbackT& event_callback);
std::shared_ptr<ClientSession> create_client(std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const ClientSession::EventCallbackT& event_callback);

/**
* @brief Returns the number of managed client sessions
Expand Down
91 changes: 51 additions & 40 deletions ecal/service/ecal_service/include/ecal/service/client_session.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,8 @@
#include <functional>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#ifdef _MSC_VER
#pragma warning(push)
Expand All @@ -34,6 +36,7 @@
#endif

#include <ecal/service/client_session_types.h>
#include <ecal/service/error.h>
#include <ecal/service/logger.h>
#include <ecal/service/state.h>

Expand Down Expand Up @@ -133,43 +136,38 @@ namespace eCAL
*
* @param io_context The io_context to use for the session and all callbacks.
* @param protocol_version The protocol version to use for the session. When this is 0, the legacy buggy protocol is used.
* @param address The address of the server to connect to. May be an IP or a Hostname, IPv6 is supported.
* @param port The port of the server to connect to.
* @param server_list A list of endpoints to connect to. Must not be empty. The endpoints will be tried in the given order until a working endpoint is found.
* @param event_callback The callback to be called when the session's state changes, i.e. when the session successfully connected to a server or disconnected from it.
* @param logger The logger to use for logging.
* @param delete_callback The callback to be called when the session is deleted. This is useful for the eCAL::service::ClientManager to keep track of the number of active sessions.
*
* @return The new ClientSession instance as a shared_ptr.
*/
static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const EventCallbackT& event_callback
, const LoggerT& logger
, const DeleteCallbackT& delete_callback);
static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const EventCallbackT& event_callback
, const LoggerT& logger
, const DeleteCallbackT& delete_callback);

static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const EventCallbackT& event_callback
, const LoggerT& logger = default_logger("Service Client"));
static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const EventCallbackT& event_callback
, const LoggerT& logger = default_logger("Service Client"));

static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const EventCallbackT& event_callback
, const DeleteCallbackT& delete_callback);
static std::shared_ptr<ClientSession> create(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const EventCallbackT& event_callback
, const DeleteCallbackT& delete_callback);

protected:
ClientSession(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const EventCallbackT& event_callback
, const LoggerT& logger);
ClientSession(const std::shared_ptr<asio::io_context>& io_context
, std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const EventCallbackT& event_callback
, const LoggerT& logger);

public:
// Delete copy constructor and assignment operator
Expand Down Expand Up @@ -227,28 +225,41 @@ namespace eCAL
eCAL::service::Error call_service(const std::shared_ptr<const std::string>& request, std::shared_ptr<std::string>& response);

/**
* @brief Get the address that this client session has been created with.
* @brief Get the host that this client is connected to.
*
* This function returns the address that this client session has been
* created with. It will not return the address of the server that this
* client session is connected to, which would actually be the same
* address, but probably resolved to an IP.
* Get the host that this client is connected to.
* If the client is not connected, this function will return an empty
* string. Otherwise, it will return the hostname from the list
* server_list that the client is connected to.
*
* @return The address that this client session has been created with.
* The host is not resolved to an IP address. Use get_remote_endpoint()
* to get the actual IP address.
*
* @return The host that this client is connected to.
*/
std::string get_address() const;
std::string get_host() const;

/**
* @brief Get the port that this client session has been created with.
* @brief Get the port that this client session is connected to.
*
* This function returns the port that this client session has been
* created with. It is not said, that the connection has been established
* successfully.
* Get the port that this client session is connected to. If the client
* is not connected, this function will return 0. Otherwise, it will
* return the port from the list server_list that the client is connected
* to.
*
* @return The port that this client session has been created with.
* @return The port that this client is connected to
*/
std::uint16_t get_port() const;

/**
* @brief Get the remote endpoint that this client session is connected to.
*
* Get the remote endpoint that this client session is connected to. Only
* valid, if the client session is actually connected to a server. If a
* hostname was given, this function will return the resolved IP address.
*/
asio::ip::tcp::endpoint get_remote_endpoint() const;

/**
* @brief Get the state of this client session.
*
Expand Down
10 changes: 7 additions & 3 deletions ecal/service/ecal_service/include/ecal/service/server_manager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,14 @@
#include <cstdint>
#include <map>
#include <memory>

#include <ecal/service/server.h>
#include <mutex>

#include <asio.hpp>

#include <ecal/service/logger.h>

#include <ecal/service/server.h> // IWYU pragma: export

namespace eCAL
{
namespace service
Expand Down
21 changes: 14 additions & 7 deletions ecal/service/ecal_service/src/client_manager.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ========================= eCAL LICENSE =================================
*
* Copyright (C) 2016 - 2019 Continental Corporation
* Copyright (C) 2016 - 2024 Continental Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,14 +17,22 @@
* ========================= eCAL LICENSE =================================
*/

#include <ecal/service/client_manager.h>

#include <cstddef>
#include <cstdint>
#include <ecal/service/client_manager.h>
#include <map>
#include <memory>
#include <mutex>
#include <string>

#include <asio.hpp>

#include <ecal/service/client_session.h>
#include <ecal/service/logger.h>
#include <utility>
#include <vector>

namespace eCAL
{
namespace service
Expand Down Expand Up @@ -52,10 +60,9 @@ namespace eCAL
///////////////////////////////////////////////////////
// Public API
///////////////////////////////////////////////////////
std::shared_ptr<ClientSession> ClientManager::create_client(std::uint8_t protocol_version
, const std::string& address
, std::uint16_t port
, const ClientSession::EventCallbackT& event_callback)
std::shared_ptr<ClientSession> ClientManager::create_client(std::uint8_t protocol_version
, const std::vector<std::pair<std::string, std::uint16_t>>& server_list
, const ClientSession::EventCallbackT& event_callback)
{
const std::lock_guard<std::mutex> lock(client_manager_mutex_);
if (stopped_)
Expand All @@ -74,7 +81,7 @@ namespace eCAL
}
};

auto client = ClientSession::create(io_context_, protocol_version, address, port, event_callback, logger_, deleter);
auto client = ClientSession::create(io_context_, protocol_version, server_list, event_callback, logger_, deleter);
sessions_.emplace(client.get(), client);
return client;
}
Expand Down
Loading

0 comments on commit 68cc1e3

Please sign in to comment.