// Copyright (C) 2013-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. #if !defined (COMMONAPI_INTERNAL_COMPILATION) #error "Only can be included directly, this file may disappear or change contents." #endif #ifndef COMMONAPI_DBUS_FACTORY_HPP_ #define COMMONAPI_DBUS_FACTORY_HPP_ #include #include #include #include namespace CommonAPI { namespace DBus { class DBusAddress; class DBusProxy; class DBusProxyConnection; class DBusStubAdapter; typedef std::shared_ptr (*ProxyCreateFunction)(const DBusAddress &_address, const std::shared_ptr &_connection); typedef std::shared_ptr (*StubAdapterCreateFunction) (const DBusAddress &_address, const std::shared_ptr &_connection, const std::shared_ptr &_stub); class Factory : public CommonAPI::Factory { public: COMMONAPI_EXPORT static std::shared_ptr get(); COMMONAPI_EXPORT Factory(); COMMONAPI_EXPORT virtual ~Factory(); COMMONAPI_EXPORT void registerProxyCreateMethod(const std::string &_address, ProxyCreateFunction _function); COMMONAPI_EXPORT void registerStubAdapterCreateMethod(const std::string &_address, StubAdapterCreateFunction _function); COMMONAPI_EXPORT std::shared_ptr createProxy(const std::string &_domain, const std::string &_interface, const std::string &_instance, const ConnectionId_t &_connectionId); COMMONAPI_EXPORT std::shared_ptr createProxy(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr _context); COMMONAPI_EXPORT bool registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr _stub, const ConnectionId_t &_connectionId); COMMONAPI_EXPORT bool registerStub(const std::string &_domain, const std::string &_interface, const std::string &_instance, std::shared_ptr _stub, std::shared_ptr _context); COMMONAPI_EXPORT bool unregisterStub(const std::string &_domain, const std::string &_interface, const std::string &_instance); // Services COMMONAPI_EXPORT std::shared_ptr getRegisteredService(const std::string &_address); // Managed services COMMONAPI_EXPORT std::shared_ptr createDBusStubAdapter(const std::shared_ptr &_stub, const std::string &_interface, const DBusAddress &_address, const std::shared_ptr &_connection); COMMONAPI_EXPORT bool registerManagedService(const std::shared_ptr &_adapter); COMMONAPI_EXPORT bool unregisterManagedService(const std::string &_address); private: COMMONAPI_EXPORT std::shared_ptr getConnection(const ConnectionId_t &); COMMONAPI_EXPORT std::shared_ptr getConnection(std::shared_ptr); COMMONAPI_EXPORT bool registerStubAdapter(std::shared_ptr); COMMONAPI_EXPORT bool unregisterStubAdapter(std::shared_ptr); // Managed services typedef std::unordered_map> ServicesMap; COMMONAPI_EXPORT bool unregisterManagedService(const ServicesMap::iterator &); private: static std::shared_ptr theFactory; std::map> connections_; std::map> contextConnections_; std::map proxyCreateFunctions_; std::map stubAdapterCreateFunctions_; ServicesMap services_; DBusType_t dBusBusType_; }; } // namespace DBus } // namespace CommonAPI #endif // COMMONAPI_DBUS_FACTORY_HPP_