AudioManager  7.6.6
Native Application Runtime Environment
CAmCommonAPIWrapper.h
Go to the documentation of this file.
1 
19 #ifndef COMMONAPIWRAPPER_H_
20 #define COMMONAPIWRAPPER_H_
21 
22 #include <string>
23 #include <list>
24 #include <map>
25 #include <queue>
26 #include <memory>
27 #include <cassert>
28 #include <CommonAPI/CommonAPI.hpp>
29 #ifndef COMMONAPI_INTERNAL_COMPILATION
30 #define COMMONAPI_INTERNAL_COMPILATION
31 #include <CommonAPI/MainLoopContext.hpp>
32 #undef COMMONAPI_INTERNAL_COMPILATION
33 #endif
34 #include <CommonAPI/Utils.hpp>
35 #include "audiomanagerconfig.h"
36 #include "CAmSocketHandler.h"
37 
44 namespace am
45 {
46 
47 class CAmSocketHandler;
48 
50 {
51  void commonPrepareCallback(const sh_pollHandle_t handle, void* userData);
52  TAmShPollPrepare<CAmCommonAPIWrapper> pCommonPrepareCallback;
53 
54  bool commonDispatchCallback(const sh_pollHandle_t handle, void* userData);
55  TAmShPollDispatch<CAmCommonAPIWrapper> pCommonDispatchCallback;
56 
57  void commonFireCallback(const pollfd pollfd, const sh_pollHandle_t, void*);
58  TAmShPollFired<CAmCommonAPIWrapper> pCommonFireCallback;
59 
60  bool commonCheckCallback(const sh_pollHandle_t handle, void*);
61  TAmShPollCheck<CAmCommonAPIWrapper> pCommonCheckCallback;
62 
63  void commonTimerCallback(sh_timerHandle_t handle, void* userData);
64  TAmShTimerCallBack<CAmCommonAPIWrapper> pCommonTimerCallback;
65 
66  struct timerHandles
67  {
68  sh_timerHandle_t handle;
69  CommonAPI::Timeout* timeout;
70  };
71 
72  CAmSocketHandler *mpSocketHandler;
73 
74  std::shared_ptr<CommonAPI::Runtime> mRuntime;
75  std::shared_ptr<CommonAPI::MainLoopContext> mContext;
76 
77  CommonAPI::DispatchSourceListenerSubscription mDispatchSourceListenerSubscription;
78  CommonAPI::WatchListenerSubscription mWatchListenerSubscription;
79  CommonAPI::TimeoutSourceListenerSubscription mTimeoutSourceListenerSubscription;
80  CommonAPI::WakeupListenerSubscription mWakeupListenerSubscription;
81  std::multimap<CommonAPI::DispatchPriority, CommonAPI::DispatchSource*> mRegisteredDispatchSources;
82  std::map<int,CommonAPI::Watch*> mMapWatches;
83  CommonAPI::Watch* mWatchToCheck;
84  std::list<CommonAPI::DispatchSource*> mSourcesToDispatch;
85  std::vector<timerHandles> mpListTimerhandles;
86 
87  void registerDispatchSource(CommonAPI::DispatchSource* dispatchSource, const CommonAPI::DispatchPriority dispatchPriority);
88  void deregisterDispatchSource(CommonAPI::DispatchSource* dispatchSource);
89  void registerWatch(CommonAPI::Watch* watch, const CommonAPI::DispatchPriority dispatchPriority);
90  void deregisterWatch(CommonAPI::Watch* watch);
91  void registerTimeout(CommonAPI::Timeout* timeout, const CommonAPI::DispatchPriority dispatchPriority);
92  void deregisterTimeout(CommonAPI::Timeout* timeout);
93  void wakeup();
94 
95 protected:
96  CAmCommonAPIWrapper(CAmSocketHandler* socketHandler, const std::string & applicationName = "") ;
97 
98 public:
99 
100  virtual ~CAmCommonAPIWrapper();
101 
110 
114  static void deleteInstance();
115 
127  static CAmCommonAPIWrapper* instantiateOnce(CAmSocketHandler* socketHandler, const std::string & applicationName = "");
128 
129 
135  CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; }
136 #if COMMONAPI_VERSION_NUMBER >= 300
137 
149  template <class TStubImp> bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance, const CommonAPI::ConnectionId_t & connectionId)
150  {
151  return mRuntime->registerService(domain, instance, shStub, connectionId);
152  }
153 #endif
154 
165  template <class TStubImp> bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance)
166  {
167  return mRuntime->registerService(domain, instance, shStub, mContext);
168  }
169 
178  bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance)
179  {
180  return mRuntime->unregisterService(domain, interface, instance);
181  }
182 
195  template <class TStubImp> bool __attribute__((deprecated)) registerStub(const std::shared_ptr<TStubImp> & shStub, const std::string & address)
196  {
197  std::vector<std::string> parts = CommonAPI::split(address, ':');
198  assert(parts.size()==3);
199 
200  return registerService(shStub, parts[0], parts[2]);
201  }
202 
211  bool __attribute__((deprecated)) unregisterStub(const std::string & address)
212  {
213  std::vector<std::string> parts = CommonAPI::split(address, ':');
214  assert(parts.size()==3);
215 
216  return unregisterService(parts[0], parts[1], parts[2]);
217  }
218 
219 #if COMMONAPI_VERSION_NUMBER >= 300
220 
231  template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
232  std::shared_ptr<ProxyClass<AttributeExtensions...>> buildProxy(const std::string &domain, const std::string &instance, const CommonAPI::ConnectionId_t & connectionId)
233  {
234  return mRuntime->buildProxy<ProxyClass>(domain, instance, connectionId);
235  }
236 #endif
237 
248  template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
249  std::shared_ptr<ProxyClass<AttributeExtensions...>> buildProxy(const std::string &domain, const std::string &instance)
250  {
251  return mRuntime->buildProxy<ProxyClass>(domain, instance, mContext);
252  }
253 
254 
265  template<template<typename ...> class ProxyClass, typename ... AttributeExtensions>
266  std::shared_ptr<ProxyClass<AttributeExtensions...>> __attribute__((deprecated)) buildProxy(const std::string & address)
267  {
268  std::vector<std::string> parts=CommonAPI::split(address, ':');
269  assert(parts.size()==3);
270 
271  return buildProxy<ProxyClass>(parts[0], parts[2]);
272  }
273 
274 };
275 
276 
277 //Alias
278 extern CAmCommonAPIWrapper* (*getCAPI)();
279 
280 #ifndef AMCAPI
281  #define AMCAPI getCAPI()
282 #endif
283 
284 #ifndef AM_CAPI
285  #define AM_CAPI getCAPI()
286 #endif
287 
288 #ifndef CAPI
289  #define CAPI getCAPI()
290 #endif
291 
292 
293 }
294 
295 #endif /* COMMONAPIWRAPPER_H_ */
CAmCommonAPIWrapper(CAmSocketHandler *socketHandler, const std::string &applicationName="")
A Common-API wrapper class, which loads the common-api runtime and instantiates all necessary objects...
template for a callback
bool __attribute__((deprecated)) registerStub(const std
Deprecated method.
bool unregisterService(const std::string &domain, const std::string &interface, const std::string &instance)
Unregister stub objects.
make private, not public template for a callback
static CAmCommonAPIWrapper * instantiateOnce(CAmSocketHandler *socketHandler, const std::string &applicationName="")
Creates a singleton instance attached to the provided socket handler object.
The am::CAmSocketHandler implements a mainloop for the AudioManager.
STL namespace.
uint16_t sh_pollHandle_t
this is a handle for a filedescriptor to be used with the SocketHandler
std::shared_ptr< ProxyClass< AttributeExtensions... > > buildProxy(const std::string &domain, const std::string &instance)
Build proxy objects.
static void deleteInstance()
Deletes the instanciated object.
template for a callback
template for a callback
static CAmCommonAPIWrapper * getInstance()
Returns an already instantiated object.
std::shared_ptr< ProxyClass< AttributeExtensions... > > __attribute__((deprecated)) buildProxy(const std
Deprecated method.
CAmSocketHandler * getSocketHandler() const
Getter for the socket handler.
SPDX license identifier: MPL-2.0.
bool __attribute__((deprecated)) unregisterStub(const std
Deprecated method.
bool registerService(const std::shared_ptr< TStubImp > &shStub, const std::string &domain, const std::string &instance)
Register stub objects.
sh_pollHandle_t sh_timerHandle_t
this is a handle for a timer to be used with the SocketHandler
template to create the functor for a class