diff options
-rwxr-xr-x | AudioManagerDaemon/src/main.cpp | 2 | ||||
-rw-r--r-- | AudioManagerUtilities/include/CAmCommonAPIWrapper.h | 41 | ||||
-rw-r--r-- | AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp | 18 |
3 files changed, 52 insertions, 9 deletions
diff --git a/AudioManagerDaemon/src/main.cpp b/AudioManagerDaemon/src/main.cpp index fac3e1e..6db7715 100755 --- a/AudioManagerDaemon/src/main.cpp +++ b/AudioManagerDaemon/src/main.cpp @@ -335,7 +335,7 @@ void mainProgram(int argc, char *argv[]) #ifdef WITH_CAPI_WRAPPER //We instantiate a singleton with the current socket handler, which loads the common-api runtime. - CAmCommonAPIWrapper *pCAPIWrapper = CAmCommonAPIWrapper::instantiateOnce(&iSocketHandler); + CAmCommonAPIWrapper *pCAPIWrapper = CAmCommonAPIWrapper::instantiateOnce(&iSocketHandler, "AudioManager"); CAmCommonAPIWrapper iDBusWrapper = *pCAPIWrapper; #ifdef WITH_NSM CAmNodeStateCommunicatorCAPI iNodeStateCommunicator(&iDBusWrapper); diff --git a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h index 7fc5692..ce02a44 100644 --- a/AudioManagerUtilities/include/CAmCommonAPIWrapper.h +++ b/AudioManagerUtilities/include/CAmCommonAPIWrapper.h @@ -94,7 +94,7 @@ class CAmCommonAPIWrapper void wakeup(); protected: - CAmCommonAPIWrapper(CAmSocketHandler* socketHandler) ; + CAmCommonAPIWrapper(CAmSocketHandler* socketHandler, const std::string & applicationName = "") ; public: @@ -120,7 +120,7 @@ public: * * @return The common-api wrapper object. */ - static CAmCommonAPIWrapper* instantiateOnce(CAmSocketHandler* socketHandler); + static CAmCommonAPIWrapper* instantiateOnce(CAmSocketHandler* socketHandler, const std::string & applicationName = ""); /** @@ -129,7 +129,24 @@ public: * @return Pointer to the socket handler. */ CAmSocketHandler *getSocketHandler() const { return mpSocketHandler; } - +#if COMMONAPI_VERSION_NUMBER >= 300 + /** + * \brief Register stub objects. + * + * Example: std::shared_ptr<ConcreteStubClass> aStub; + * registerService( aStub, "local", "com.your_company.instance_name", "service-name"); + * + * @param shStub: Shared pointer to a stub instance + * @param domain: A string with the domain name, usually "local" + * @param instance: Common-api instance string as example "com.your_company.instance_name" + * @param connectionId: A string connection id, which is used by CommonAPI to group applications + * + */ + template <class TStubImp> bool registerService(const std::shared_ptr<TStubImp> & shStub, const std::string & domain, const std::string & instance, const CommonAPI::ConnectionId_t & connectionId) + { + return mRuntime->registerService(domain, instance, shStub, connectionId); + } +#endif /** * \brief Register stub objects. * @@ -195,6 +212,24 @@ public: return unregisterService(parts[0], parts[1], parts[2]); } +#if COMMONAPI_VERSION_NUMBER >= 300 + /** + * \brief Build proxy objects. + * + * Example: std::shared_ptr<AProxyClass<>> aProxy = buildProxy<AProxyClass>("local", "com.your_company.instance_name", "client-name"); + * + * @param domain: A string with the domain name, usually "local" + * @param instance: Common-api instance string as example "com.your_company.instance_name" + * @param connectionId: A string connection id, which is used by CommonAPI to group applications + * + * @return A proxy object. + */ + template<template<typename ...> class ProxyClass, typename ... AttributeExtensions> + std::shared_ptr<ProxyClass<AttributeExtensions...>> buildProxy(const std::string &domain, const std::string &instance, const CommonAPI::ConnectionId_t & connectionId) + { + return mRuntime->buildProxy<ProxyClass>(domain, instance, connectionId); + } +#endif /** * \brief Build proxy objects. diff --git a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp index 8412a71..b6ac399 100644 --- a/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp +++ b/AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp @@ -48,7 +48,7 @@ namespace am static CAmCommonAPIWrapper* pSingleCommonAPIInstance = NULL; -CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): +CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler, const std::string & applicationName): pCommonPrepareCallback(this,&CAmCommonAPIWrapper::commonPrepareCallback), // pCommonDispatchCallback(this, &CAmCommonAPIWrapper::commonDispatchCallback), // pCommonFireCallback(this, &CAmCommonAPIWrapper::commonFireCallback), // @@ -64,18 +64,26 @@ CAmCommonAPIWrapper::CAmCommonAPIWrapper(CAmSocketHandler* socketHandler): #else CommonAPI::Runtime::setProperty("LogContext", "AMCAPI"); mRuntime = CommonAPI::Runtime::get(); + logInfo("CommonAPI runtime has been loaded! Default Binding is", mRuntime->getDefaultBinding()); #endif assert(NULL!=mRuntime); //Create the context +#if COMMONAPI_VERSION_NUMBER < 300 mContext = std::make_shared<CommonAPI::MainLoopContext>(); +#else + if(applicationName.size()) + mContext = std::make_shared<CommonAPI::MainLoopContext>(applicationName); + else + mContext = std::make_shared<CommonAPI::MainLoopContext>(); +#endif assert(NULL!=mContext); + logInfo("CommonAPI main loop context with name '", mContext->getName(), "' has been created!"); #if COMMONAPI_VERSION_NUMBER < 300 - mFactory = runtime->createFactory(mContext); + mFactory = mRuntime->createFactory(mContext); assert(mFactory); #else - logInfo("CommonAPI runtime has been loaded! Default Binding is", mRuntime->getDefaultBinding()); #if COMMONAPI_USED_BINDING > 0 mFactory = CommonAPI::SomeIP::Factory::get(); assert(mFactory); @@ -111,14 +119,14 @@ CAmCommonAPIWrapper::~CAmCommonAPIWrapper() mWatchToCheck = NULL; } -CAmCommonAPIWrapper* CAmCommonAPIWrapper::instantiateOnce(CAmSocketHandler* socketHandler) +CAmCommonAPIWrapper* CAmCommonAPIWrapper::instantiateOnce(CAmSocketHandler* socketHandler, const std::string & applicationName) { if(NULL==pSingleCommonAPIInstance) { if(NULL==socketHandler) throw std::runtime_error(std::string("Expected a valid socket handler. The socket handler pointer must not be NULL.")); else - pSingleCommonAPIInstance = new CAmCommonAPIWrapper(socketHandler); + pSingleCommonAPIInstance = new CAmCommonAPIWrapper(socketHandler, applicationName); } else throw std::logic_error(std::string("The singleton instance has been already instantiated. This method should be called only once.")); |