FairMQ: Add uuid generator to tools & let tests use it for session names.

This commit is contained in:
Alexey Rybalchenko 2017-11-28 17:25:39 +01:00 committed by Mohammad Al-Turany
parent 85aab51bd4
commit 0dc4000187
14 changed files with 218 additions and 67 deletions

View File

@ -110,6 +110,7 @@ set(FAIRMQ_HEADER_FILES
tools/Network.h tools/Network.h
tools/Strings.h tools/Strings.h
tools/Version.h tools/Version.h
tools/Unique.h
zeromq/FairMQMessageZMQ.h zeromq/FairMQMessageZMQ.h
zeromq/FairMQPollerZMQ.h zeromq/FairMQPollerZMQ.h
zeromq/FairMQUnmanagedRegionZMQ.h zeromq/FairMQUnmanagedRegionZMQ.h
@ -269,6 +270,8 @@ target_link_libraries(runConfigExample FairMQ)
add_executable(shmmonitor shmem/runMonitor.cxx) add_executable(shmmonitor shmem/runMonitor.cxx)
target_link_libraries(shmmonitor FairMQ) target_link_libraries(shmmonitor FairMQ)
add_executable(uuidGen run/runUuidGenerator.cxx)
target_link_libraries(uuidGen FairMQ)
#################### ####################
# aggregate target # # aggregate target #

View File

@ -13,10 +13,7 @@
#include <nanomsg/FairMQTransportFactoryNN.h> #include <nanomsg/FairMQTransportFactoryNN.h>
#endif /* NANOMSG_FOUND */ #endif /* NANOMSG_FOUND */
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <fairmq/Tools.h>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <memory> #include <memory>
#include <string> #include <string>
@ -36,7 +33,7 @@ auto FairMQTransportFactory::CreateTransportFactory(const std::string& type, con
// Generate uuid if empty // Generate uuid if empty
if (finalId == "") if (finalId == "")
{ {
finalId = boost::uuids::to_string(boost::uuids::random_generator()()); finalId = fair::mq::tools::Uuid();
} }
if (type == "zeromq") if (type == "zeromq")

View File

@ -14,6 +14,7 @@
#include <fairmq/tools/Network.h> #include <fairmq/tools/Network.h>
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
#include <fairmq/tools/Version.h> #include <fairmq/tools/Version.h>
#include <fairmq/tools/Unique.h>
// IWYU pragma: end_exports // IWYU pragma: end_exports
#endif // FAIR_MQ_TOOLS_H #endif // FAIR_MQ_TOOLS_H

View File

@ -0,0 +1,58 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#include <fairmq/Tools.h>
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
using namespace std;
using namespace boost::program_options;
int main(int argc, char** argv)
{
try
{
bool hash = false;
options_description desc("Options");
desc.add_options()
("hash,h", value<bool>(&hash)->implicit_value(true), "Generates UUID and returns its hash.")
("help", "Print help");
variables_map vm;
store(parse_command_line(argc, argv, desc), vm);
if (vm.count("help"))
{
cout << "UUID generator" << endl << desc << endl;
return 0;
}
notify(vm);
if (hash)
{
std::cout << fair::mq::tools::UuidHash() << std::endl;
}
else
{
std::cout << fair::mq::tools::Uuid() << std::endl;
}
return 0;
}
catch (exception& e)
{
cerr << "Unhandled Exception reached the top of main: " << e.what() << ", application will now exit" << endl;
return 2;
}
return 0;
}

View File

@ -35,12 +35,12 @@ FairMQ::Transport FairMQTransportFactorySHM::fTransportType = FairMQ::Transport:
FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const FairMQProgOptions* config) FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const FairMQProgOptions* config)
: FairMQTransportFactory(id) : FairMQTransportFactory(id)
, fSessionName("default") , fSessionName()
, fContext(nullptr) , fContext(nullptr)
, fHeartbeatSocket(nullptr) , fHeartbeatSocket(nullptr)
, fHeartbeatThread() , fHeartbeatThread()
, fSendHeartbeats(true) , fSendHeartbeats(true)
, fShMutex(bipc::open_or_create, std::string("fmq_shm_" + fSessionName + "_mutex").c_str()) , fShMutex(nullptr)
, fDeviceCounter(nullptr) , fDeviceCounter(nullptr)
, fManager(nullptr) , fManager(nullptr)
{ {
@ -62,6 +62,7 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
{ {
numIoThreads = config->GetValue<int>("io-threads"); numIoThreads = config->GetValue<int>("io-threads");
fSessionName = config->GetValue<string>("session"); fSessionName = config->GetValue<string>("session");
fSessionName.resize(8); // shorten the session name, to acomodate for name size limit on some systems (MacOS)
// fSegmentName = "fmq_shm_" + fSessionName + "_main"; // fSegmentName = "fmq_shm_" + fSessionName + "_main";
segmentSize = config->GetValue<size_t>("shm-segment-size"); segmentSize = config->GetValue<size_t>("shm-segment-size");
} }
@ -70,56 +71,66 @@ FairMQTransportFactorySHM::FairMQTransportFactorySHM(const string& id, const Fai
LOG(WARN) << "shmem: FairMQProgOptions not available! Using defaults."; LOG(WARN) << "shmem: FairMQProgOptions not available! Using defaults.";
} }
if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0) try
{ {
LOG(ERROR) << "shmem: failed configuring context, reason: " << zmq_strerror(errno); fShMutex = fair::mq::tools::make_unique<bipc::named_mutex>(bipc::open_or_create, std::string("fmq_shm_" + fSessionName + "_mutex").c_str());
}
// Set the maximum number of allowed sockets on the context. if (zmq_ctx_set(fContext, ZMQ_IO_THREADS, numIoThreads) != 0)
if (zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000) != 0)
{
LOG(ERROR) << "shmem: failed configuring context, reason: " << zmq_strerror(errno);
}
fManager = fair::mq::tools::make_unique<Manager>(fSessionName, segmentSize);
LOG(DEBUG) << "shmem: created/opened shared memory segment of " << segmentSize << " bytes. Available are " << fManager->Segment().get_free_memory() << " bytes.";
{
bipc::scoped_lock<bipc::named_mutex> lock(fShMutex);
fDeviceCounter = fManager->Segment().find<DeviceCounter>(bipc::unique_instance).first;
if (fDeviceCounter)
{ {
LOG(DEBUG) << "shmem: device counter found, with value of " << fDeviceCounter->fCount << ". incrementing."; LOG(ERROR) << "shmem: failed configuring context, reason: " << zmq_strerror(errno);
(fDeviceCounter->fCount)++;
LOG(DEBUG) << "shmem: incremented device counter, now: " << fDeviceCounter->fCount;
}
else
{
LOG(DEBUG) << "shmem: no device counter found, creating one and initializing with 1";
fDeviceCounter = fManager->Segment().construct<DeviceCounter>(bipc::unique_instance)(1);
LOG(DEBUG) << "shmem: initialized device counter with: " << fDeviceCounter->fCount;
} }
// start shm monitor // Set the maximum number of allowed sockets on the context.
// try if (zmq_ctx_set(fContext, ZMQ_MAX_SOCKETS, 10000) != 0)
// { {
// MonitorStatus* monitorStatus = fManagementSegment.find<MonitorStatus>(bipc::unique_instance).first; LOG(ERROR) << "shmem: failed configuring context, reason: " << zmq_strerror(errno);
// if (monitorStatus == nullptr) }
// {
// LOG(DEBUG) << "shmem: no shmmonitor found, starting..."; fManager = fair::mq::tools::make_unique<Manager>(fSessionName, segmentSize);
// StartMonitor(); LOG(DEBUG) << "shmem: created/opened shared memory segment of " << segmentSize << " bytes. Available are " << fManager->Segment().get_free_memory() << " bytes.";
// }
// else {
// { bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
// LOG(DEBUG) << "shmem: found shmmonitor.";
// } fDeviceCounter = fManager->Segment().find<DeviceCounter>(bipc::unique_instance).first;
// } if (fDeviceCounter)
// catch (std::exception& e) {
// { LOG(DEBUG) << "shmem: device counter found, with value of " << fDeviceCounter->fCount << ". incrementing.";
// LOG(ERROR) << "shmem: Exception during shmmonitor initialization: " << e.what() << ", application will now exit"; (fDeviceCounter->fCount)++;
// exit(EXIT_FAILURE); LOG(DEBUG) << "shmem: incremented device counter, now: " << fDeviceCounter->fCount;
// } }
else
{
LOG(DEBUG) << "shmem: no device counter found, creating one and initializing with 1";
fDeviceCounter = fManager->Segment().construct<DeviceCounter>(bipc::unique_instance)(1);
LOG(DEBUG) << "shmem: initialized device counter with: " << fDeviceCounter->fCount;
}
// start shm monitor
// try
// {
// MonitorStatus* monitorStatus = fManagementSegment.find<MonitorStatus>(bipc::unique_instance).first;
// if (monitorStatus == nullptr)
// {
// LOG(DEBUG) << "shmem: no shmmonitor found, starting...";
// StartMonitor();
// }
// else
// {
// LOG(DEBUG) << "shmem: found shmmonitor.";
// }
// }
// catch (std::exception& e)
// {
// LOG(ERROR) << "shmem: Exception during shmmonitor initialization: " << e.what() << ", application will now exit";
// exit(EXIT_FAILURE);
// }
}
}
catch(bipc::interprocess_exception& e)
{
LOG(ERROR) << "Could not initialize shared memory transport: " << e.what();
throw runtime_error("Cannot update configuration. Socket method (bind/connect) not specified.");
} }
fSendHeartbeats = true; fSendHeartbeats = true;
@ -267,7 +278,7 @@ FairMQTransportFactorySHM::~FairMQTransportFactorySHM()
bool lastRemoved = false; bool lastRemoved = false;
{ // mutex scope { // mutex scope
bipc::scoped_lock<bipc::named_mutex> lock(fShMutex); bipc::scoped_lock<bipc::named_mutex> lock(*fShMutex);
(fDeviceCounter->fCount)--; (fDeviceCounter->fCount)--;

View File

@ -60,7 +60,7 @@ class FairMQTransportFactorySHM : public FairMQTransportFactory
void* fHeartbeatSocket; void* fHeartbeatSocket;
std::thread fHeartbeatThread; std::thread fHeartbeatThread;
std::atomic<bool> fSendHeartbeats; std::atomic<bool> fSendHeartbeats;
boost::interprocess::named_mutex fShMutex; std::unique_ptr<boost::interprocess::named_mutex> fShMutex;
fair::mq::shmem::DeviceCounter* fDeviceCounter; fair::mq::shmem::DeviceCounter* fDeviceCounter;
std::unique_ptr<fair::mq::shmem::Manager> fManager; std::unique_ptr<fair::mq::shmem::Manager> fManager;
}; };

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include "runner.h"
#include <fairmq/Tools.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> // std::stringstream #include <sstream> // std::stringstream
#include <thread> #include <thread>
@ -19,13 +20,15 @@ using namespace fair::mq::test;
auto RunPoller(string transport, int pollType) -> void auto RunPoller(string transport, int pollType) -> void
{ {
size_t session{fair::mq::tools::UuidHash()};
auto pollout = execute_result{"", 0}; auto pollout = execute_result{"", 0};
thread poll_out_thread([&]() { thread poll_out_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice cmd << runTestDevice
<< " --id pollout_"<< transport << " --id pollout_"<< transport
<< " --control static --verbosity DEBUG --log-color false" << " --control static --verbosity DEBUG --log-color false"
<< " --mq-config \"" << mqConfig << "\""; << " --session " << session << " --mq-config \"" << mqConfig << "\"";
pollout = execute(cmd.str(), "[POLLOUT]"); pollout = execute(cmd.str(), "[POLLOUT]");
}); });
@ -35,7 +38,7 @@ auto RunPoller(string transport, int pollType) -> void
cmd << runTestDevice cmd << runTestDevice
<< " --id pollin_" << transport << " --id pollin_" << transport
<< " --control static --verbosity DEBUG --log-color false" << " --control static --verbosity DEBUG --log-color false"
<< " --mq-config \"" << mqConfig << "\" --poll-type " << pollType; << " --session " << session << " --mq-config \"" << mqConfig << "\" --poll-type " << pollType;
pollin = execute(cmd.str(), "[POLLIN]"); pollin = execute(cmd.str(), "[POLLIN]");
}); });

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include "runner.h"
#include <fairmq/Tools.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> // std::stringstream #include <sstream> // std::stringstream
#include <thread> #include <thread>
@ -19,11 +20,13 @@ using namespace fair::mq::test;
auto RunPubSub(string transport) -> void auto RunPubSub(string transport) -> void
{ {
size_t session{fair::mq::tools::UuidHash()};
auto pub = execute_result{"", 0}; auto pub = execute_result{"", 0};
thread pub_thread([&]() { thread pub_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id pub_" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id pub_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
pub = execute(cmd.str(), "[PUB]"); pub = execute(cmd.str(), "[PUB]");
}); });
@ -31,7 +34,7 @@ auto RunPubSub(string transport) -> void
thread sub1_thread([&]() { thread sub1_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id sub_1" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id sub_1" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
sub1 = execute(cmd.str(), "[SUB1]"); sub1 = execute(cmd.str(), "[SUB1]");
}); });
@ -39,7 +42,7 @@ auto RunPubSub(string transport) -> void
thread sub2_thread([&]() { thread sub2_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id sub_2" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id sub_2" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
sub2 = execute(cmd.str(), "[SUB2]"); sub2 = execute(cmd.str(), "[SUB2]");
}); });

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include "runner.h"
#include <fairmq/Tools.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> // std::stringstream #include <sstream> // std::stringstream
#include <thread> #include <thread>
@ -19,11 +20,13 @@ using namespace fair::mq::test;
auto RunPushPull(string transport) -> void auto RunPushPull(string transport) -> void
{ {
size_t session{fair::mq::tools::UuidHash()};
auto push = execute_result{"", 100}; auto push = execute_result{"", 100};
thread push_thread([&]() { thread push_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id push_" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id push_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
push = execute(cmd.str(), "[PUSH]"); push = execute(cmd.str(), "[PUSH]");
}); });
@ -31,7 +34,7 @@ auto RunPushPull(string transport) -> void
thread pull_thread([&]() { thread pull_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id pull_" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id pull_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
pull = execute(cmd.str(), "[PULL]"); pull = execute(cmd.str(), "[PULL]");
}); });

