diff options
Diffstat (limited to 'src/CommonAPI')
-rw-r--r-- | src/CommonAPI/MiddlewareInfo.h | 104 | ||||
-rw-r--r-- | src/CommonAPI/Runtime.cpp | 112 | ||||
-rw-r--r-- | src/CommonAPI/Runtime.h | 86 | ||||
-rw-r--r-- | src/CommonAPI/Stub.h | 88 |
4 files changed, 195 insertions, 195 deletions
diff --git a/src/CommonAPI/MiddlewareInfo.h b/src/CommonAPI/MiddlewareInfo.h index 988c58c..e58ea40 100644 --- a/src/CommonAPI/MiddlewareInfo.h +++ b/src/CommonAPI/MiddlewareInfo.h @@ -1,52 +1,52 @@ -/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * 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/. */
-#ifndef MIDDLEWAREINFO_H_
-#define MIDDLEWAREINFO_H_
-
-
-#include <memory>
-#include <cstring>
-
-
-namespace CommonAPI {
-
-
-class Runtime;
-
-
-inline int FNV1aHash(const char* s) {
- const int FNV_offset_basis = 2166136261;
- const int FNV_prime = 16777619;
-
- int hashValue = FNV_offset_basis;
- for (int i = 0; i < strlen(s); i++) {
- hashValue = (hashValue ^ s[i]) * FNV_prime;
- }
- return hashValue;
-}
-
-
-typedef std::shared_ptr<Runtime> (*MiddlewareRuntimeLoadFunction) ();
-
-
-struct MiddlewareInfo {
- const int middlewareId;
- const char* middlewareName_;
- MiddlewareRuntimeLoadFunction getInstance;
-
- MiddlewareInfo(const char* middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction):
- middlewareName_(middlewareName),
- middlewareId(FNV1aHash(middlewareName)),
- getInstance(middlewareRuntimeLoadFunction) {
-}
-};
-
-
-} // namespace CommonAPI
-
-
-#endif /* MIDDLEWAREINFO_H_ */
+/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#ifndef MIDDLEWAREINFO_H_ +#define MIDDLEWAREINFO_H_ + + +#include <memory> +#include <cstring> + + +namespace CommonAPI { + + +class Runtime; + + +inline int FNV1aHash(const char* s) { + const int FNV_offset_basis = 2166136261; + const int FNV_prime = 16777619; + + int hashValue = FNV_offset_basis; + for (int i = 0; i < strlen(s); i++) { + hashValue = (hashValue ^ s[i]) * FNV_prime; + } + return hashValue; +} + + +typedef std::shared_ptr<Runtime> (*MiddlewareRuntimeLoadFunction) (); + + +struct MiddlewareInfo { + const int middlewareId; + const char* middlewareName_; + MiddlewareRuntimeLoadFunction getInstance; + + MiddlewareInfo(const char* middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction): + middlewareName_(middlewareName), + middlewareId(FNV1aHash(middlewareName)), + getInstance(middlewareRuntimeLoadFunction) { +} +}; + + +} // namespace CommonAPI + + +#endif /* MIDDLEWAREINFO_H_ */ diff --git a/src/CommonAPI/Runtime.cpp b/src/CommonAPI/Runtime.cpp index 156bdd0..2ab8bf7 100644 --- a/src/CommonAPI/Runtime.cpp +++ b/src/CommonAPI/Runtime.cpp @@ -1,56 +1,56 @@ -/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * 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/. */
-#include "Runtime.h"
-
-#include <iostream>
-
-
-namespace CommonAPI {
-
-
-std::unordered_map<std::string, MiddlewareRuntimeLoadFunction>* registeredRuntimeLoadFunctions_;
-
-
-void Runtime::registerRuntimeLoader(std::string middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction) {
- if(!registeredRuntimeLoadFunctions_) {
- registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction>();
- }
- registeredRuntimeLoadFunctions_->insert({middlewareName, middlewareRuntimeLoadFunction});
-}
-
-
-std::shared_ptr<Runtime> Runtime::load() {
- if(!registeredRuntimeLoadFunctions_) {
- registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction> {};
- }
-
- auto begin = registeredRuntimeLoadFunctions_->begin();
-
- if (begin != registeredRuntimeLoadFunctions_->end()) {
- return (begin->second)();
- }
-
- return std::shared_ptr<Runtime>(NULL);
-}
-
-
-std::shared_ptr<Runtime> Runtime::load(const std::string& middlewareName) {
- if(!registeredRuntimeLoadFunctions_) {
- registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction> {};
- }
-
- for (auto it = registeredRuntimeLoadFunctions_->begin(); it != registeredRuntimeLoadFunctions_->end(); ++it) {
- if(it->first == middlewareName) {
- return (it->second)();
- }
- }
-
- return std::shared_ptr<Runtime>(NULL);
-}
-
-
-}
+/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#include "Runtime.h" + +#include <iostream> + + +namespace CommonAPI { + + +std::unordered_map<std::string, MiddlewareRuntimeLoadFunction>* registeredRuntimeLoadFunctions_; + + +void Runtime::registerRuntimeLoader(std::string middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction) { + if(!registeredRuntimeLoadFunctions_) { + registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction>(); + } + registeredRuntimeLoadFunctions_->insert({middlewareName, middlewareRuntimeLoadFunction}); +} + + +std::shared_ptr<Runtime> Runtime::load() { + if(!registeredRuntimeLoadFunctions_) { + registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction> {}; + } + + auto begin = registeredRuntimeLoadFunctions_->begin(); + + if (begin != registeredRuntimeLoadFunctions_->end()) { + return (begin->second)(); + } + + return std::shared_ptr<Runtime>(NULL); +} + + +std::shared_ptr<Runtime> Runtime::load(const std::string& middlewareName) { + if(!registeredRuntimeLoadFunctions_) { + registeredRuntimeLoadFunctions_ = new std::unordered_map<std::string, MiddlewareRuntimeLoadFunction> {}; + } + + for (auto it = registeredRuntimeLoadFunctions_->begin(); it != registeredRuntimeLoadFunctions_->end(); ++it) { + if(it->first == middlewareName) { + return (it->second)(); + } + } + + return std::shared_ptr<Runtime>(NULL); +} + + +} diff --git a/src/CommonAPI/Runtime.h b/src/CommonAPI/Runtime.h index f73dfcf..92cf736 100644 --- a/src/CommonAPI/Runtime.h +++ b/src/CommonAPI/Runtime.h @@ -1,43 +1,43 @@ -/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * 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/. */
-#ifndef COMMONAPI_RUNTIME_H_
-#define COMMONAPI_RUNTIME_H_
-
-
-#include "MiddlewareInfo.h"
-#include "Factory.h"
-
-#include <memory>
-#include <fstream>
-#include <unordered_map>
-#include <dlfcn.h>
-#include <string>
-#include <cassert>
-#include <cstring>
-
-
-namespace CommonAPI {
-
-
-class Factory;
-class Runtime;
-
-
-class Runtime {
- public:
- static std::shared_ptr<Runtime> load();
- static std::shared_ptr<Runtime> load(const std::string& middlewareId);
- static void registerRuntimeLoader(std::string middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction);
-
- virtual ~Runtime() {}
- virtual std::shared_ptr<Factory> createFactory() = 0;
-};
-
-
-} // namespace CommonAPI
-
-#endif // COMMONAPI_RUNTIME_H_
+/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#ifndef COMMONAPI_RUNTIME_H_ +#define COMMONAPI_RUNTIME_H_ + + +#include "MiddlewareInfo.h" +#include "Factory.h" + +#include <memory> +#include <fstream> +#include <unordered_map> +#include <dlfcn.h> +#include <string> +#include <cassert> +#include <cstring> + + +namespace CommonAPI { + + +class Factory; +class Runtime; + + +class Runtime { + public: + static std::shared_ptr<Runtime> load(); + static std::shared_ptr<Runtime> load(const std::string& middlewareId); + static void registerRuntimeLoader(std::string middlewareName, MiddlewareRuntimeLoadFunction middlewareRuntimeLoadFunction); + + virtual ~Runtime() {} + virtual std::shared_ptr<Factory> createFactory() = 0; +}; + + +} // namespace CommonAPI + +#endif // COMMONAPI_RUNTIME_H_ diff --git a/src/CommonAPI/Stub.h b/src/CommonAPI/Stub.h index 44cadf9..7353f54 100644 --- a/src/CommonAPI/Stub.h +++ b/src/CommonAPI/Stub.h @@ -1,44 +1,44 @@ -/* Copyright (C) 2013 BMW Group
- * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
- * Author: Juergen Gehring (juergen.gehring@bmw.de)
- * 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/. */
-#ifndef COMMONAPI_STUB_H_
-#define COMMONAPI_STUB_H_
-
-#include <memory>
-#include <string>
-#include <type_traits>
-
-namespace CommonAPI {
-
-class StubAdapter {
- public:
- virtual ~StubAdapter() { }
-
- virtual const std::string getAddress() const = 0;
- virtual const std::string& getDomain() const = 0;
- virtual const std::string& getServiceId() const = 0;
- virtual const std::string& getInstanceId() const = 0;
-};
-
-struct StubBase {
- virtual ~StubBase() {}
-};
-
-template <typename _StubAdapter, typename _StubRemoteEventHandler>
-class Stub : public StubBase {
- static_assert(std::is_base_of<StubAdapter, _StubAdapter>::value, "Invalid StubAdapter Class!");
- public:
- typedef _StubAdapter StubAdapterType;
- typedef _StubRemoteEventHandler RemoteEventHandlerType;
-
- virtual ~Stub() { }
-
- virtual _StubRemoteEventHandler* initStubAdapter(const std::shared_ptr<_StubAdapter>& stubAdapter) = 0;
-};
-
-} // namespace CommonAPI
-
-#endif // COMMONAPI_STUB_H_
+/* Copyright (C) 2013 BMW Group + * Author: Manfred Bathelt (manfred.bathelt@bmw.de) + * Author: Juergen Gehring (juergen.gehring@bmw.de) + * 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/. */ +#ifndef COMMONAPI_STUB_H_ +#define COMMONAPI_STUB_H_ + +#include <memory> +#include <string> +#include <type_traits> + +namespace CommonAPI { + +class StubAdapter { + public: + virtual ~StubAdapter() { } + + virtual const std::string getAddress() const = 0; + virtual const std::string& getDomain() const = 0; + virtual const std::string& getServiceId() const = 0; + virtual const std::string& getInstanceId() const = 0; +}; + +struct StubBase { + virtual ~StubBase() {} +}; + +template <typename _StubAdapter, typename _StubRemoteEventHandler> +class Stub : public StubBase { + static_assert(std::is_base_of<StubAdapter, _StubAdapter>::value, "Invalid StubAdapter Class!"); + public: + typedef _StubAdapter StubAdapterType; + typedef _StubRemoteEventHandler RemoteEventHandlerType; + + virtual ~Stub() { } + + virtual _StubRemoteEventHandler* initStubAdapter(const std::shared_ptr<_StubAdapter>& stubAdapter) = 0; +}; + +} // namespace CommonAPI + +#endif // COMMONAPI_STUB_H_ |