diff --git a/include/CommonAPI/Runtime.hpp b/include/CommonAPI/Runtime.hpp index 61bd5fe..6cb61fd 100644 --- a/include/CommonAPI/Runtime.hpp +++ b/include/CommonAPI/Runtime.hpp @@ -76,6 +76,48 @@ class Runtime { return nullptr; } + template class ProxyClass_, typename ... AttributeExtensions_> + COMMONAPI_EXPORT std::shared_ptr< + ProxyClass_ + > + buildDynamicProxy(const std::string &_domain, + const std::string &_template_instance, + const std::string &_instance, + const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) { + std::shared_ptr proxy + = createDynamicProxy(_domain, + ProxyClass_::getInterface(), + _template_instance, + _instance, + _connectionId); + + if (proxy) { + return std::make_shared>(proxy); + } + return nullptr; + } + + template class ProxyClass_, typename ... AttributeExtensions_> + COMMONAPI_EXPORT std::shared_ptr< + ProxyClass_ + > + buildDynamicProxy(const std::string &_domain, + const std::string &_template_instance, + const std::string &_instance, + std::shared_ptr _context) { + std::shared_ptr proxy + = createDynamicProxy(_domain, + ProxyClass_::getInterface(), + _template_instance, + _instance, + _context); + if (proxy) { + return std::make_shared>(proxy); + } + return nullptr; + } + + template class ProxyClass_, template class AttributeExtension_> COMMONAPI_EXPORT std::shared_ptr::class_t> buildProxyWithDefaultAttributeExtension(const std::string &_domain, @@ -124,6 +166,25 @@ class Runtime { return registerStub(_domain, Stub_::StubInterface::getInterface(), _instance, _service, _context); } + template + COMMONAPI_EXPORT bool registerDynamicService(const std::string &_domain, + const std::string &_template_instance, + const std::string &_instance, + std::shared_ptr _service, + const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) { + return registerDynamicStub(_domain, Stub_::StubInterface::getInterface(), _template_instance, _instance, _service, _connectionId); + } + + template + COMMONAPI_EXPORT bool registerDynamicService(const std::string &_domain, + const std::string &_template_instance, + const std::string &_instance, + std::shared_ptr _service, + std::shared_ptr _context) { + return registerDynamicStub(_domain, Stub_::StubInterface::getInterface(), _template_instance, _instance, _service, _context); + } + + COMMONAPI_EXPORT bool unregisterService(const std::string &_domain, const std::string &_interface, const std::string &_instance) { @@ -147,7 +208,10 @@ class Runtime { const ConnectionId_t &); COMMONAPI_EXPORT std::shared_ptr createProxy(const std::string &, const std::string &, const std::string &, std::shared_ptr); - + COMMONAPI_EXPORT std::shared_ptr createDynamicProxy(const std::string &, const std::string &, const std::string &, const std::string &, + const ConnectionId_t &); + COMMONAPI_EXPORT std::shared_ptr createDynamicProxy(const std::string &, const std::string &, const std::string &, const std::string &, + std::shared_ptr); COMMONAPI_EXPORT std::shared_ptr createProxyHelper(const std::string &, const std::string &, const std::string &, const ConnectionId_t &, bool); COMMONAPI_EXPORT std::shared_ptr createProxyHelper(const std::string &, const std::string &, const std::string &, @@ -158,6 +222,10 @@ class Runtime { std::shared_ptr, const ConnectionId_t &); COMMONAPI_EXPORT bool registerStub(const std::string &, const std::string &, const std::string &, std::shared_ptr, std::shared_ptr); + COMMONAPI_EXPORT bool registerDynamicStub(const std::string &, const std::string &, const std::string &, const std::string &, + std::shared_ptr, const ConnectionId_t &); + COMMONAPI_EXPORT bool registerDynamicStub(const std::string &, const std::string &, const std::string &, const std::string &, + std::shared_ptr, std::shared_ptr); COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &, std::shared_ptr, const ConnectionId_t &, bool); COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &, diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp index 1f531a0..5778003 100644 --- a/src/CommonAPI/Runtime.cpp +++ b/src/CommonAPI/Runtime.cpp @@ -256,6 +256,20 @@ std::shared_ptr Runtime::createProxy( const std::string &_domain, const std::string &_interface, const std::string &_instance, const ConnectionId_t &_connectionId) { + return createDynamicProxy(_domain, _interface, _instance, _instance, _connectionId); +} + +std::shared_ptr +Runtime::createProxy( + const std::string &_domain, const std::string &_interface, const std::string &_instance, + std::shared_ptr _context) { + return createDynamicProxy(_domain, _interface, _instance, _instance, _context); +} + +std::shared_ptr +Runtime::createDynamicProxy( + const std::string &_domain, const std::string &_interface, const std::string &_template_instance, const std::string &_instance, + const ConnectionId_t &_connectionId) { if (!isInitialized_) { initFactories(); } @@ -265,7 +279,7 @@ Runtime::createProxy( if (!proxy) { // ...it seems do not, lets try to load a library that does... std::lock_guard itsGuard(loadMutex_); - std::string library = getLibrary(_domain, _interface, _instance, true); + std::string library = getLibrary(_domain, _interface, _template_instance, true); if (loadLibrary(library) || defaultFactory_) { proxy = createProxyHelper(_domain, _interface, _instance, _connectionId, true); } @@ -274,9 +288,9 @@ Runtime::createProxy( } std::shared_ptr -Runtime::createProxy( - const std::string &_domain, const std::string &_interface, const std::string &_instance, - std::shared_ptr _context) { +Runtime::createDynamicProxy( + const std::string &_domain, const std::string &_interface, const std::string &_template_instance, const std::string &_instance, + std::shared_ptr _context) { if (!isInitialized_) { initFactories(); } @@ -286,7 +300,7 @@ Runtime::createProxy( if (!proxy) { // ...it seems do not, lets try to load a library that does... std::lock_guard itsGuard(loadMutex_); - std::string library = getLibrary(_domain, _interface, _instance, true); + std::string library = getLibrary(_domain, _interface, _template_instance, true); if (loadLibrary(library) || defaultFactory_) { proxy = createProxyHelper(_domain, _interface, _instance, _context, true); } @@ -298,6 +312,19 @@ Runtime::createProxy( bool Runtime::registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr _stub, const ConnectionId_t &_connectionId) { + return registerDynamicStub(_domain, _interface, _instance, _instance, _stub, _connectionId); +} + +bool +Runtime::registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, + std::shared_ptr _stub, std::shared_ptr _context) { + return registerDynamicStub(_domain, _interface, _instance, _instance, _stub, _context); +} + + +bool +Runtime::registerDynamicStub(const std::string &_domain, const std::string &_interface, const std::string &_template_instance, const std::string &_instance, + std::shared_ptr _stub, const ConnectionId_t &_connectionId) { if (!_stub) { return false; } @@ -308,7 +335,7 @@ Runtime::registerStub(const std::string &_domain, const std::string &_interface, bool isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _connectionId, false); if (!isRegistered) { - std::string library = getLibrary(_domain, _interface, _instance, false); + std::string library = getLibrary(_domain, _interface, _template_instance, false); std::lock_guard itsGuard(loadMutex_); if (loadLibrary(library) || defaultFactory_) { isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _connectionId, true); @@ -318,8 +345,8 @@ Runtime::registerStub(const std::string &_domain, const std::string &_interface, } bool -Runtime::registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, - std::shared_ptr _stub, std::shared_ptr _context) { +Runtime::registerDynamicStub(const std::string &_domain, const std::string &_interface, const std::string &_template_instance, const std::string &_instance, + std::shared_ptr _stub, std::shared_ptr _context) { if (!_stub) { return false; } @@ -330,7 +357,7 @@ Runtime::registerStub(const std::string &_domain, const std::string &_interface, bool isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _context, false); if (!isRegistered) { - std::string library = getLibrary(_domain, _interface, _instance, false); + std::string library = getLibrary(_domain, _interface, _template_instance, false); std::lock_guard itsGuard(loadMutex_); if (loadLibrary(library) || defaultFactory_) { isRegistered = registerStubHelper(_domain, _interface, _instance, _stub, _context, true);