forked from 107-systems/107-Arduino-Cyphal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceClient.hpp
68 lines (51 loc) · 2.27 KB
/
ServiceClient.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020-2023 LXRobotics.
* Author: Alexander Entinger <alexander.entinger@lxrobotics.com>
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/
#ifndef INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_HPP
#define INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_HPP
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include "ServiceClientBase.hpp"
#include "Node.hpp"
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
namespace impl
{
/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
template<typename T_REQ, typename T_RSP, typename OnResponseCb>
class ServiceClient final : public ServiceClientBase<T_REQ>
{
public:
ServiceClient(Node & node_hdl, CanardPortID const response_port_id, CanardMicrosecond const tx_timeout_usec, OnResponseCb on_response_cb)
: _node_hdl{node_hdl}
, _response_port_id{response_port_id}
, _tx_timeout_usec{tx_timeout_usec}
, _on_response_cb{on_response_cb}
, _transfer_id{0}
{ }
virtual ~ServiceClient();
bool request(CanardNodeID const remote_node_id, T_REQ const & req) override;
bool onTransferReceived(CanardRxTransfer const & transfer) override;
private:
Node & _node_hdl;
CanardPortID const _response_port_id;
CanardMicrosecond const _tx_timeout_usec;
OnResponseCb _on_response_cb;
CanardTransferID _transfer_id;
};
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
} /* impl */
/**************************************************************************************
* TEMPLATE IMPLEMENTATION
**************************************************************************************/
#include "ServiceClient.ipp"
#endif /* INC_107_ARDUINO_CYPHAL_SERVICE_CLIENT_HPP */