src/CommonAPI/Runtime.cpp \
src/CommonAPI/Configuration.cpp \
src/CommonAPI/ServicePublisher.cpp \
- src/CommonAPI/ContainerUtils.cpp
+ src/CommonAPI/ContainerUtils.cpp \
+ src/CommonAPI/MainLoopContext.cpp \
+ src/CommonAPI/InputStream.cpp \
+ src/CommonAPI/Factory.cpp \
+ src/CommonAPI/utils.cpp
CommonAPI_includedir=$(includedir)/CommonAPI-${COMMONAPI_API_HEADER_VERSION}/CommonAPI
CommonAPI_include_HEADERS = \
template<typename _AttributeType>
class AttributeExtension {
public:
- inline _AttributeType& getBaseAttribute() {
+ _AttributeType& getBaseAttribute() {
return baseAttribute_;
}
* @param listener A listener to be added
* @return A token identifying this subscription
*/
- virtual inline Subscription subscribe(Listener listener);
+ virtual Subscription subscribe(Listener listener);
/**
* \brief Subscribe a cancellable listener to this event
--- /dev/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 "Factory.h"
+
+namespace CommonAPI {
+
+std::shared_ptr<Runtime> Factory::getRuntime() {
+ return runtime_;
+}
+
+} // namespace CommonAPI
*
* @return the Runtime
*/
- inline std::shared_ptr<Runtime> getRuntime();
+ std::shared_ptr<Runtime> getRuntime();
/**
* \brief Register a service stub under a specified address
return buildProxyWithDefaultAttributeExtension<_ProxyClass, _AttributeExtension>(participantId, serviceName, domain);
}
-inline std::shared_ptr<Runtime> Factory::getRuntime() {
- return runtime_;
-}
-
template<typename _Stub>
COMMONAPI_DEPRECATED bool Factory::registerService(std::shared_ptr<_Stub> stub,
const std::string& participantId,
--- /dev/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 "InputStream.h"
+
+namespace CommonAPI {
+
+InputStream& operator>>(InputStream& inputStream, bool& boolValue) {
+ return inputStream.readValue(boolValue);
+}
+
+InputStream& operator>>(InputStream& inputStream, int8_t& int8Value) {
+ return inputStream.readValue(int8Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, int16_t& int16Value) {
+ return inputStream.readValue(int16Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, int32_t& int32Value) {
+ return inputStream.readValue(int32Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, int64_t& int64Value) {
+ return inputStream.readValue(int64Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, uint8_t& uint8Value) {
+ return inputStream.readValue(uint8Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, uint16_t& uint16Value) {
+ return inputStream.readValue(uint16Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, uint32_t& uint32Value) {
+ return inputStream.readValue(uint32Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, uint64_t& uint64Value) {
+ return inputStream.readValue(uint64Value);
+}
+
+InputStream& operator>>(InputStream& inputStream, float& floatValue) {
+ return inputStream.readValue(floatValue);
+}
+
+InputStream& operator>>(InputStream& inputStream, double& doubleValue) {
+ return inputStream.readValue(doubleValue);
+}
+
+InputStream& operator>>(InputStream& inputStream, std::string& stringValue) {
+ return inputStream.readValue(stringValue);
+}
+
+InputStream& operator>>(InputStream& inputStream, Version& versionValue) {
+ return inputStream.readVersionValue(versionValue);
+}
+
+InputStream& operator>>(InputStream& inputStream, SerializableStruct& serializableStruct) {
+ inputStream.beginReadSerializableStruct(serializableStruct);
+ serializableStruct.readFromInputStream(inputStream);
+ inputStream.endReadSerializableStruct(serializableStruct);
+
+ return inputStream;
+}
+
+InputStream& operator>>(InputStream& inputStream, SerializableVariant& serializableVariant) {
+ inputStream.readSerializableVariant(serializableVariant);
+ return inputStream;
+}
+
+}
virtual InputStream& readEnumValue(uint64_t& uint64BackingTypeValue) = 0;
template<typename _EnumBackingType, typename _EnumType>
- inline InputStream& readEnumValue(_EnumType& enumValue);
+ InputStream& readEnumValue(_EnumType& enumValue);
virtual InputStream& readVersionValue(Version& versionValue) = 0;
return *this;
}
-inline InputStream& operator>>(InputStream& inputStream, bool& boolValue) {
- return inputStream.readValue(boolValue);
-}
+InputStream& operator>>(InputStream& inputStream, bool& boolValue);
-inline InputStream& operator>>(InputStream& inputStream, int8_t& int8Value) {
- return inputStream.readValue(int8Value);
-}
+InputStream& operator>>(InputStream& inputStream, int8_t& int8Value);
-inline InputStream& operator>>(InputStream& inputStream, int16_t& int16Value) {
- return inputStream.readValue(int16Value);
-}
+InputStream& operator>>(InputStream& inputStream, int16_t& int16Value);
-inline InputStream& operator>>(InputStream& inputStream, int32_t& int32Value) {
- return inputStream.readValue(int32Value);
-}
+InputStream& operator>>(InputStream& inputStream, int32_t& int32Value);
-inline InputStream& operator>>(InputStream& inputStream, int64_t& int64Value) {
- return inputStream.readValue(int64Value);
-}
+InputStream& operator>>(InputStream& inputStream, int64_t& int64Value);
-inline InputStream& operator>>(InputStream& inputStream, uint8_t& uint8Value) {
- return inputStream.readValue(uint8Value);
-}
-
-inline InputStream& operator>>(InputStream& inputStream, uint16_t& uint16Value) {
- return inputStream.readValue(uint16Value);
-}
+InputStream& operator>>(InputStream& inputStream, uint8_t& uint8Value);
-inline InputStream& operator>>(InputStream& inputStream, uint32_t& uint32Value) {
- return inputStream.readValue(uint32Value);
-}
+InputStream& operator>>(InputStream& inputStream, uint16_t& uint16Value);
-inline InputStream& operator>>(InputStream& inputStream, uint64_t& uint64Value) {
- return inputStream.readValue(uint64Value);
-}
+InputStream& operator>>(InputStream& inputStream, uint32_t& uint32Value);
-inline InputStream& operator>>(InputStream& inputStream, float& floatValue) {
- return inputStream.readValue(floatValue);
-}
+InputStream& operator>>(InputStream& inputStream, uint64_t& uint64Value);
-inline InputStream& operator>>(InputStream& inputStream, double& doubleValue) {
- return inputStream.readValue(doubleValue);
-}
+InputStream& operator>>(InputStream& inputStream, float& floatValue);
-inline InputStream& operator>>(InputStream& inputStream, std::string& stringValue) {
- return inputStream.readValue(stringValue);
-}
+InputStream& operator>>(InputStream& inputStream, double& doubleValue);
-inline InputStream& operator>>(InputStream& inputStream, Version& versionValue) {
- return inputStream.readVersionValue(versionValue);
-}
+InputStream& operator>>(InputStream& inputStream, std::string& stringValue);
-inline InputStream& operator>>(InputStream& inputStream, SerializableStruct& serializableStruct) {
- inputStream.beginReadSerializableStruct(serializableStruct);
- serializableStruct.readFromInputStream(inputStream);
- inputStream.endReadSerializableStruct(serializableStruct);
+InputStream& operator>>(InputStream& inputStream, Version& versionValue);
- return inputStream;
-}
+InputStream& operator>>(InputStream& inputStream, SerializableStruct& serializableStruct);
template<typename _SerializablePolymorphicStructType>
typename std::enable_if<std::is_base_of<SerializablePolymorphicStruct, _SerializablePolymorphicStructType>::value,
return inputStream;
}
-inline InputStream& operator>>(InputStream& inputStream, SerializableVariant& serializableVariant) {
- inputStream.readSerializableVariant(serializableVariant);
- return inputStream;
-}
+InputStream& operator>>(InputStream& inputStream, SerializableVariant& serializableVariant);
template<typename _VectorElementType>
class InputStreamGenericTypeVectorHelper {
--- /dev/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 "MainLoopContext.h"
+
+
+namespace CommonAPI {
+
+int64_t getCurrentTimeInMs() {
+ return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
+}
+
+DispatchSourceListenerSubscription MainLoopContext::subscribeForDispatchSources(DispatchSourceAddedCallback dispatchAddedCallback, DispatchSourceRemovedCallback dispatchRemovedCallback) {
+ dispatchSourceListeners_.emplace_front(dispatchAddedCallback, dispatchRemovedCallback);
+ return dispatchSourceListeners_.begin();
+}
+
+WatchListenerSubscription MainLoopContext::subscribeForWatches(WatchAddedCallback watchAddedCallback, WatchRemovedCallback watchRemovedCallback) {
+ watchListeners_.emplace_front(watchAddedCallback, watchRemovedCallback);
+ return watchListeners_.begin();
+}
+
+TimeoutSourceListenerSubscription MainLoopContext::subscribeForTimeouts(TimeoutSourceAddedCallback timeoutAddedCallback, TimeoutSourceRemovedCallback timeoutRemovedCallback) {
+ timeoutSourceListeners_.emplace_front(timeoutAddedCallback, timeoutRemovedCallback);
+ return timeoutSourceListeners_.begin();
+}
+
+WakeupListenerSubscription MainLoopContext::subscribeForWakeupEvents(WakeupCallback wakeupCallback) {
+ wakeupListeners_.emplace_front(wakeupCallback);
+ return wakeupListeners_.begin();
+}
+
+void MainLoopContext::unsubscribeForDispatchSources(DispatchSourceListenerSubscription subscription) {
+ dispatchSourceListeners_.erase(subscription);
+}
+
+void MainLoopContext::unsubscribeForWatches(WatchListenerSubscription subscription) {
+ watchListeners_.erase(subscription);
+}
+
+void MainLoopContext::unsubscribeForTimeouts(TimeoutSourceListenerSubscription subscription) {
+ timeoutSourceListeners_.erase(subscription);
+}
+
+void MainLoopContext::unsubscribeForWakeupEvents(WakeupListenerSubscription subscription) {
+ wakeupListeners_.erase(subscription);
+}
+
+void MainLoopContext::registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority) {
+ for(auto listener = dispatchSourceListeners_.begin(); listener != dispatchSourceListeners_.end(); ++listener) {
+ listener->first(dispatchSource, dispatchPriority);
+ }
+}
+
+void MainLoopContext::deregisterDispatchSource(DispatchSource* dispatchSource) {
+ for(auto listener = dispatchSourceListeners_.begin(); listener != dispatchSourceListeners_.end(); ++listener) {
+ listener->second(dispatchSource);
+ }
+}
+
+void MainLoopContext::registerWatch(Watch* watch, const DispatchPriority dispatchPriority) {
+ for(auto listener = watchListeners_.begin(); listener != watchListeners_.end(); ++listener) {
+ listener->first(watch, dispatchPriority);
+ }
+}
+
+void MainLoopContext::deregisterWatch(Watch* watch) {
+ for(auto listener = watchListeners_.begin(); listener != watchListeners_.end(); ++listener) {
+ listener->second(watch);
+ }
+}
+
+void MainLoopContext::registerTimeoutSource(Timeout* timeoutEvent, const DispatchPriority dispatchPriority) {
+ for(auto listener = timeoutSourceListeners_.begin(); listener != timeoutSourceListeners_.end(); ++listener) {
+ listener->first(timeoutEvent, dispatchPriority);
+ }
+}
+
+void MainLoopContext::deregisterTimeoutSource(Timeout* timeoutEvent) {
+ for(auto listener = timeoutSourceListeners_.begin(); listener != timeoutSourceListeners_.end(); ++listener) {
+ listener->second(timeoutEvent);
+ }
+}
+
+void MainLoopContext::wakeup() {
+ for(auto listener = wakeupListeners_.begin(); listener != wakeupListeners_.end(); ++listener) {
+ (*listener)();
+ }
+}
+
+bool MainLoopContext::isInitialized() {
+ return dispatchSourceListeners_.size() > 0 || watchListeners_.size() > 0;
+}
+
+} //Namespace CommonAPI
#include <list>
#include <functional>
-
namespace CommonAPI {
-
-
-
enum class DispatchPriority {
VERY_HIGH,
HIGH,
};
-inline int64_t getCurrentTimeInMs() {
- return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
-}
+int64_t getCurrentTimeInMs();
/**
/**
* \brief Registers for all DispatchSources that are added or removed.
*/
- inline DispatchSourceListenerSubscription subscribeForDispatchSources(DispatchSourceAddedCallback dispatchAddedCallback, DispatchSourceRemovedCallback dispatchRemovedCallback) {
- dispatchSourceListeners_.emplace_front(dispatchAddedCallback, dispatchRemovedCallback);
- return dispatchSourceListeners_.begin();
- }
+ DispatchSourceListenerSubscription subscribeForDispatchSources(DispatchSourceAddedCallback dispatchAddedCallback, DispatchSourceRemovedCallback dispatchRemovedCallback);
/**
* \brief Registers for all Watches that are added or removed.
*/
- inline WatchListenerSubscription subscribeForWatches(WatchAddedCallback watchAddedCallback, WatchRemovedCallback watchRemovedCallback) {
- watchListeners_.emplace_front(watchAddedCallback, watchRemovedCallback);
- return watchListeners_.begin();
- }
+ WatchListenerSubscription subscribeForWatches(WatchAddedCallback watchAddedCallback, WatchRemovedCallback watchRemovedCallback);
/**
* \brief Registers for all Timeouts that are added or removed.
*/
- inline TimeoutSourceListenerSubscription subscribeForTimeouts(TimeoutSourceAddedCallback timeoutAddedCallback, TimeoutSourceRemovedCallback timeoutRemovedCallback) {
- timeoutSourceListeners_.emplace_front(timeoutAddedCallback, timeoutRemovedCallback);
- return timeoutSourceListeners_.begin();
- }
+ TimeoutSourceListenerSubscription subscribeForTimeouts(TimeoutSourceAddedCallback timeoutAddedCallback, TimeoutSourceRemovedCallback timeoutRemovedCallback);
/**
* \brief Registers for all Wakeup-Events that need to interrupt a call to "poll".
*/
- inline WakeupListenerSubscription subscribeForWakeupEvents(WakeupCallback wakeupCallback) {
- wakeupListeners_.emplace_front(wakeupCallback);
- return wakeupListeners_.begin();
- }
+ WakeupListenerSubscription subscribeForWakeupEvents(WakeupCallback wakeupCallback);
/**
* \brief Unsubscribes your listeners for DispatchSources.
*/
- inline void unsubscribeForDispatchSources(DispatchSourceListenerSubscription subscription) {
- dispatchSourceListeners_.erase(subscription);
- }
+ void unsubscribeForDispatchSources(DispatchSourceListenerSubscription subscription);
/**
* \brief Unsubscribes your listeners for Watches.
*/
- inline void unsubscribeForWatches(WatchListenerSubscription subscription) {
- watchListeners_.erase(subscription);
- }
+ void unsubscribeForWatches(WatchListenerSubscription subscription);
/**
* \brief Unsubscribes your listeners for Timeouts.
*/
- inline void unsubscribeForTimeouts(TimeoutSourceListenerSubscription subscription) {
- timeoutSourceListeners_.erase(subscription);
- }
+ void unsubscribeForTimeouts(TimeoutSourceListenerSubscription subscription);
/**
* \brief Unsubscribes your listeners for Wakeup-Events.
*/
- inline void unsubscribeForWakeupEvents(WakeupListenerSubscription subscription) {
- wakeupListeners_.erase(subscription);
- }
+ void unsubscribeForWakeupEvents(WakeupListenerSubscription subscription);
/**
* \brief Notifies all listeners about a new DispatchSource.
*/
- inline void registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT) {
- for(auto listener = dispatchSourceListeners_.begin(); listener != dispatchSourceListeners_.end(); ++listener) {
- listener->first(dispatchSource, dispatchPriority);
- }
- }
+ void registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT);
/**
* \brief Notifies all listeners about the removal of a DispatchSource.
*/
- inline void deregisterDispatchSource(DispatchSource* dispatchSource) {
- for(auto listener = dispatchSourceListeners_.begin(); listener != dispatchSourceListeners_.end(); ++listener) {
- listener->second(dispatchSource);
- }
- }
+ void deregisterDispatchSource(DispatchSource* dispatchSource);
/**
* \brief Notifies all listeners about a new Watch.
*/
- inline void registerWatch(Watch* watch, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT) {
- for(auto listener = watchListeners_.begin(); listener != watchListeners_.end(); ++listener) {
- listener->first(watch, dispatchPriority);
- }
- }
+ void registerWatch(Watch* watch, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT);
/**
* \brief Notifies all listeners about the removal of a Watch.
*/
- inline void deregisterWatch(Watch* watch) {
- for(auto listener = watchListeners_.begin(); listener != watchListeners_.end(); ++listener) {
- listener->second(watch);
- }
- }
+ void deregisterWatch(Watch* watch);
/**
* \brief Notifies all listeners about a new Timeout.
*/
- inline void registerTimeoutSource(Timeout* timeoutEvent, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT) {
- for(auto listener = timeoutSourceListeners_.begin(); listener != timeoutSourceListeners_.end(); ++listener) {
- listener->first(timeoutEvent, dispatchPriority);
- }
- }
+ void registerTimeoutSource(Timeout* timeoutEvent, const DispatchPriority dispatchPriority = DispatchPriority::DEFAULT);
/**
* \brief Notifies all listeners about the removal of a Timeout.
*/
- inline void deregisterTimeoutSource(Timeout* timeoutEvent) {
- for(auto listener = timeoutSourceListeners_.begin(); listener != timeoutSourceListeners_.end(); ++listener) {
- listener->second(timeoutEvent);
- }
- }
+ void deregisterTimeoutSource(Timeout* timeoutEvent);
/**
* \brief Notifies all listeners about a wakeup event that just happened.
*/
- inline void wakeup() {
- for(auto listener = wakeupListeners_.begin(); listener != wakeupListeners_.end(); ++listener) {
- (*listener)();
- }
- }
+ void wakeup();
/**
* \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;
- }
+ bool isInitialized();
private:
DispatchSourceListenerList dispatchSourceListeners_;
static const char MIDDLEWARE_INFO_SYMBOL_NAME[] = "middlewareInfo";
#ifndef WIN32
-inline bool Runtime::tryLoadLibrary(const std::string& libraryPath,
+bool Runtime::tryLoadLibrary(const std::string& libraryPath,
void** sharedLibraryHandle,
MiddlewareInfo** foundMiddlewareInfo) {
*
* @return Index of contained type
*/
- inline uint8_t getValueType() const {
- return valueType_;
+ uint8_t getValueType() const {
+ return valueType_;
}
private:
template<typename _EnumType>
class EnumHasher {
public:
- inline size_t operator()(const _EnumType& testEnum) const {
+ size_t operator()(const _EnumType& testEnum) const {
return static_cast<int32_t>(testEnum);
}
--- /dev/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 "utils.h"
+
+namespace CommonAPI {
+std::string getCurrentBinaryFileFQN() {
+ #ifdef WIN32
+ TCHAR result[MAX_PATH];
+ std::basic_string<TCHAR> resultString(result, GetModuleFileName(NULL, result, MAX_PATH));
+ return std::string(resultString.begin(), resultString.end());
+ #else
+ char fqnOfBinary[FILENAME_MAX];
+ char pathToProcessImage[FILENAME_MAX];
+
+ sprintf(pathToProcessImage, "/proc/%d/exe", getpid());
+ const ssize_t lengthOfFqn = readlink(pathToProcessImage, fqnOfBinary, sizeof(fqnOfBinary) - 1);
+
+ if (lengthOfFqn != -1) {
+ fqnOfBinary[lengthOfFqn] = '\0';
+ return std::string(std::move(fqnOfBinary));
+ }
+ else {
+ return std::string("");
+ }
+ #endif
+ }
+
+std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) {
+ std::istringstream ss(s);
+ std::string item;
+ while (std::getline(ss, item, delim)) {
+ elems.push_back(item);
+ }
+ return elems;
+}
+
+std::vector<std::string> split(const std::string& s, char delim) {
+ std::vector<std::string> elems;
+ return split(s, delim, elems);
+}
+
+void trim(std::string& toTrim) {
+ toTrim.erase(
+ toTrim.begin(),
+ std::find_if(toTrim.begin(),
+ toTrim.end(),
+ std::not1(std::ptr_fun(isspace)))
+ );
+ toTrim.erase(
+ std::find_if(toTrim.rbegin(),
+ toTrim.rend(),
+ std::not1(std::ptr_fun(isspace))).base(),
+ toTrim.end()
+ );
+}
+
+bool notIsdigit(char c) {
+ return !std::isdigit(c, std::locale());
+}
+
+bool containsOnlyDigits(const std::string& toCheck) {
+ auto firstNonDigitIt = std::find_if(
+ toCheck.begin(),
+ toCheck.end(),
+ notIsdigit);
+
+ return firstNonDigitIt == toCheck.end();
+}
+
+bool notIsalnum(char c) {
+ return !std::isalnum(c, std::locale());
+}
+
+bool containsOnlyAlphanumericCharacters(const std::string& toCheck) {
+ auto firstNonAlphanumericCharacterIt = std::find_if(
+ toCheck.begin(),
+ toCheck.end(),
+ notIsalnum);
+
+ return firstNonAlphanumericCharacterIt == toCheck.end();
+}
+
+bool isValidDomainName(const std::string& domainName) {
+ return containsOnlyAlphanumericCharacters(domainName);
+}
+
+bool isValidServiceName(const std::string& serviceName) {
+ bool isValid = serviceName[0] != '.' && serviceName[serviceName.size() - 1] != '.';
+
+ if (isValid) {
+ std::vector<std::string> splittedServiceName = split(serviceName, '.');
+
+ for (auto serviceNameElementIt = splittedServiceName.begin();
+ serviceNameElementIt != splittedServiceName.end() && isValid;
+ ++serviceNameElementIt) {
+ isValid &= containsOnlyAlphanumericCharacters(*serviceNameElementIt);
+ }
+ }
+
+ return isValid;
+}
+
+bool isValidInstanceId(const std::string& instanceId) {
+ //Validation rules for ServiceName and InstanceID are equivalent
+ return isValidServiceName(instanceId);
+}
+
+bool isValidCommonApiAddress(const std::string& commonApiAddress) {
+ std::vector<std::string> splittedAddress = split(commonApiAddress, ':');
+ if (splittedAddress.size() != 3) {
+ return false;
+ }
+ return isValidDomainName(splittedAddress[0]) && isValidServiceName(splittedAddress[1]) && isValidInstanceId(splittedAddress[2]);
+}
+
+#ifndef WIN32
+bool loadGenericLibrary(const std::string& wellKnownMiddlewareName, const std::string& libraryName, const std::string& path, bool checkStandardNamePattern) {
+ std::string fqnOfLibrary = path + libraryName;
+ struct stat filestat;
+ if (stat(fqnOfLibrary.c_str(), &filestat)) {
+ return false;
+ }
+ if (S_ISDIR(filestat.st_mode)) {
+ return false;
+ }
+
+ if (checkStandardNamePattern) {
+ const std::string generatedLibPrefix = "lib" + wellKnownMiddlewareName + "Gen-";
+ if (strncmp(generatedLibPrefix.c_str(), libraryName.c_str(), generatedLibPrefix.length()) != 0) {
+ return false;
+ }
+
+ const char* fileNamePtr = libraryName.c_str();
+ while ((fileNamePtr = strchr(fileNamePtr + 1, '.'))) {
+ if (strncmp(".so\0", fileNamePtr, 4) == 0 || strncmp(".so.", fileNamePtr, 4) == 0) {
+ break;
+ }
+ }
+
+ if (!fileNamePtr) {
+ return false;
+ }
+ }
+
+ dlopen(fqnOfLibrary.c_str(), RTLD_NOW | RTLD_GLOBAL);
+ return true;
+}
+
+bool loadGenericLibrary(const std::string& wellKnownMiddlewareName,
+ const std::string& fqnOfLibrary,
+ bool checkStandardNamePattern) {
+ uint32_t position = fqnOfLibrary.find_last_of("/\\");
+ std::string path = fqnOfLibrary.substr(0, position + 1);
+ std::string file = fqnOfLibrary.substr(position + 1);
+ return loadGenericLibrary(wellKnownMiddlewareName, file, path, checkStandardNamePattern);
+}
+
+void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::string& singleSearchPath) {
+ DIR *directory = opendir(singleSearchPath.c_str());
+
+ if (directory != NULL) {
+ struct dirent* entry;
+
+ while ((entry = readdir(directory))) {
+ loadGenericLibrary(requestedMiddlewareName, entry->d_name, singleSearchPath, true);
+ }
+ }
+}
+
+void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::vector<std::string>& searchPaths) {
+ for (const std::string& singleSearchPath : searchPaths) {
+ findAndLoadGenericLibraries(requestedMiddlewareName, singleSearchPath.c_str());
+ }
+}
+#endif
+}//namespace CommonAPI
*
* @return The name of the currently executing binary.
*/
-inline std::string getCurrentBinaryFileFQN() {
-#ifdef WIN32
- TCHAR result[MAX_PATH];
- std::basic_string<TCHAR> resultString(result, GetModuleFileName(NULL, result, MAX_PATH));
- return std::string(resultString.begin(), resultString.end());
-#else
- char fqnOfBinary[FILENAME_MAX];
- char pathToProcessImage[FILENAME_MAX];
-
- sprintf(pathToProcessImage, "/proc/%d/exe", getpid());
- const ssize_t lengthOfFqn = readlink(pathToProcessImage, fqnOfBinary, sizeof(fqnOfBinary) - 1);
-
- if (lengthOfFqn != -1) {
- fqnOfBinary[lengthOfFqn] = '\0';
- return std::string(std::move(fqnOfBinary));
- }
- else {
- return std::string("");
- }
-#endif
-}
+std::string getCurrentBinaryFileFQN();
/**
* \brief Splits a std::string according to the given delim-char.
*
* @return A reference to the vector you passed in (elems)
*/
-inline std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems) {
- std::istringstream ss(s);
- std::string item;
- while (std::getline(ss, item, delim)) {
- elems.push_back(item);
- }
- return elems;
-}
+std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems);
/**
* \brief Splits a std::string according to the given delim-char.
*
* @return A vector containing the splitted string elements.
*/
-inline std::vector<std::string> split(const std::string& s, char delim) {
- std::vector<std::string> elems;
- return split(s, delim, elems);
-}
+std::vector<std::string> split(const std::string& s, char delim);
inline bool isspace(char c) {
return std::isspace(c, std::locale());
*
* @param toTrim: The string that is to be trimmed.
*/
-inline void trim(std::string& toTrim) {
- toTrim.erase(
- toTrim.begin(),
- std::find_if(toTrim.begin(),
- toTrim.end(),
- std::not1(std::ptr_fun(isspace)))
- );
- toTrim.erase(
- std::find_if(toTrim.rbegin(),
- toTrim.rend(),
- std::not1(std::ptr_fun(isspace))).base(),
- toTrim.end()
- );
-}
+void trim(std::string& toTrim);
-inline bool notIsdigit(char c) {
- return !std::isdigit(c, std::locale());
-}
+bool notIsdigit(char c);
/**
* \brief Checks whether the given string contains nothing but digits.
*
* @return true if toCheck contains nothing but digits, false otherwise.
*/
-inline bool containsOnlyDigits(const std::string& toCheck) {
- auto firstNonDigitIt = std::find_if(
- toCheck.begin(),
- toCheck.end(),
- notIsdigit);
-
- return firstNonDigitIt == toCheck.end();
-}
+bool containsOnlyDigits(const std::string& toCheck);
-inline bool notIsalnum(char c) {
- return !std::isalnum(c, std::locale());
-}
+bool notIsalnum(char c);
/**
* \brief Checks whether the given string contains nothing but alphanumeric characters.
*
* @return true if toCheck contains nothing but alphanumeric characters, false otherwise.
*/
-inline bool containsOnlyAlphanumericCharacters(const std::string& toCheck) {
- auto firstNonAlphanumericCharacterIt = std::find_if(
- toCheck.begin(),
- toCheck.end(),
- notIsalnum);
-
- return firstNonAlphanumericCharacterIt == toCheck.end();
-}
+bool containsOnlyAlphanumericCharacters(const std::string& toCheck);
/**
* \brief Checks whether the given std::string is a valid CommonAPI domain name.
*
* @return true if domainName is a valid CommonAPI domainName, false otherwise.
*/
-inline bool isValidDomainName(const std::string& domainName) {
- return containsOnlyAlphanumericCharacters(domainName);
-}
+bool isValidDomainName(const std::string& domainName);
/**
* \brief Checks whether the given std::string is a valid CommonAPI service name.
*
* @return true if serviceName is a valid CommonAPI serviceName, false otherwise.
*/
-inline bool isValidServiceName(const std::string& serviceName) {
- bool isValid = serviceName[0] != '.' && serviceName[serviceName.size() - 1] != '.';
-
- if (isValid) {
- std::vector<std::string> splittedServiceName = split(serviceName, '.');
-
- for (auto serviceNameElementIt = splittedServiceName.begin();
- serviceNameElementIt != splittedServiceName.end() && isValid;
- ++serviceNameElementIt) {
- isValid &= containsOnlyAlphanumericCharacters(*serviceNameElementIt);
- }
- }
-
- return isValid;
-}
+bool isValidServiceName(const std::string& serviceName);
/**
* \brief Checks whether the given std::string is a valid CommonAPI instance ID.
*
* @return true if instanceId is a valid CommonAPI instance ID, false otherwise.
*/
-inline bool isValidInstanceId(const std::string& instanceId) {
- //Validation rules for ServiceName and InstanceID are equivalent
- return isValidServiceName(instanceId);
-}
+bool isValidInstanceId(const std::string& instanceId);
/**
* \brief Checks whether the given std::string is a valid CommonAPI address.
*
* @return true if commonApiAddress is a valid CommonAPI address, false otherwise.
*/
-inline bool isValidCommonApiAddress(const std::string& commonApiAddress) {
- std::vector<std::string> splittedAddress = split(commonApiAddress, ':');
- if (splittedAddress.size() != 3) {
- return false;
- }
- return isValidDomainName(splittedAddress[0]) && isValidServiceName(splittedAddress[1]) && isValidInstanceId(splittedAddress[2]);
-}
+bool isValidCommonApiAddress(const std::string& commonApiAddress);
#ifndef WIN32
/**
* only by specific middlewares. This name however will only be taken into consideration during name checking
* if the checkStandardNamePattern flag is set to true.
*/
-inline bool loadGenericLibrary(const std::string& wellKnownMiddlewareName, const std::string& libraryName, const std::string& path, bool checkStandardNamePattern = true) {
- std::string fqnOfLibrary = path + libraryName;
- struct stat filestat;
- if (stat(fqnOfLibrary.c_str(), &filestat)) {
- return false;
- }
- if (S_ISDIR(filestat.st_mode)) {
- return false;
- }
-
- if (checkStandardNamePattern) {
- const std::string generatedLibPrefix = "lib" + wellKnownMiddlewareName + "Gen-";
- if (strncmp(generatedLibPrefix.c_str(), libraryName.c_str(), generatedLibPrefix.length()) != 0) {
- return false;
- }
-
- const char* fileNamePtr = libraryName.c_str();
- while ((fileNamePtr = strchr(fileNamePtr + 1, '.'))) {
- if (strncmp(".so\0", fileNamePtr, 4) == 0 || strncmp(".so.", fileNamePtr, 4) == 0) {
- break;
- }
- }
-
- if (!fileNamePtr) {
- return false;
- }
- }
-
- dlopen(fqnOfLibrary.c_str(), RTLD_NOW | RTLD_GLOBAL);
- return true;
-}
+bool loadGenericLibrary(const std::string& wellKnownMiddlewareName, const std::string& libraryName, const std::string& path, bool checkStandardNamePattern = true);
/**
* \brief Loads a specific generic library at runtime.
* only by specific middlewares. This name however will only be taken into consideration during name checking
* if the checkStandardNamePattern flag is set to true.
*/
-inline bool loadGenericLibrary(const std::string& wellKnownMiddlewareName,
+bool loadGenericLibrary(const std::string& wellKnownMiddlewareName,
const std::string& fqnOfLibrary,
- bool checkStandardNamePattern = true) {
- uint32_t position = fqnOfLibrary.find_last_of("/\\");
- std::string path = fqnOfLibrary.substr(0, position + 1);
- std::string file = fqnOfLibrary.substr(position + 1);
- return loadGenericLibrary(wellKnownMiddlewareName, file, path, checkStandardNamePattern);
-}
-
+ bool checkStandardNamePattern = true);
/**
* \brief Searches the given path for additional generic CommonAPI libraries and loads them.
* be used to perform the name check.
* @param singleSearchPath: The directory that is to be searched for libraries.
*/
-inline void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::string& singleSearchPath) {
- DIR *directory = opendir(singleSearchPath.c_str());
-
- if (directory != NULL) {
- struct dirent* entry;
-
- while ((entry = readdir(directory))) {
- loadGenericLibrary(requestedMiddlewareName, entry->d_name, singleSearchPath, true);
- }
- }
-}
+void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::string& singleSearchPath);
/**
* \brief Searches the given paths for additional generic CommonAPI libraries and loads them.
* be used to perform the name check.
* @param searchPaths: The directories that are to be searched for libraries.
*/
-inline void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::vector<std::string>& searchPaths) {
- for (const std::string& singleSearchPath : searchPaths) {
- findAndLoadGenericLibraries(requestedMiddlewareName, singleSearchPath.c_str());
- }
-}
+void findAndLoadGenericLibraries(const std::string& requestedMiddlewareName, const std::vector<std::string>& searchPaths);
#endif
} //namespace CommonAPI