Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first draft of a new client api #1785

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ecal/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ if(ECAL_CORE_SERVICE)
src/service/ecal_service_client.cpp
src/service/ecal_service_client_impl.cpp
src/service/ecal_service_client_impl.h
src/service/ecal_service_client_id.cpp
src/service/ecal_service_client_id_impl.cpp
src/service/ecal_service_client_id_impl.h
src/service/ecal_service_server.cpp
src/service/ecal_service_server_impl.cpp
src/service/ecal_service_server_impl.h
Expand Down Expand Up @@ -511,6 +514,7 @@ set(ecal_header_cmn
include/ecal/ecal_callback.h
include/ecal/ecal_config.h
include/ecal/ecal_client.h
include/ecal/ecal_client_id.h
include/ecal/ecal_core.h
include/ecal/ecal_deprecate.h
include/ecal/ecal_init.h
Expand Down
3 changes: 2 additions & 1 deletion ecal/core/include/ecal/cimpl/ecal_service_info_cimpl.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 Down Expand Up @@ -32,6 +32,7 @@ enum eCallState
{
call_state_none = 0, //!< undefined
call_state_executed, //!< executed (successfully)
call_state_timeouted, //!< timeout
call_state_failed //!< failed
};

Expand Down
1 change: 1 addition & 0 deletions ecal/core/include/ecal/ecal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ecal/ecal_defs.h>
#include <ecal/ecal_callback.h>
#include <ecal/ecal_client.h>
#include <ecal/ecal_client_id.h>
#include <ecal/ecal_config.h>
#include <ecal/ecal_core.h>
#include <ecal/ecal_log.h>
Expand Down
2 changes: 1 addition & 1 deletion ecal/core/include/ecal/ecal_client.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 Down
201 changes: 201 additions & 0 deletions ecal/core/include/ecal/ecal_client_id.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/* ========================= eCAL LICENSE =================================
*
* 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.
* 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.
*
* ========================= eCAL LICENSE =================================
*/

/**
* @file ecal_client.h
* @brief eCAL client interface
**/

#pragma once

#include <ecal/ecal_deprecate.h>
#include <ecal/ecal_os.h>
#include <ecal/ecal_callback.h>
#include <ecal/ecal_service_info.h>

#include <iostream>
#include <string>
#include <vector>
#include <memory>

namespace eCAL
{
class CServiceClientIDImpl;

/**
* @brief Service client wrapper class.
**/
class CServiceClientID
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: class 'CServiceClientID' defines a non-default destructor, a copy constructor and a copy assignment operator but does not define a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

  class CServiceClientID
        ^

{
public:
/**
* @brief Constructor.
**/
ECAL_API CServiceClientID();

/**
* @brief Constructor.
*
* @param service_name_ Unique service name.
**/
ECAL_API explicit CServiceClientID(const std::string& service_name_);

/**
* @brief Constructor.
*
* @param service_name_ Unique service name.
* @param method_information_map_ Map of method names and corresponding datatype information.
**/
ECAL_API explicit CServiceClientID(const std::string& service_name_, const ServiceMethodInformationMapT& method_information_map_);

/**
* @brief Destructor.
**/
ECAL_API virtual ~CServiceClientID();

/**
* @brief CServiceClients are non-copyable
**/
CServiceClientID(const CServiceClientID&) = delete;

/**
* @brief CServiceClients are non-copyable
**/
CServiceClientID& operator=(const CServiceClientID&) = delete;

/**
* @brief Creates this object.
*
* @param service_name_ Unique service name.
*
* @return True if successful.
**/
ECAL_API bool Create(const std::string& service_name_);

/**
* @brief Creates this object.
*
* @param service_name_ Unique service name.
* @param method_information_map_ Map of method names and corresponding datatype information.
*
* @return True if successful.
**/
ECAL_API bool Create(const std::string& service_name_, const ServiceMethodInformationMapT& method_information_map_);

/**
* @brief Destroys this object.
*
* @return True if successful.
**/
ECAL_API bool Destroy();

/**
* @brief Get the unique service id's for all matching services
*
* @return Service id's of all matching services
**/
ECAL_API std::vector<Registration::SEntityId> GetServiceIDs();

/**
* @brief Blocking call specific service method, response will be returned as pair<bool, SServiceReponse>
*
* @param entity_id_ Unique service entity (service id, process id, host name).
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
*
* @return success state and service response
**/
ECAL_API std::pair<bool, SServiceResponse> CallWithResponse(const Registration::SEntityId& entity_id_, const std::string& method_name_, const std::string& request_, int timeout_ = -1);

/**
* @brief Blocking call specific service method, using callback
*
* @param entity_id_ Unique service entity (service id, process id, host name).
* @param method_name_ Method name.
* @param request_ Request string.
* @param timeout_ Maximum time before operation returns (in milliseconds, -1 means infinite).
*
* @return True if successful.
**/
ECAL_API bool CallWithCallback(const Registration::SEntityId& entity_id_, const std::string& method_name_, const std::string& request_, int timeout_ = -1);

/**
* @brief Add server response callback.
*
* @param callback_ Callback function for server response.
*
* @return True if successful.
**/
ECAL_API bool AddResponseCallback(const ResponseIDCallbackT& callback_);

/**
* @brief Remove server response callback.
*
* @return True if successful.
**/
ECAL_API bool RemResponseCallback();

/**
* @brief Add client event callback function.
*
* @param type_ The event type to react on.
* @param callback_ The callback function to add.
*
* @return True if succeeded, false if not.
**/
ECAL_API bool AddEventCallback(eCAL_Client_Event type_, ClientEventCallbackT callback_);

/**
* @brief Remove client event callback function.
*
* @param type_ The event type to remove.
*
* @return True if succeeded, false if not.
**/
ECAL_API bool RemEventCallback(eCAL_Client_Event type_);

/**
* @brief Retrieve service name.
*
* @return The service name.
**/
ECAL_API std::string GetServiceName();

/**
* @brief Check connection state of a specific server connection.
*
* @param entity_id_ Unique service entity (service id, process id, host name).
*
* @return True if connected, false if not.
**/
ECAL_API bool IsConnected(const Registration::SEntityId& entity_id_);

/**
* @brief Check connection state.
*
* @return True if connected, false if not.
**/
ECAL_API bool IsConnected();

protected:
std::shared_ptr<eCAL::CServiceClientIDImpl> m_service_client_impl;
std::string m_service_name;
};
}
13 changes: 10 additions & 3 deletions ecal/core/include/ecal/ecal_service_info.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 Down Expand Up @@ -53,7 +53,7 @@ namespace eCAL
eCallState call_state; //!< call state (see eCallState)
std::string response; //!< service response
};
using ServiceResponseVecT = std::vector<SServiceResponse>; //!< vector of multiple service responses
using ServiceResponseVecT = std::vector<SServiceResponse>; //!< vector of multiple service responses (deprecated)

/**
* @brief Service method callback function type (low level server interface).
Expand All @@ -67,11 +67,18 @@ namespace eCAL
using MethodCallbackT = std::function<int (const std::string &, const std::string &, const std::string &, const std::string &, std::string &)>;

/**
* @brief Service response callback function type (low level client interface).
* @brief Service response callback function type (low level client interface). (deprecated)
*
* @param service_response_ Service response struct containing the (responding) server informations and the response itself.
**/
using ResponseCallbackT = std::function<void (const struct SServiceResponse &)>;

/**
* @brief Service response callback function type (low level client interface).
* @param entity_id_ Unique service id (entity id, process id, host name, service name, method name)
* @param service_response_ Service response struct containing the (responding) server informations and the response itself.
**/
using ResponseIDCallbackT = std::function<void (const Registration::SEntityId &, const struct SServiceResponse &)>;

using ServiceMethodInformationMapT = std::map<std::string, SServiceMethodInformation>;
}
Loading
Loading