logic: interprocess utility
Added basic interprocess utility
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
Settings.cpp WARNING: File for Settings not found: data/TestSettings.xml
|
||||
Token.cpp ERROR: Location Id was not referenced by this Token.
|
||||
Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class
|
||||
Edge.cpp ERROR: Nodes are not plain copies.
|
||||
|
||||
@@ -239,6 +239,19 @@ add_files(
|
||||
utility/file/FileSystem.cpp
|
||||
utility/file/FileSystem.h
|
||||
|
||||
utility/interprocess/InterprocessDataManager.cpp
|
||||
utility/interprocess/InterprocessDataManager.h
|
||||
utility/interprocess/InterprocessProcessManager.cpp
|
||||
utility/interprocess/InterprocessProcessManager.h
|
||||
utility/interprocess/InterprocessUtility.h
|
||||
utility/interprocess/SharedContainer.h
|
||||
utility/interprocess/SharedMap.h
|
||||
utility/interprocess/SharedParserArguments.cpp
|
||||
utility/interprocess/SharedParserArguments.h
|
||||
utility/interprocess/SharedQueue.h
|
||||
utility/interprocess/SharedUUIDMANAGER.cpp
|
||||
utility/interprocess/SharedUUIDMANAGER.h
|
||||
|
||||
utility/logging/ConsoleLogger.cpp
|
||||
utility/logging/ConsoleLogger.h
|
||||
utility/logging/FileLogger.cpp
|
||||
@@ -410,6 +423,8 @@ add_files(
|
||||
utility/utilityLibrary.h
|
||||
utility/utilityString.cpp
|
||||
utility/utilityString.h
|
||||
utility/UUIDUtility.cpp
|
||||
utility/UUIDUtility.h
|
||||
utility/Version.cpp
|
||||
utility/Version.h
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#include "UUIDUtility.h"
|
||||
|
||||
#include <boost/uuid/uuid_generators.hpp>
|
||||
#include <boost/uuid/uuid_io.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
UUID UUIDUtility::getUUID()
|
||||
{
|
||||
return boost::uuids::random_generator()();
|
||||
}
|
||||
|
||||
std::string UUIDUtility::UUIDtoString(const UUID& uuid)
|
||||
{
|
||||
return boost::lexical_cast<std::string>(uuid);
|
||||
}
|
||||
|
||||
std::string UUIDUtility::getUUIDString()
|
||||
{
|
||||
return UUIDtoString(getUUID());
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef UUID_UTILITY_H
|
||||
#define UUID_UTILITY_H
|
||||
|
||||
#include <string>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
|
||||
typedef boost::uuids::uuid UUID;
|
||||
|
||||
class UUIDUtility
|
||||
{
|
||||
public:
|
||||
static UUID getUUID();
|
||||
static std::string UUIDtoString(const UUID& uuid);
|
||||
static std::string getUUIDString();
|
||||
};
|
||||
|
||||
#endif // UUID_UTILITY_H
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "InterprocessDataManager.h"
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
#include "SharedUUIDManager.h"
|
||||
|
||||
#include "InterprocessUtility.h"
|
||||
#include "SharedQueue.h"
|
||||
|
||||
std::string InterprocessDataManager::m_sharedArgumentQueueName = "coati_parser_arguments";
|
||||
|
||||
InterprocessDataManager::InterprocessDataManager(const bool isOwner)
|
||||
: m_isOwner(isOwner)
|
||||
, m_initialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
InterprocessDataManager::~InterprocessDataManager()
|
||||
{
|
||||
SharedUUIDManager::getInstance()->removeUUIDsForInstance(
|
||||
SharedUUIDManager::getInstance()->getInstanceUUID());
|
||||
}
|
||||
|
||||
void InterprocessDataManager::initialize()
|
||||
{
|
||||
try
|
||||
{
|
||||
m_sharedArgumentQueueName = UUIDUtility::getUUIDString() + "_" + m_sharedArgumentQueueName;
|
||||
|
||||
std::string uuid = SharedUUIDManager::getInstance()->getNewUUID();
|
||||
m_parserArguments.initialize(m_isOwner, uuid.c_str());
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void InterprocessDataManager::pushParserArguments(const Parser::Arguments& arguments)
|
||||
{
|
||||
IF_INITIALIZED()
|
||||
{
|
||||
SharedParserArguments::VoidAllocator allocator(m_parserArguments.getSegmentManager());
|
||||
SharedParserArguments args(allocator);
|
||||
|
||||
args.setCompilationDatabasePath(arguments.compilationDatabasePath.str());
|
||||
args.setCompilerFlags(arguments.compilerFlags);
|
||||
args.setFrameworkSearchPaths(arguments.frameworkSearchPaths);
|
||||
args.setHeaderSearchPaths(arguments.headerSearchPaths);
|
||||
args.setJavaClassPaths(arguments.javaClassPaths);
|
||||
args.setLanguage(arguments.language);
|
||||
args.setLanguageStandard(arguments.languageStandard);
|
||||
args.setLogErrors(arguments.logErrors);
|
||||
args.setSystemHeaderSearchPaths(arguments.systemHeaderSearchPaths);
|
||||
|
||||
m_parserArguments.pushValue(args);
|
||||
}
|
||||
}
|
||||
|
||||
Parser::Arguments InterprocessDataManager::popParserArguments()
|
||||
{
|
||||
IF_INITIALIZED(Parser::Arguments())
|
||||
{
|
||||
if (m_parserArguments.size() > 0)
|
||||
{
|
||||
SharedParserArguments args = m_parserArguments.popValue();
|
||||
|
||||
Parser::Arguments result;
|
||||
|
||||
result.compilationDatabasePath = FilePath(args.getCompilationDatabasePath());
|
||||
result.compilerFlags = args.getCompilerFlags();
|
||||
result.frameworkSearchPaths = args.getFrameworkSearchPaths();
|
||||
result.headerSearchPaths = args.getHeaderSearchPaths();
|
||||
result.javaClassPaths = args.getJavaClassPaths();
|
||||
result.language = args.getLanguage();
|
||||
result.languageStandard = args.getLanguageStandard();
|
||||
result.logErrors = args.getLogErrors();
|
||||
result.systemHeaderSearchPaths = args.getSystemHeaderSearchPaths();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int InterprocessDataManager::parserArgumentCount() const
|
||||
{
|
||||
IF_INITIALIZED(0)
|
||||
{
|
||||
return m_parserArguments.size();
|
||||
}
|
||||
}
|
||||
|
||||
void InterprocessDataManager::cleanSharedMemory()
|
||||
{
|
||||
std::vector<std::string> instances = SharedUUIDManager::getInstance()->getStoredInstanceUUIDs();
|
||||
|
||||
for (unsigned int i = 0; i < instances.size(); i++)
|
||||
{
|
||||
std::vector<std::string> uuids = SharedUUIDManager::getInstance()->getUUIDsForInstance(instances[i]);
|
||||
|
||||
if (uuids.size() == 1) // uuid list has to equal the count of used containers
|
||||
{
|
||||
std::string parserArgumentMemName = SharedQueue<SharedParserArguments>::getMemoryNamePrefix() + uuids[0];
|
||||
boost::interprocess::shared_memory_object::remove(parserArgumentMemName.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef INTERPROCESS_DATA_MANAGER_H
|
||||
#define INTERPROCESS_DATA_MANAGER_H
|
||||
|
||||
#include "data/parser/Parser.h"
|
||||
|
||||
#include "SharedQueue.h"
|
||||
|
||||
#include "SharedParserArguments.h"
|
||||
|
||||
class InterprocessDataManager
|
||||
{
|
||||
public:
|
||||
InterprocessDataManager(const bool isOwner = false);
|
||||
~InterprocessDataManager();
|
||||
|
||||
void initialize();
|
||||
|
||||
void pushParserArguments(const Parser::Arguments& arguments);
|
||||
Parser::Arguments popParserArguments();
|
||||
unsigned int parserArgumentCount() const;
|
||||
|
||||
private:
|
||||
void cleanSharedMemory();
|
||||
|
||||
static std::string m_sharedArgumentQueueName;
|
||||
|
||||
bool m_isOwner;
|
||||
bool m_initialized;
|
||||
|
||||
SharedQueue<SharedParserArguments> m_parserArguments;
|
||||
};
|
||||
|
||||
#endif // INTERPROCESS_DATA_MANAGER_H
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "InterprocessProcessManager.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
InterprocessProcessManager::InterprocessProcessManager()
|
||||
: m_processName("")
|
||||
, m_processCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
InterprocessProcessManager::~InterprocessProcessManager()
|
||||
{
|
||||
}
|
||||
|
||||
void InterprocessProcessManager::setProcessName(const std::string& processName)
|
||||
{
|
||||
m_processName = processName;
|
||||
}
|
||||
|
||||
std::string InterprocessProcessManager::getProcessName() const
|
||||
{
|
||||
return m_processName;
|
||||
}
|
||||
|
||||
void InterprocessProcessManager::setProcessCount(const unsigned int processCount)
|
||||
{
|
||||
m_processCount = processCount;
|
||||
}
|
||||
|
||||
unsigned int InterprocessProcessManager::getProcessCount() const
|
||||
{
|
||||
return m_processCount;
|
||||
}
|
||||
|
||||
void InterprocessProcessManager::runProcesses()
|
||||
{
|
||||
std::vector<std::thread*> processThreads;
|
||||
|
||||
for (unsigned int i = 0; i < m_processCount; i++)
|
||||
{
|
||||
std::thread* thread = new std::thread(&InterprocessProcessManager::runProcess, this);
|
||||
processThreads.push_back(thread);
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < m_processCount; i++)
|
||||
{
|
||||
processThreads[i]->join();
|
||||
|
||||
delete processThreads[i];
|
||||
}
|
||||
}
|
||||
|
||||
void InterprocessProcessManager::runProcess()
|
||||
{
|
||||
int result = 1;
|
||||
|
||||
while (result != 0)
|
||||
{
|
||||
result = system(m_processName.c_str());
|
||||
|
||||
LOG_INFO_STREAM(<< "Process returned with " << std::to_string(result));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef INTERPROCESS_PROCESS_MANAGER_H
|
||||
#define INTERPROCESS_PROCESS_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class InterprocessProcessManager
|
||||
{
|
||||
public:
|
||||
InterprocessProcessManager();
|
||||
~InterprocessProcessManager();
|
||||
|
||||
void setProcessName(const std::string& processName);
|
||||
std::string getProcessName() const;
|
||||
|
||||
void setProcessCount(const unsigned int processCount);
|
||||
unsigned int getProcessCount() const;
|
||||
|
||||
void runProcesses();
|
||||
|
||||
private:
|
||||
void runProcess();
|
||||
|
||||
std::string m_processName;
|
||||
unsigned int m_processCount;
|
||||
};
|
||||
|
||||
#endif // INTERPROCESS_PROCESS_MANAGER_H
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef INTERPROCESS_UTILITY_H
|
||||
#define INTERPROCESS_UTILITY_H
|
||||
|
||||
// requires a bool field 'm_initialized' to be defined
|
||||
// if 'm_initialized' is false, the value '__retVal__' will be returned
|
||||
// '__retVal__' is not required
|
||||
#define IF_INITIALIZED(__retVal__) \
|
||||
if(m_initialized == false) \
|
||||
{ \
|
||||
LOG_ERROR_STREAM(<< "not initialized"); \
|
||||
return __retVal__; \
|
||||
} \
|
||||
else \
|
||||
|
||||
#endif // INTERPROCESS_UTILITY_H
|
||||
@@ -0,0 +1,95 @@
|
||||
#ifndef SHARED_CONTAINER_H
|
||||
#define SHARED_CONTAINER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
#include "InterprocessUtility.h"
|
||||
|
||||
class SharedContainer
|
||||
{
|
||||
public:
|
||||
static std::string getMemoryNamePrefix();
|
||||
static std::string getContainerNamePrefix();
|
||||
|
||||
SharedContainer();
|
||||
virtual ~SharedContainer();
|
||||
|
||||
virtual bool initialize(const bool isOwner, const std::string& containerName) = 0;
|
||||
|
||||
protected:
|
||||
static const std::string m_memoryNamePrefix;
|
||||
static const std::string m_containerNamePrefix;
|
||||
|
||||
bool initializeSharedMemory(const bool isOwner);
|
||||
|
||||
boost::interprocess::managed_shared_memory m_sharedMemory;
|
||||
|
||||
bool m_isOwner;
|
||||
bool m_initialized;
|
||||
|
||||
std::string m_memoryName;
|
||||
std::string m_containerName;
|
||||
};
|
||||
|
||||
const std::string SharedContainer::m_memoryNamePrefix("coati_memory_");
|
||||
|
||||
const std::string SharedContainer::m_containerNamePrefix("coati_container_");
|
||||
|
||||
std::string SharedContainer::getMemoryNamePrefix()
|
||||
{
|
||||
return m_memoryNamePrefix;
|
||||
}
|
||||
|
||||
std::string SharedContainer::getContainerNamePrefix()
|
||||
{
|
||||
return m_containerNamePrefix;
|
||||
}
|
||||
|
||||
SharedContainer::SharedContainer()
|
||||
: m_isOwner(false)
|
||||
, m_initialized(false)
|
||||
, m_memoryName(m_memoryNamePrefix)
|
||||
, m_containerName(m_containerNamePrefix)
|
||||
{
|
||||
}
|
||||
|
||||
SharedContainer::~SharedContainer()
|
||||
{
|
||||
}
|
||||
|
||||
bool SharedContainer::initializeSharedMemory(const bool isOwner)
|
||||
{
|
||||
bool initialized = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (isOwner)
|
||||
{
|
||||
boost::interprocess::shared_memory_object::remove(m_memoryName.c_str());
|
||||
|
||||
m_sharedMemory = boost::interprocess::managed_shared_memory(boost::interprocess::create_only,
|
||||
m_memoryName.c_str(),
|
||||
65536);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sharedMemory = boost::interprocess::managed_shared_memory(boost::interprocess::open_only,
|
||||
m_memoryName.c_str());
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR(e.what());
|
||||
}
|
||||
|
||||
return initialized;
|
||||
}
|
||||
|
||||
|
||||
#endif // SHARED_CONTAINER_H
|
||||
@@ -0,0 +1,125 @@
|
||||
#ifndef SHARED_DICTIONARY_H
|
||||
#define SHARED_DICTIONARY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
|
||||
#include "SharedContainer.h"
|
||||
|
||||
template<typename Key, typename Value>
|
||||
class SharedMap : public SharedContainer
|
||||
{
|
||||
public:
|
||||
SharedMap();
|
||||
virtual ~SharedMap();
|
||||
|
||||
virtual void initialize(const bool isOwner, const std::string& mapName);
|
||||
|
||||
Value& operator[](const Key& key);
|
||||
|
||||
unsigned int size() const;
|
||||
|
||||
void clear();
|
||||
|
||||
boost::interprocess::managed_shared_memory::segment_manager* getSegmentManager() const;
|
||||
|
||||
private:
|
||||
typedef std::pair<Key, Value> ValueType;
|
||||
typedef boost::interprocess::allocator<ValueType, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
|
||||
typedef boost::interprocess::map<Key, Value, std::less<Key>, ShmemAllocator> ShmemMap;
|
||||
|
||||
ShmemMap* m_map;
|
||||
};
|
||||
|
||||
template<typename Key, typename Value>
|
||||
SharedMap<Key, Value>::SharedMap()
|
||||
: m_map(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
SharedMap<Key, Value>::~SharedMap()
|
||||
{
|
||||
if (m_map != NULL && m_initialized && m_isOwner)
|
||||
{
|
||||
m_sharedMemory.destroy<ShmemDeque>(m_containerName.c_str());
|
||||
boost::interprocess::shared_memory_object::remove(m_memoryName.c_str());
|
||||
|
||||
delete m_map;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
void SharedMap<Key, Value>::initialize(const bool isOwner, const std::string& mapName)
|
||||
{
|
||||
m_isOwner = isOwner;
|
||||
m_containerName = m_containerNamePrefix + dequeName;
|
||||
m_memoryName = m_memoryNamePrefix + m_containerName;
|
||||
|
||||
if (initializeSharedMemory(m_isOwner))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (m_isOwner)
|
||||
{
|
||||
m_sharedMemory.destroy<ShmemDeque>(m_containerName.c_str());
|
||||
|
||||
const ShmemAllocator allocator(m_sharedMemory.get_segment_manager());
|
||||
|
||||
m_map = m_sharedMemory.construct<ShmemMap>(m_containerName.c_str())(allocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_map = m_sharedMemory.find<ShmemMap>(m_containerName.c_str()).first;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR_STREAM(<< e.what());
|
||||
}
|
||||
}
|
||||
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
Value& SharedMap<Key, Value>::operator[](const Key& key)
|
||||
{
|
||||
IF_INITIALIZED(NULL)
|
||||
{
|
||||
return m_map->at(key);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
unsigned int SharedMap<Key, Value>::size() const
|
||||
{
|
||||
IF_INITIALIZED(0)
|
||||
{
|
||||
return m_map->size();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
void SharedMap<Key, Value>::clear()
|
||||
{
|
||||
IF_INITIALIZED()
|
||||
{
|
||||
m_map->clear();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Key, typename Value>
|
||||
boost::interprocess::managed_shared_memory::segment_manager* SharedMap<Key, Value>::getSegmentManager() const
|
||||
{
|
||||
IF_INITIALIZED(NULL)
|
||||
{
|
||||
return m_sharedMemory.get_segment_manager();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SHARED_DICTIONARY_H
|
||||
@@ -0,0 +1,173 @@
|
||||
#include "SharedParserArguments.h"
|
||||
|
||||
SharedParserArguments::SharedParserArguments(const VoidAllocator& allocator)
|
||||
: m_logErrors(false)
|
||||
, m_language("", allocator)
|
||||
, m_languageStandard("", allocator)
|
||||
, m_compilationDatabasePath("", allocator)
|
||||
, m_javaClassPaths(allocator)
|
||||
, m_headerSearchPaths(allocator)
|
||||
, m_systemHeaderSearchPaths(allocator)
|
||||
, m_frameworkSearchPaths(allocator)
|
||||
, m_compilerFlags(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
SharedParserArguments::~SharedParserArguments()
|
||||
{
|
||||
}
|
||||
|
||||
void SharedParserArguments::setLogErrors(const bool logErrors)
|
||||
{
|
||||
m_logErrors = logErrors;
|
||||
}
|
||||
|
||||
bool SharedParserArguments::getLogErrors() const
|
||||
{
|
||||
return m_logErrors;
|
||||
}
|
||||
|
||||
void SharedParserArguments::setLanguage(const std::string& language)
|
||||
{
|
||||
m_language = language.c_str();
|
||||
}
|
||||
|
||||
std::string SharedParserArguments::getLanguage() const
|
||||
{
|
||||
return std::string(m_language.c_str());
|
||||
}
|
||||
|
||||
void SharedParserArguments::setLanguageStandard(const std::string& languageStandard)
|
||||
{
|
||||
m_languageStandard = languageStandard.c_str();
|
||||
}
|
||||
|
||||
std::string SharedParserArguments::getLanguageStandard() const
|
||||
{
|
||||
return std::string(m_languageStandard.c_str());
|
||||
}
|
||||
|
||||
void SharedParserArguments::setCompilationDatabasePath(const std::string& compilationDatabasePath)
|
||||
{
|
||||
m_compilationDatabasePath = compilationDatabasePath.c_str();
|
||||
}
|
||||
|
||||
std::string SharedParserArguments::getCompilationDatabasePath() const
|
||||
{
|
||||
return std::string(m_compilationDatabasePath.c_str());
|
||||
}
|
||||
|
||||
void SharedParserArguments::setJavaClassPaths(std::vector<FilePath> javaClassPaths)
|
||||
{
|
||||
m_javaClassPaths.clear();
|
||||
for (unsigned int i = 0; i < javaClassPaths.size(); i++)
|
||||
{
|
||||
SharedString path(m_javaClassPaths.get_allocator());
|
||||
path = javaClassPaths[i].str().c_str();
|
||||
m_javaClassPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> SharedParserArguments::getJavaClassPaths() const
|
||||
{
|
||||
std::vector<FilePath> result;
|
||||
|
||||
for (unsigned int i = 0; i < m_javaClassPaths.size(); i++)
|
||||
{
|
||||
result.push_back(FilePath(m_javaClassPaths[i].c_str()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SharedParserArguments::setHeaderSearchPaths(std::vector<FilePath> headerSearchPaths)
|
||||
{
|
||||
m_headerSearchPaths.clear();
|
||||
for (unsigned int i = 0; i < headerSearchPaths.size(); i++)
|
||||
{
|
||||
SharedString path(m_headerSearchPaths.get_allocator());
|
||||
path = headerSearchPaths[i].str().c_str();
|
||||
m_headerSearchPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> SharedParserArguments::getHeaderSearchPaths() const
|
||||
{
|
||||
std::vector<FilePath> result;
|
||||
|
||||
for (unsigned int i = 0; i < m_headerSearchPaths.size(); i++)
|
||||
{
|
||||
result.push_back(FilePath(m_headerSearchPaths[i].c_str()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SharedParserArguments::setSystemHeaderSearchPaths(std::vector<FilePath> systemHeaderSearchPaths)
|
||||
{
|
||||
m_systemHeaderSearchPaths.clear();
|
||||
for (unsigned int i = 0; i < systemHeaderSearchPaths.size(); i++)
|
||||
{
|
||||
SharedString path(m_systemHeaderSearchPaths.get_allocator());
|
||||
path = systemHeaderSearchPaths[i].str().c_str();
|
||||
m_systemHeaderSearchPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> SharedParserArguments::getSystemHeaderSearchPaths() const
|
||||
{
|
||||
std::vector<FilePath> result;
|
||||
|
||||
for (unsigned int i = 0; i < m_systemHeaderSearchPaths.size(); i++)
|
||||
{
|
||||
result.push_back(FilePath(m_systemHeaderSearchPaths[i].c_str()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SharedParserArguments::setFrameworkSearchPaths(std::vector<FilePath> frameworkSearchPaths)
|
||||
{
|
||||
m_frameworkSearchPaths.clear();
|
||||
for (unsigned int i = 0; i < frameworkSearchPaths.size(); i++)
|
||||
{
|
||||
SharedString path(m_frameworkSearchPaths.get_allocator());
|
||||
path = frameworkSearchPaths[i].str().c_str();
|
||||
m_frameworkSearchPaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<FilePath> SharedParserArguments::getFrameworkSearchPaths() const
|
||||
{
|
||||
std::vector<FilePath> result;
|
||||
|
||||
for (unsigned int i = 0; i < m_frameworkSearchPaths.size(); i++)
|
||||
{
|
||||
result.push_back(FilePath(m_frameworkSearchPaths[i].c_str()));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void SharedParserArguments::setCompilerFlags(std::vector<std::string> compilerFlags)
|
||||
{
|
||||
m_compilerFlags.clear();
|
||||
for (unsigned int i = 0; i < compilerFlags.size(); i++)
|
||||
{
|
||||
SharedString path(m_compilerFlags.get_allocator());
|
||||
path = compilerFlags[i].c_str();
|
||||
m_compilerFlags.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> SharedParserArguments::getCompilerFlags() const
|
||||
{
|
||||
std::vector<std::string> result;
|
||||
|
||||
for (unsigned int i = 0; i < m_compilerFlags.size(); i++)
|
||||
{
|
||||
result.push_back(m_compilerFlags[i].c_str());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
#ifndef SHARED_PARSER_ARGUMENTS_H
|
||||
#define SHARED_PARSER_ARGUMENTS_H
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <boost/interprocess/containers/string.hpp>
|
||||
#include <boost/interprocess/containers/vector.hpp>
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
|
||||
class SharedParserArguments
|
||||
{
|
||||
public:
|
||||
typedef boost::interprocess::allocator<void, boost::interprocess::managed_shared_memory::segment_manager> VoidAllocator;
|
||||
|
||||
SharedParserArguments(const VoidAllocator& allocator);
|
||||
~SharedParserArguments();
|
||||
|
||||
void setLogErrors(const bool logErrors);
|
||||
bool getLogErrors() const;
|
||||
|
||||
|
||||
void setLanguage(const std::string& language);
|
||||
std::string getLanguage() const;
|
||||
|
||||
|
||||
void setLanguageStandard(const std::string& languageStandard);
|
||||
std::string getLanguageStandard() const;
|
||||
|
||||
void setCompilationDatabasePath(const std::string& compilationDatabasePath);
|
||||
std::string getCompilationDatabasePath() const;
|
||||
|
||||
void setJavaClassPaths(std::vector<FilePath> javaClassPaths);
|
||||
std::vector<FilePath> getJavaClassPaths() const;
|
||||
|
||||
void setHeaderSearchPaths(std::vector<FilePath> headerSearchPaths);
|
||||
std::vector<FilePath> getHeaderSearchPaths() const;
|
||||
|
||||
void setSystemHeaderSearchPaths(std::vector<FilePath> systemHeaderSearchPaths);
|
||||
std::vector<FilePath> getSystemHeaderSearchPaths() const;
|
||||
|
||||
void setFrameworkSearchPaths(std::vector<FilePath> frameworkSearchPaths);
|
||||
std::vector<FilePath> getFrameworkSearchPaths() const;
|
||||
|
||||
void setCompilerFlags(std::vector<std::string> compilerFlags);
|
||||
std::vector<std::string> getCompilerFlags() const;
|
||||
|
||||
private:
|
||||
typedef boost::interprocess::allocator<char, boost::interprocess::managed_shared_memory::segment_manager> CharAllocator;
|
||||
typedef boost::interprocess::basic_string<char, std::char_traits<char>, CharAllocator> SharedString;
|
||||
typedef boost::interprocess::allocator<SharedString, boost::interprocess::managed_shared_memory::segment_manager> StringAllocator;
|
||||
typedef boost::interprocess::vector<SharedString, StringAllocator> SharedStringVector;
|
||||
|
||||
bool m_logErrors;
|
||||
|
||||
SharedString m_language;
|
||||
SharedString m_languageStandard;
|
||||
SharedString m_compilationDatabasePath;
|
||||
|
||||
SharedStringVector m_javaClassPaths;
|
||||
SharedStringVector m_headerSearchPaths;
|
||||
SharedStringVector m_systemHeaderSearchPaths;
|
||||
SharedStringVector m_frameworkSearchPaths;
|
||||
SharedStringVector m_compilerFlags;
|
||||
};
|
||||
|
||||
#endif // SHARED_PARSER_ARGUMENTS_H
|
||||
@@ -0,0 +1,128 @@
|
||||
#ifndef SHARED_QUEUE_H
|
||||
#define SHARED_QUEUE_H
|
||||
|
||||
#include <boost/interprocess/containers/deque.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
|
||||
#include "SharedContainer.h"
|
||||
|
||||
template<typename T>
|
||||
class SharedQueue : public SharedContainer
|
||||
{
|
||||
public:
|
||||
SharedQueue();
|
||||
virtual ~SharedQueue();
|
||||
|
||||
virtual bool initialize(const bool isOwner, const std::string& dequeName);
|
||||
|
||||
void pushValue(const T& val);
|
||||
T popValue();
|
||||
|
||||
unsigned int size() const;
|
||||
|
||||
boost::interprocess::managed_shared_memory::segment_manager* getSegmentManager() const;
|
||||
|
||||
private:
|
||||
typedef boost::interprocess::allocator<T, boost::interprocess::managed_shared_memory::segment_manager> ShmemAllocator;
|
||||
typedef boost::interprocess::deque<T, ShmemAllocator> ShmemDeque;
|
||||
|
||||
ShmemDeque* m_deque;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
SharedQueue<T>::SharedQueue()
|
||||
: m_deque(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
SharedQueue<T>::~SharedQueue()
|
||||
{
|
||||
if (m_deque != NULL && m_initialized && m_isOwner)
|
||||
{
|
||||
m_sharedMemory.destroy<ShmemDeque>(m_containerName.c_str());
|
||||
boost::interprocess::shared_memory_object::remove(m_memoryName.c_str());
|
||||
|
||||
delete m_deque;
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool SharedQueue<T>::initialize(const bool isOwner, const std::string& dequeName)
|
||||
{
|
||||
m_isOwner = isOwner;
|
||||
m_containerName = m_containerNamePrefix + dequeName;
|
||||
m_memoryName = m_memoryNamePrefix + m_containerName;
|
||||
|
||||
if (initializeSharedMemory(m_isOwner))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (isOwner)
|
||||
{
|
||||
m_sharedMemory.destroy<ShmemDeque>(m_containerName.c_str());
|
||||
|
||||
const ShmemAllocator allocator(m_sharedMemory.get_segment_manager());
|
||||
|
||||
m_deque = m_sharedMemory.construct<ShmemDeque>(m_containerName.c_str())(allocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_deque = m_sharedMemory.find<ShmemDeque>(m_containerName.c_str()).first;
|
||||
}
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
LOG_ERROR(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SharedQueue<T>::pushValue(const T& val)
|
||||
{
|
||||
IF_INITIALIZED()
|
||||
{
|
||||
m_deque->push_back(val);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T SharedQueue<T>::popValue()
|
||||
{
|
||||
if (m_initialized)
|
||||
{
|
||||
T val = m_deque->front();
|
||||
m_deque->pop_front();
|
||||
|
||||
return val;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw(std::exception("Deque was not initialized"));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
unsigned int SharedQueue<T>::size() const
|
||||
{
|
||||
IF_INITIALIZED(0)
|
||||
{
|
||||
return m_deque->size();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
boost::interprocess::managed_shared_memory::segment_manager* SharedQueue<T>::getSegmentManager() const
|
||||
{
|
||||
IF_INITIALIZED(NULL)
|
||||
{
|
||||
return m_sharedMemory.get_segment_manager();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // SHARED_QUEUE_H
|
||||
@@ -0,0 +1,128 @@
|
||||
#include "SharedUUIDManager.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/ConfigManager.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
#include "utility/UserPaths.h"
|
||||
|
||||
const std::string SharedUUIDManager::m_fileName("sharedUUIDs.xml");
|
||||
const std::string SharedUUIDManager::m_instanceUUIDsKey("instances");
|
||||
std::shared_ptr<SharedUUIDManager> SharedUUIDManager::m_instance(NULL);
|
||||
|
||||
std::shared_ptr<SharedUUIDManager> SharedUUIDManager::getInstance()
|
||||
{
|
||||
if (m_instance == NULL)
|
||||
{
|
||||
// m_instance = std::make_shared<SharedUUIDManager>();
|
||||
SharedUUIDManager* sharedUUIDManager = new SharedUUIDManager();
|
||||
m_instance = std::shared_ptr<SharedUUIDManager>(sharedUUIDManager);
|
||||
m_instance->setFilePath(UserPaths::getUserDataPath());
|
||||
m_instance->saveInstanceUUID();
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
SharedUUIDManager::~SharedUUIDManager()
|
||||
{
|
||||
}
|
||||
|
||||
void SharedUUIDManager::setFilePath(const std::string& filePath)
|
||||
{
|
||||
m_filePath = filePath;
|
||||
FileSystem::createDirectory(m_filePath);
|
||||
|
||||
refreshUUIDs();
|
||||
}
|
||||
|
||||
std::string SharedUUIDManager::getInstanceUUID() const
|
||||
{
|
||||
return UUIDUtility::UUIDtoString(m_instanceUUID);
|
||||
}
|
||||
|
||||
std::string SharedUUIDManager::getNewUUID()
|
||||
{
|
||||
std::string uuidString = UUIDUtility::getUUIDString();
|
||||
|
||||
std::vector<std::string> uuids;
|
||||
m_uuids->getValues(UUIDUtility::UUIDtoString(m_instanceUUID), uuids);
|
||||
|
||||
uuids.push_back(uuidString);
|
||||
|
||||
m_uuids->setValues(UUIDUtility::UUIDtoString(m_instanceUUID), uuids);
|
||||
|
||||
m_uuids->save(m_filePath + m_fileName);
|
||||
|
||||
return uuidString;
|
||||
}
|
||||
|
||||
std::vector<std::string> SharedUUIDManager::getUUIDsForInstance(const std::string& instanceUUID)
|
||||
{
|
||||
std::vector<std::string> uuids;
|
||||
m_uuids->getValues(instanceUUID, uuids);
|
||||
|
||||
return uuids;
|
||||
}
|
||||
|
||||
void SharedUUIDManager::removeUUIDsForInstance(const std::string& instanceUUID)
|
||||
{
|
||||
m_uuids->removeValues(instanceUUID);
|
||||
|
||||
m_uuids->save(m_filePath + m_fileName);
|
||||
}
|
||||
|
||||
std::vector<std::string> SharedUUIDManager::getStoredInstanceUUIDs() const
|
||||
{
|
||||
std::vector<std::string> instanceUUIDs;
|
||||
m_uuids->getValues(m_instanceUUIDsKey, instanceUUIDs);
|
||||
|
||||
return instanceUUIDs;
|
||||
}
|
||||
|
||||
void SharedUUIDManager::removeInstanceUUID(const std::string& instanceUUID)
|
||||
{
|
||||
std::vector<std::string> instanceUUIDs;
|
||||
m_uuids->getValues(m_instanceUUIDsKey, instanceUUIDs);
|
||||
|
||||
// instanceUUIDs
|
||||
|
||||
std::vector<std::string>::iterator it = instanceUUIDs.begin();
|
||||
for (it; it != instanceUUIDs.end(); it++)
|
||||
{
|
||||
if (*it == instanceUUID)
|
||||
{
|
||||
instanceUUIDs.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
m_uuids->setValues(m_instanceUUIDsKey, instanceUUIDs);
|
||||
m_uuids->save(m_filePath + m_fileName);
|
||||
}
|
||||
|
||||
SharedUUIDManager::SharedUUIDManager()
|
||||
: m_filePath("user/")
|
||||
, m_instanceUUID(UUIDUtility::getUUID())
|
||||
, m_uuids(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
void SharedUUIDManager::saveInstanceUUID()
|
||||
{
|
||||
std::vector<std::string> instanceUUIDs;
|
||||
m_uuids->getValues(m_instanceUUIDsKey, instanceUUIDs);
|
||||
|
||||
instanceUUIDs.push_back(getInstanceUUID());
|
||||
m_uuids->setValues(m_instanceUUIDsKey, instanceUUIDs);
|
||||
}
|
||||
|
||||
void SharedUUIDManager::refreshUUIDs()
|
||||
{
|
||||
if (FilePath(m_filePath + m_fileName).exists())
|
||||
{
|
||||
m_uuids = ConfigManager::createAndLoad(TextAccess::createFromFile(m_filePath + m_fileName));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
#ifndef SHARED_UUID_MANAGER_H
|
||||
#define SHARED_UUID_MANAGER_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include "utility/UUIDUtility.h"
|
||||
|
||||
#include "utility/ConfigManager.h"
|
||||
|
||||
class SharedUUIDManager
|
||||
{
|
||||
public:
|
||||
static std::shared_ptr<SharedUUIDManager> getInstance();
|
||||
|
||||
~SharedUUIDManager();
|
||||
|
||||
void setFilePath(const std::string& filePath);
|
||||
|
||||
std::string getInstanceUUID() const;
|
||||
std::string getNewUUID();
|
||||
|
||||
std::vector<std::string> getUUIDsForInstance(const std::string& instanceUUID);
|
||||
void removeUUIDsForInstance(const std::string& instanceUUID);
|
||||
|
||||
std::vector<std::string> getStoredInstanceUUIDs() const;
|
||||
void removeInstanceUUID(const std::string& instanceUUID);
|
||||
|
||||
private:
|
||||
SharedUUIDManager();
|
||||
|
||||
void saveInstanceUUID();
|
||||
|
||||
void refreshUUIDs();
|
||||
|
||||
static const std::string m_fileName;
|
||||
static const std::string m_instanceUUIDsKey;
|
||||
static std::shared_ptr<SharedUUIDManager> m_instance;
|
||||
|
||||
std::string m_filePath;
|
||||
|
||||
const UUID m_instanceUUID;
|
||||
|
||||
std::shared_ptr<ConfigManager> m_uuids;
|
||||
};
|
||||
|
||||
#endif // SHARED_UUID_MANAGER_H
|
||||
Reference in New Issue
Block a user