ADTF  3.18.2
rpc_object_registry.h
Go to the documentation of this file.
1 
15 #ifndef PKG_RPC_OBJECTSERVER_REGISTRY_H_INCLUDED
16 #define PKG_RPC_OBJECTSERVER_REGISTRY_H_INCLUDED
17 
20 #include <rpc/rpc_server.h>
21 
22 #include <map>
23 
24 namespace rpc {
25 
30 public: // types
32  typedef std::pair<std::unique_ptr<a_util::concurrency::shared_mutex>, IRPCObject*> tRPCItem;
33 
34 public:
38  virtual a_util::result::Result RegisterRPCObject(const char* strName, IRPCObject* pObject);
39 
43  virtual a_util::result::Result UnregisterRPCObject(const char* strName);
44 
48  class cLockedRPCObject final {
49  typedef std::pair<a_util::concurrency::shared_mutex*, IRPCObject*> tRPCRawItem;
50  tRPCRawItem m_oItem;
51 
52  public:
54  cLockedRPCObject() = default;
59  cLockedRPCObject(const tRPCItem& oItem);
87  operator bool() const;
88  };
89 
95  virtual cLockedRPCObject GetRPCObject(const char* strName) const;
96 
97 private:
98  mutable a_util::concurrency::shared_mutex m_oObjectsLock;
99  typedef std::map<std::string, tRPCItem> tRPCObjects;
100  tRPCObjects m_oRPCObjects;
101 };
102 
103 } // namespace rpc
104 
105 #endif // PKG_RPC_OBJECTSERVER_REGISTRY_H_INCLUDED
A shared_mutex class as a workaround for std::shared_timed_mutex.
Definition: shared_mutex.h:26
A common result class usable as return value throughout.
Interface of an object that support remote calls.
Definition: rpc_server.h:47
Interface for an RPC server that handles multiple RPC objects.
Definition: rpc_server.h:64
Implements thread safe access to the rpc::IRPCObject object.
cLockedRPCObject(const tRPCItem &oItem)
Construct with an tRPCItem and lock the shared mutex.
~cLockedRPCObject()
DTOR, unlocking any shared lock if previously locked.
cLockedRPCObject(cLockedRPCObject &&)=default
Default move construction.
cLockedRPCObject & operator=(cLockedRPCObject &&)=default
Default move assignment.
IRPCObject * operator->()
Pointer like access to rpc object protected by *this via a shared lock.
cLockedRPCObject & operator=(const cLockedRPCObject &other)
Copy assignment from other.
cLockedRPCObject(const cLockedRPCObject &other)
Create a copy from other and add lock to the shared mutex.
An RPC Server that receives calls via HTTP.
std::pair< std::unique_ptr< a_util::concurrency::shared_mutex >, IRPCObject * > tRPCItem
Type granting thread safe access to an object of type rpc::IRPCObject.
virtual a_util::result::Result UnregisterRPCObject(const char *strName)
Unregisters an RPC object.
virtual a_util::result::Result RegisterRPCObject(const char *strName, IRPCObject *pObject)
Register an RPC object.
virtual cLockedRPCObject GetRPCObject(const char *strName) const
Get thread safe rpc object access by the rpc objects name.
Common include for Result functionality.
RPC Protocol declaration.
Public API for shared_mutex type.