mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
Always have access to FairMQProgOptions from device.
This commit is contained in:
parent
7bb6a2eed9
commit
f4e5a74f23
|
@ -21,6 +21,10 @@
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp> // join/split
|
#include <boost/algorithm/string.hpp> // join/split
|
||||||
|
|
||||||
|
#include <boost/uuid/uuid.hpp>
|
||||||
|
#include <boost/uuid/uuid_generators.hpp>
|
||||||
|
#include <boost/uuid/uuid_io.hpp>
|
||||||
|
|
||||||
#include "FairMQSocket.h"
|
#include "FairMQSocket.h"
|
||||||
#include "FairMQDevice.h"
|
#include "FairMQDevice.h"
|
||||||
#include "FairMQLogger.h"
|
#include "FairMQLogger.h"
|
||||||
|
@ -68,7 +72,9 @@ FairMQDevice::FairMQDevice()
|
||||||
, fInputChannelKeys()
|
, fInputChannelKeys()
|
||||||
, fMultitransportMutex()
|
, fMultitransportMutex()
|
||||||
, fMultitransportProceed(false)
|
, fMultitransportProceed(false)
|
||||||
|
, fExternalConfig(false)
|
||||||
{
|
{
|
||||||
|
LOG(DEBUG) << "PID: " << getpid();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FairMQDevice::CatchSignals()
|
void FairMQDevice::CatchSignals()
|
||||||
|
@ -913,8 +919,38 @@ unique_ptr<FairMQTransportFactory> FairMQDevice::MakeTransport(const string& tra
|
||||||
return move(tr);
|
return move(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FairMQDevice::CreateOwnConfig()
|
||||||
|
{
|
||||||
|
// TODO: make fConfig a shared_ptr when no old user code has FairMQProgOptions ptr*
|
||||||
|
fConfig = new FairMQProgOptions();
|
||||||
|
|
||||||
|
string id{boost::uuids::to_string(boost::uuids::random_generator()())};
|
||||||
|
LOG(WARN) << "No FairMQProgOptions provided, creating one internally and setting device ID to " << id;
|
||||||
|
|
||||||
|
// dummy argc+argv
|
||||||
|
char arg0[] = "undefined"; // executable name
|
||||||
|
char arg1[] = "--id";
|
||||||
|
char* arg2 = const_cast<char*>(id.c_str()); // device ID
|
||||||
|
char* argv[] = { &arg0[0], &arg1[0], arg2, nullptr };
|
||||||
|
int argc = static_cast<int>((sizeof(argv) / sizeof(argv[0])) - 1);
|
||||||
|
|
||||||
|
fConfig->ParseAll(argc, &argv[0]);
|
||||||
|
|
||||||
|
fId = fConfig->GetValue<string>("id");
|
||||||
|
fNetworkInterface = fConfig->GetValue<string>("network-interface");
|
||||||
|
fNumIoThreads = fConfig->GetValue<int>("io-threads");
|
||||||
|
fInitializationTimeoutInS = fConfig->GetValue<int>("initialization-timeout");
|
||||||
|
}
|
||||||
|
|
||||||
void FairMQDevice::SetTransport(const string& transport)
|
void FairMQDevice::SetTransport(const string& transport)
|
||||||
{
|
{
|
||||||
|
// This method is the first to be called, if FairMQProgOptions are not used (either SetTransport() or SetConfig() make sense, not both).
|
||||||
|
// Make sure here that at least internal config is available.
|
||||||
|
if (!fExternalConfig && !fConfig)
|
||||||
|
{
|
||||||
|
CreateOwnConfig();
|
||||||
|
}
|
||||||
|
|
||||||
if (fTransports.empty())
|
if (fTransports.empty())
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "Requesting '" << transport << "' as default transport for the device";
|
LOG(DEBUG) << "Requesting '" << transport << "' as default transport for the device";
|
||||||
|
@ -929,7 +965,7 @@ void FairMQDevice::SetTransport(const string& transport)
|
||||||
|
|
||||||
void FairMQDevice::SetConfig(FairMQProgOptions& config)
|
void FairMQDevice::SetConfig(FairMQProgOptions& config)
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "PID: " << getpid();
|
fExternalConfig = true;
|
||||||
fConfig = &config;
|
fConfig = &config;
|
||||||
fChannels = config.GetFairMQMap();
|
fChannels = config.GetFairMQMap();
|
||||||
fDefaultTransport = config.GetValue<string>("transport");
|
fDefaultTransport = config.GetValue<string>("transport");
|
||||||
|
@ -1209,6 +1245,11 @@ const FairMQChannel& FairMQDevice::GetChannel(const std::string& channelName, co
|
||||||
void FairMQDevice::Exit()
|
void FairMQDevice::Exit()
|
||||||
{
|
{
|
||||||
LOG(DEBUG) << "All transports are shut down.";
|
LOG(DEBUG) << "All transports are shut down.";
|
||||||
|
|
||||||
|
if (!fExternalConfig && fConfig)
|
||||||
|
{
|
||||||
|
delete fConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FairMQDevice::~FairMQDevice()
|
FairMQDevice::~FairMQDevice()
|
||||||
|
|
|
@ -472,6 +472,8 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
|
||||||
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i) const;
|
bool HandleMsgInput(const std::string& chName, const InputMsgCallback& callback, int i) const;
|
||||||
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i) const;
|
bool HandleMultipartInput(const std::string& chName, const InputMultipartCallback& callback, int i) const;
|
||||||
|
|
||||||
|
void CreateOwnConfig();
|
||||||
|
|
||||||
/// Signal handler
|
/// Signal handler
|
||||||
void SignalHandler(int signal);
|
void SignalHandler(int signal);
|
||||||
bool fCatchingSignals;
|
bool fCatchingSignals;
|
||||||
|
@ -486,6 +488,8 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
|
||||||
std::vector<std::string> fInputChannelKeys;
|
std::vector<std::string> fInputChannelKeys;
|
||||||
std::mutex fMultitransportMutex;
|
std::mutex fMultitransportMutex;
|
||||||
std::atomic<bool> fMultitransportProceed;
|
std::atomic<bool> fMultitransportProceed;
|
||||||
|
|
||||||
|
bool fExternalConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAIRMQDEVICE_H_ */
|
#endif /* FAIRMQDEVICE_H_ */
|
||||||
|
|
|
@ -110,14 +110,12 @@ void FairMQProgOptions::ParseAll(const int argc, char** argv, bool allowUnregist
|
||||||
|
|
||||||
if (!optionExists)
|
if (!optionExists)
|
||||||
{
|
{
|
||||||
LOG(WARN) << "Options to configure FairMQ channels are not provided.";
|
LOG(WARN) << "FairMQProgOptions: no channels configuration provided via neither of:";
|
||||||
LOG(WARN) << "Please provide the value for one of the following keys:";
|
|
||||||
for (const auto& p : MQParserKeys)
|
for (const auto& p : MQParserKeys)
|
||||||
{
|
{
|
||||||
LOG(WARN) << p;
|
LOG(WARN) << " --" << p;
|
||||||
}
|
}
|
||||||
LOG(WARN) << "No channels will be created (You can create them manually).";
|
LOG(WARN) << "No channels will be created (You can create them manually).";
|
||||||
// return 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user