diff options
author | Philip Rauwolf <rauwolf@itestra.de> | 2013-06-24 14:19:41 +0200 |
---|---|---|
committer | Philip Rauwolf <rauwolf@itestra.de> | 2013-06-24 14:32:45 +0200 |
commit | e1cab8b38e9f2adff15221c69caac06bd3f945ba (patch) | |
tree | dd1efc5bbe145d54235dfe9623c431c307e770d3 | |
parent | d820ba6424b13990cabafc7215cefe875d574775 (diff) | |
download | genivi-common-api-dbus-runtime-2.1-pre1.tar.gz |
Added runtime check that mainloop context is initialized2.1-pre1
-rw-r--r-- | src/CommonAPI/DBus/DBusRuntime.cpp | 31 | ||||
-rw-r--r-- | src/CommonAPI/DBus/DBusRuntime.h | 21 | ||||
-rw-r--r-- | src/test/DBusMainLoopIntegrationTest.cpp | 12 | ||||
-rw-r--r-- | src/test/DBusServiceRegistryTest.cpp | 2 |
4 files changed, 36 insertions, 30 deletions
diff --git a/src/CommonAPI/DBus/DBusRuntime.cpp b/src/CommonAPI/DBus/DBusRuntime.cpp index 0d1ff62..a4b632b 100644 --- a/src/CommonAPI/DBus/DBusRuntime.cpp +++ b/src/CommonAPI/DBus/DBusRuntime.cpp @@ -24,37 +24,32 @@ std::shared_ptr<Runtime> DBusRuntime::getInstance() { return singleton_; } -std::shared_ptr<Factory> DBusRuntime::createFactory(std::shared_ptr<MainLoopContext> mainLoopContext) { - return createFactory(mainLoopContext, ""); +std::shared_ptr<Factory> DBusRuntime::doCreateFactory(std::shared_ptr<MainLoopContext> mainLoopContext) { + return doCreateFactory(mainLoopContext, ""); } -std::shared_ptr<Factory> DBusRuntime::createFactory(const std::string factoryName, - const bool nullOnInvalidName) { - return createFactory(std::shared_ptr<MainLoopContext>(NULL), factoryName, nullOnInvalidName); +std::shared_ptr<Factory> DBusRuntime::doCreateFactory(const std::string factoryName, + const bool nullOnInvalidName) { + return doCreateFactory(std::shared_ptr<MainLoopContext>(NULL), factoryName, nullOnInvalidName); } - - -std::shared_ptr<Factory> DBusRuntime::createFactory(std::shared_ptr<MainLoopContext> mainLoopContext, - const std::string factoryName, - const bool nullOnInvalidName) { +std::shared_ptr<Factory> DBusRuntime::doCreateFactory(std::shared_ptr<MainLoopContext> mainLoopContext, + const std::string factoryName, + const bool nullOnInvalidName) { auto factory = std::shared_ptr<DBusFactory>(NULL); - if (factoryName == "") + if (factoryName == "") { factory = std::make_shared<DBusFactory>(this->shared_from_this(), &middlewareInfo_, mainLoopContext); - else - { + } else { DBusAddressTranslator::FactoryConfigDBus* factoryConfigDBus = DBusAddressTranslator::getInstance().searchForFactoryConfiguration(factoryName); DBusAddressTranslator::FactoryConfigDBus defaultFactoryConfigDBus; - if (factoryConfigDBus == NULL) - { + if (factoryConfigDBus == NULL) { // unknown / unconfigured Factory requested - if (nullOnInvalidName) + if (nullOnInvalidName) { return (NULL); - else - { + } else { DBusFactory::getDefaultFactoryConfig(defaultFactoryConfigDBus); // get default settings factoryConfigDBus = &defaultFactoryConfigDBus; } diff --git a/src/CommonAPI/DBus/DBusRuntime.h b/src/CommonAPI/DBus/DBusRuntime.h index 133b624..6d65966 100644 --- a/src/CommonAPI/DBus/DBusRuntime.h +++ b/src/CommonAPI/DBus/DBusRuntime.h @@ -23,21 +23,18 @@ namespace DBus { class DBusRuntime: public Runtime, public std::enable_shared_from_this<DBusRuntime> { public: static std::shared_ptr<Runtime> getInstance(); - - - //std::shared_ptr<Factory> createFactory(std::shared_ptr<MainLoopContext> = std::shared_ptr<MainLoopContext>(NULL)); - std::shared_ptr<Factory> createFactory(std::shared_ptr<MainLoopContext> mainLoopContext = std::shared_ptr<MainLoopContext>(NULL)); - - std::shared_ptr<Factory> createFactory(const std::string factoryName, - const bool nullOnInvalidName = false); - std::shared_ptr<Factory> createFactory(std::shared_ptr<MainLoopContext> mainLoopContext, - const std::string factoryName, - const bool nullOnInvalidName = false); - - std::shared_ptr<ServicePublisher> getServicePublisher(); static const MiddlewareInfo middlewareInfo_; + + protected: + std::shared_ptr<Factory> doCreateFactory(std::shared_ptr<MainLoopContext> mainLoopContext); + std::shared_ptr<Factory> doCreateFactory(const std::string factoryName, + const bool nullOnInvalidName = false); + std::shared_ptr<Factory> doCreateFactory(std::shared_ptr<MainLoopContext> mainLoopContext, + const std::string factoryName, + const bool nullOnInvalidName = false); + private: static std::unordered_map<std::string, DBusRuntime> registeredRuntimes; }; diff --git a/src/test/DBusMainLoopIntegrationTest.cpp b/src/test/DBusMainLoopIntegrationTest.cpp index baa77ae..f945e64 100644 --- a/src/test/DBusMainLoopIntegrationTest.cpp +++ b/src/test/DBusMainLoopIntegrationTest.cpp @@ -69,6 +69,18 @@ TEST_F(DBusBasicMainLoopTest, MainloopContextCanBeCreated) { } +TEST_F(DBusBasicMainLoopTest, NoFactoryWillBeCreatedIfContextIsUninitialized) { + std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); + ASSERT_TRUE((bool) runtime); + + std::shared_ptr<CommonAPI::MainLoopContext> context = runtime->getNewMainLoopContext(); + ASSERT_TRUE((bool) context); + + std::shared_ptr<CommonAPI::Factory> factory = runtime->createFactory(context); + ASSERT_FALSE((bool) factory); +} + + TEST_F(DBusBasicMainLoopTest, SeveralMainloopContextsCanBeCreated) { std::shared_ptr<CommonAPI::Runtime> runtime = CommonAPI::Runtime::load(); ASSERT_TRUE((bool)runtime); diff --git a/src/test/DBusServiceRegistryTest.cpp b/src/test/DBusServiceRegistryTest.cpp index a1321d1..9a7676e 100644 --- a/src/test/DBusServiceRegistryTest.cpp +++ b/src/test/DBusServiceRegistryTest.cpp @@ -10,7 +10,9 @@ #include <CommonAPI/CommonAPI.h> +#ifndef COMMONAPI_INTERNAL_COMPILATION #define COMMONAPI_INTERNAL_COMPILATION +#endif #include <CommonAPI/DBus/DBusServiceRegistry.h> #include <CommonAPI/DBus/DBusConnection.h> |