ADTF  3.18.2
rpc_object_client.h
Go to the documentation of this file.
1 
7 #pragma once
8 
10 #include <adtf_utils.h>
11 #include <adtfucom3/adtf_ucom3.h>
12 #include <memory>
13 
14 namespace adtf
15 {
16  namespace remote
17  {
18  namespace ant
19  {
20 
21  template<typename INTERFACE>
23  {
24  private:
25  std::shared_ptr<IRPCObjectClient> m_pObjectCLient;
26  INTERFACE* m_pInterface = nullptr;
27 
28  public:
29  rpc_object_client_ptr() = default;
31  {
32  Reset(oVal.m_pObjectCLient);
33  }
34  rpc_object_client_ptr& operator=(const rpc_object_client_ptr& oVal)
35  {
36  Reset(oVal.m_pObjectCLient);
37  return *this;
38  }
40  {
41  std::swap(m_pObjectCLient, oVal.m_pObjectCLient);
42  std::swap(m_pInterface, oVal.m_pInterface);
43  }
45  {
46  std::swap(m_pObjectCLient, oVal.m_pObjectCLient);
47  std::swap(m_pInterface, oVal.m_pInterface);
48  return *this;
49  }
50 
51  rpc_object_client_ptr(const std::shared_ptr<IRPCObjectClient>& pObjectCLient)
52  {
53  Reset(pObjectCLient);
54  }
55  rpc_object_client_ptr& operator=(const std::shared_ptr<IRPCObjectClient>& pObjectCLient)
56  {
57  Reset(pObjectCLient);
58  return *this;
59  }
60 
62  {
63  Reset();
64  }
65 
66  explicit operator bool() const
67  {
68  return (m_pInterface != nullptr);
69  }
70 
71  const std::shared_ptr<IRPCObjectClient>& GetObjectClient() const
72  {
73  return m_pObjectCLient;
74  }
75 
76  INTERFACE& GetInterface() const
77  {
78  return *m_pInterface;
79  }
80 
81  INTERFACE* operator->() const
82  {
83  return m_pInterface;
84  }
85 
86  tResult Reset(const std::shared_ptr<IRPCObjectClient>& oObject) override
87  {
88  if (oObject)
89  {
90  adtf::util::cString strIID;
91  oObject->GetRPCIID(adtf_string_intf(strIID));
92  if (strIID.IsEqual(adtf::ucom::get_iid<INTERFACE>()))
93  {
94  m_pInterface = dynamic_cast<INTERFACE*>(oObject.get());
95  RETURN_IF_POINTER_NULL(m_pInterface);
96  m_pObjectCLient = oObject;
97  }
98  else
99  {
100  Reset();
101  RETURN_ERROR(ERR_INVALID_INTERFACE);
102  }
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 }
Copyright © Audi Electronics Venture GmbH.
Copyright © Audi Electronics Venture GmbH.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
#define RETURN_IF_POINTER_NULL(_ptr)
Return ERR_POINTER if _ptr is nullptr, which requires the calling function's return type to be tResul...
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
Namespace for entire ADTF SDK.
Copyright © Audi Electronics Venture GmbH.
#define adtf_string_intf(__string__)
The adtf_string_intf Macro helps to easily create a rvalue reference of a adtf::util::cString.
Definition: string_intf.h:371