summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Rauwolf <rauwolf@itestra.de>2013-06-24 14:30:28 +0200
committerPhilip Rauwolf <rauwolf@itestra.de>2013-06-24 14:30:28 +0200
commite85fa0d2bd06ded7ee460e818994817aca80d2ef (patch)
tree3a663adfd3bdeb8128fd5eb03c14206f51c696cd
parent74b90aeece8cc8dd7f6e3fb275851e80b8754d7e (diff)
downloadgenivi-common-api-runtime-e85fa0d2bd06ded7ee460e818994817aca80d2ef.tar.gz
Added check on the mainloop context being initialized before used
-rw-r--r--src/CommonAPI/MainLoopContext.h10
-rw-r--r--src/CommonAPI/Runtime.cpp9
-rw-r--r--src/CommonAPI/Runtime.h21
3 files changed, 37 insertions, 3 deletions
diff --git a/src/CommonAPI/MainLoopContext.h b/src/CommonAPI/MainLoopContext.h
index 0d87442..c651532 100644
--- a/src/CommonAPI/MainLoopContext.h
+++ b/src/CommonAPI/MainLoopContext.h
@@ -314,6 +314,16 @@ class MainLoopContext {
}
}
+ /**
+ * \brief Will return true if at least one subscribe for DispatchSources or Watches has been called.
+ *
+ * This function will be used to prevent creation of a factory if a mainloop context is given, but
+ * no listeners have been registered. This is done in order to ensure correct use of the mainloop context.
+ */
+ inline bool isInitialized() {
+ return dispatchSourceListeners_.size() > 0 || watchListeners_.size() > 0;
+ }
+
private:
DispatchSourceListenerList dispatchSourceListeners_;
WatchListenerList watchListeners_;
diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp
index d7185df..f930db9 100644
--- a/src/CommonAPI/Runtime.cpp
+++ b/src/CommonAPI/Runtime.cpp
@@ -57,5 +57,14 @@ std::shared_ptr<MainLoopContext> Runtime::getNewMainLoopContext() const {
return std::make_shared<MainLoopContext>();
}
+std::shared_ptr<Factory> Runtime::createFactory(std::shared_ptr<MainLoopContext> mainLoopContext,
+ const std::string factoryName,
+ const bool nullOnInvalidName) {
+ if(mainLoopContext && !mainLoopContext->isInitialized()) {
+ return std::shared_ptr<Factory>(NULL);
+ }
+ return doCreateFactory(mainLoopContext, factoryName, nullOnInvalidName);
+}
+
} // namespace CommonAPI
diff --git a/src/CommonAPI/Runtime.h b/src/CommonAPI/Runtime.h
index 5cf7afa..6a8eeec 100644
--- a/src/CommonAPI/Runtime.h
+++ b/src/CommonAPI/Runtime.h
@@ -85,14 +85,24 @@ class Runtime {
*
* Create a factory for the loaded runtime
*
- * @param In case mainloop integration shall be used, a std::shared_ptr<MainLoopContext> can be passed in.
+ * @param mainLoopContext: In case mainloop integration shall be used, a std::shared_ptr<MainLoopContext> can be passed in.
* If no parameter is given, internal threading will handle sending and receiving of messages automatically.
+ * If the mainloop context is not initialized, no factory will be returned. See documentation of
+ * MainLoopContext::isInitialized().
+ *
+ * @param factoryName: If additional configuration parameters for the specific middleware factory shall be provided,
+ * the appropriate set of parameters may be identified by this name. See accompanying documentation for
+ * usage of configuration files.
+ *
+ * @param nullOnInvalidName: If a factoryName is provided, this parameter determines whether the standard configuration
+ * for factories shall be used if the specific parameter set cannot be found, or if instead no factory
+ * shall be returned in this case.
*
* @return Factory object for this runtime
*/
- virtual std::shared_ptr<Factory> createFactory(std::shared_ptr<MainLoopContext> = std::shared_ptr<MainLoopContext>(NULL),
+ virtual std::shared_ptr<Factory> createFactory(std::shared_ptr<MainLoopContext> mainLoopContext = std::shared_ptr<MainLoopContext>(NULL),
const std::string factoryName = "",
- const bool nullOnInvalidName = false) = 0;
+ const bool nullOnInvalidName = false);
/**
* \brief Returns the ServicePublisher object for this runtime.
@@ -105,6 +115,11 @@ class Runtime {
* @return The ServicePublisher object for this runtime
*/
virtual std::shared_ptr<ServicePublisher> getServicePublisher() = 0;
+
+ protected:
+ virtual std::shared_ptr<Factory> doCreateFactory(std::shared_ptr<MainLoopContext>,
+ const std::string factoryName,
+ const bool nullOnInvalidName) = 0;
};