ADTF
Loading...
Searching...
No Matches
rpc_object_client.h
Go to the documentation of this file.
1
7#pragma once
8
10#include <adtf_utils.h>
12#include <memory>
13
14namespace adtf
15{
16 namespace remote
17 {
18 namespace ant
19 {
20
21 template<typename INTERFACE>
22 class rpc_object_client_ptr : public IRPCObjectClientPtr
23 {
24 private:
25 std::shared_ptr<IRPCObjectClient> m_pObjectCLient;
26 INTERFACE* m_pInterface = nullptr;
27
28 public:
29 rpc_object_client_ptr() = default;
30 rpc_object_client_ptr(const rpc_object_client_ptr& oVal):
31 m_pObjectCLient(oVal.m_pObjectCLient), m_pInterface(oVal.m_pInterface)
32 {
33 }
34 rpc_object_client_ptr& operator=(const rpc_object_client_ptr& oVal)
35 {
36 m_pObjectCLient = oVal.m_pObjectCLient;
37 m_pInterface = oVal.m_pInterface;
38 return *this;
39 }
40 rpc_object_client_ptr(rpc_object_client_ptr&& oVal)
41 {
42 std::swap(m_pObjectCLient, oVal.m_pObjectCLient);
43 std::swap(m_pInterface, oVal.m_pInterface);
44 }
45 rpc_object_client_ptr& operator=(rpc_object_client_ptr&& oVal)
46 {
47 std::swap(m_pObjectCLient, oVal.m_pObjectCLient);
48 std::swap(m_pInterface, oVal.m_pInterface);
49 return *this;
50 }
51
52 rpc_object_client_ptr(const std::shared_ptr<IRPCObjectClient>& pObjectCLient)
53 {
54 Reset(pObjectCLient);
55 }
56 rpc_object_client_ptr& operator=(const std::shared_ptr<IRPCObjectClient>& pObjectCLient)
57 {
58 Reset(pObjectCLient);
59 return *this;
60 }
61
62 ~rpc_object_client_ptr()
63 {
64 Reset();
65 }
66
67 explicit operator bool() const
68 {
69 return (m_pInterface != nullptr);
70 }
71
72 const std::shared_ptr<IRPCObjectClient>& GetObjectClient() const
73 {
74 return m_pObjectCLient;
75 }
76
77 INTERFACE& GetInterface() const
78 {
79 return *m_pInterface;
80 }
81
82 INTERFACE* operator->() const
83 {
84 return m_pInterface;
85 }
86
87 tResult Reset(const std::shared_ptr<IRPCObjectClient>& oObject) override
88 {
89 if (oObject)
90 {
91 Reset();
92 // Technically accepting more derrived clients too, but requiring at least INTERFACE.
93 if constexpr (std::is_base_of_v<ucom::IObject, INTERFACE>)
94 {
95 m_pInterface = ucom::ucom_cast<INTERFACE*>(oObject.get());
96 }
97 else
98 {
99 m_pInterface = dynamic_cast<INTERFACE*>(oObject.get());
100 }
101 RETURN_IF_POINTER_NULL(m_pInterface);
102 m_pObjectCLient = oObject;
103 }
104 else
105 {
106 Reset();
107 }
109 }
110
111 void Reset()
112 {
113 m_pInterface = nullptr;
114 m_pObjectCLient.reset();
115 }
116 };
117
118 template<typename INTERFACE, typename RPC_CLIENT_OBJECT_FACTORY>
119 rpc_object_client_ptr<INTERFACE> make_rpc_object_client_ptr(const char* strFullURL)
120 {
122 RPC_CLIENT_OBJECT_FACTORY::CreateClient(oObj, adtf::ucom::get_iid<INTERFACE>(), strFullURL);
123 return oObj;
124 }
125
126 template<typename INTERFACE, typename RPC_CLIENT_OBJECT_FACTORY>
127 rpc_object_client_ptr<INTERFACE> make_rpc_object_client_ptr(const char* strHostURL, const char* strObjectName)
128 {
130 RPC_CLIENT_OBJECT_FACTORY::CreateClient(oObj, adtf::ucom::get_iid<INTERFACE>(), strHostURL, strObjectName);
131 return oObj;
132 }
133
134 }
135
136 using ant::rpc_object_client_ptr;
137 using ant::make_rpc_object_client_ptr;
138 }
139}
A_UTILS_NS::cResult tResult
For backwards compatibility and to bring latest version into scope.
Definition result.h:736
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
Definition result.h:29
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
Definition result.h:49
Definition rpc_object_client_intf.h:27
Definition rpc_object_client.h:23
Namespace for all functionality of the ADTF Remote SDK provided since v3.0.
Definition adtf_remote_clock_intf.h:16
Namespace for the ADTF Remote SDK.
Definition adtf_client_connector.h:16
InterfacePointerType ucom_cast(ObjectPointerType i_pObject) noexcept
Alias always bringing the latest version of ant::ucom_cast() into scope.
Definition ucom_cast.h:157
constexpr const char * get_iid() noexcept
Alias bringing the latest version of ant::get_iid() into scope.
Definition adtf_iid.h:429
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtf_client_connector.h:14