From c529ce5944d3c56c27beb78f0193698b7c1bf1ae Mon Sep 17 00:00:00 2001 From: Aleksandar Donchev Date: Fri, 11 Sep 2015 13:50:51 +0200 Subject: * CAPI wrapper with better someip integration. Signed-off-by: Christian Linke --- .../include/CAmCommonAPIWrapper.h | 41 ++++++++++++++++++++-- AudioManagerUtilities/src/CAmCommonAPIWrapper.cpp | 18 +++++++--- 2 files changed, 51 insertions(+), 8 deletions(-) (limited to 'AudioManagerUtilities') 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 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 bool registerService(const std::shared_ptr & 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> aProxy = buildProxy("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 class ProxyClass, typename ... AttributeExtensions> + std::shared_ptr> buildProxy(const std::string &domain, const std::string &instance, const CommonAPI::ConnectionId_t & connectionId) + { + return mRuntime->buildProxy(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(); +#else + if(applicationName.size()) + mContext = std::make_shared(applicationName); + else + mContext = std::make_shared(); +#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.")); -- cgit v1.2.1