View File

@ -11,6 +11,9 @@
#include <FairMQParts.h> #include <FairMQParts.h>
#include <FairMQLogger.h> #include <FairMQLogger.h>
#include <FairMQTransportFactory.h> #include <FairMQTransportFactory.h>
#include <fairmq/Tools.h>
#include <options/FairMQProgOptions.h>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <sstream> #include <sstream>
@ -23,7 +26,14 @@ namespace
using namespace std; using namespace std;
auto RunSingleThreadedMultipart(string transport, string address) -> void { auto RunSingleThreadedMultipart(string transport, string address) -> void {
auto factory = FairMQTransportFactory::CreateTransportFactory(transport);
size_t session{fair::mq::tools::UuidHash()};
FairMQProgOptions config;
config.SetValue<string>("session", std::to_string(session));
config.SetValue<int>("io-threads", 1);
config.SetValue<size_t>("shm-segment-size", 20000000);
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
auto push = FairMQChannel{"Push", "push", factory}; auto push = FairMQChannel{"Push", "push", factory};
ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(push.Bind(address));
auto pull = FairMQChannel{"Pull", "pull", factory}; auto pull = FairMQChannel{"Pull", "pull", factory};
@ -55,7 +65,13 @@ auto RunSingleThreadedMultipart(string transport, string address) -> void {
auto RunMultiThreadedMultipart(string transport, string address) -> void auto RunMultiThreadedMultipart(string transport, string address) -> void
{ {
auto factory = FairMQTransportFactory::CreateTransportFactory(transport); size_t session{fair::mq::tools::UuidHash()};
FairMQProgOptions config;
config.SetValue<string>("session", std::to_string(session));
config.SetValue<int>("io-threads", 1);
config.SetValue<size_t>("shm-segment-size", 20000000);
auto factory = FairMQTransportFactory::CreateTransportFactory(transport, fair::mq::tools::Uuid(), &config);
auto push = FairMQChannel{"Push", "push", factory}; auto push = FairMQChannel{"Push", "push", factory};
ASSERT_TRUE(push.Bind(address)); ASSERT_TRUE(push.Bind(address));
auto pull = FairMQChannel{"Pull", "pull", factory}; auto pull = FairMQChannel{"Pull", "pull", factory};

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include "runner.h"
#include <fairmq/Tools.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> // std::stringstream #include <sstream> // std::stringstream
#include <thread> #include <thread>
@ -19,11 +20,13 @@ using namespace fair::mq::test;
auto RunReqRep(string transport) -> void auto RunReqRep(string transport) -> void
{ {
size_t session{fair::mq::tools::UuidHash()};
auto rep = execute_result{ "", 0 }; auto rep = execute_result{ "", 0 };
thread rep_thread([&]() { thread rep_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id rep_" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id rep_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
rep = execute(cmd.str(), "[REP]"); rep = execute(cmd.str(), "[REP]");
}); });
@ -31,7 +34,7 @@ auto RunReqRep(string transport) -> void
thread req1_thread([&]() { thread req1_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id req_1" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id req_1" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
req1 = execute(cmd.str(), "[REQ1]"); req1 = execute(cmd.str(), "[REQ1]");
}); });
@ -39,7 +42,7 @@ auto RunReqRep(string transport) -> void
thread req2_thread([&]() { thread req2_thread([&]() {
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id req_2" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id req_2" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
req2 = execute(cmd.str(), "[REQ2]"); req2 = execute(cmd.str(), "[REQ2]");
}); });

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include "runner.h" #include "runner.h"
#include <fairmq/Tools.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <sstream> // std::stringstream #include <sstream> // std::stringstream
@ -18,9 +19,10 @@ using namespace fair::mq::test;
auto RunTransferTimeout(string transport) -> void auto RunTransferTimeout(string transport) -> void
{ {
size_t session{fair::mq::tools::UuidHash()};
stringstream cmd; stringstream cmd;
cmd << runTestDevice << " --id transfer_timeout_" << transport << " --control static --verbosity DEBUG " cmd << runTestDevice << " --id transfer_timeout_" << transport << " --control static --verbosity DEBUG "
<< "--log-color false --mq-config \"" << mqConfig << "\""; << "--session " << session << " --log-color false --mq-config \"" << mqConfig << "\"";
auto res = execute(cmd.str()); auto res = execute(cmd.str());
cerr << res.error_out; cerr << res.error_out;

View File

@ -7,6 +7,7 @@
#include <fairmq/tools/Network.h> #include <fairmq/tools/Network.h>
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
#include <fairmq/tools/Version.h> #include <fairmq/tools/Version.h>
#include <fairmq/tools/Unique.h>
namespace FairMQ namespace FairMQ
{ {
@ -22,6 +23,9 @@ using fair::mq::tools::getDefaultRouteNetworkInterface;
using fair::mq::tools::S; using fair::mq::tools::S;
using fair::mq::tools::Uuid;
using fair::mq::tools::UuidHash;
using fair::mq::tools::Version; using fair::mq::tools::Version;
} // namespace tools } // namespace tools

47
fairmq/tools/Unique.h Normal file
View File

@ -0,0 +1,47 @@
/********************************************************************************
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIR_MQ_TOOLS_UNIQUE_H
#define FAIR_MQ_TOOLS_UNIQUE_H
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/functional/hash.hpp>
#include <string>
namespace fair
{
namespace mq
{
namespace tools
{
// generates UUID string
inline std::string Uuid()
{
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
return boost::uuids::to_string(u);
}
// generates UUID and returns its hash
inline std::size_t UuidHash()
{
boost::uuids::random_generator gen;
boost::hash<boost::uuids::uuid> uuid_hasher;
boost::uuids::uuid u = gen();
return uuid_hasher(u);
}
} /* namespace tools */
} /* namespace mq */
} /* namespace fair */
#endif /* FAIR_MQ_TOOLS_UNIQUE_H */