move TransportFactory factory into FairMQTransportFactory namespace

This commit is contained in:
Dennis Klein 2017-05-17 16:08:45 +02:00 committed by Mohammad Al-Turany
parent f522dc1717
commit 97ca52aa0e
5 changed files with 64 additions and 66 deletions

View File

@ -874,33 +874,7 @@ shared_ptr<FairMQTransportFactory> FairMQDevice::AddTransport(const string& tran
if (i == fTransports.end())
{
shared_ptr<FairMQTransportFactory> tr;
if (transport == "zeromq")
{
tr = make_shared<FairMQTransportFactoryZMQ>();
}
else if (transport == "shmem")
{
tr = make_shared<FairMQTransportFactorySHM>();
}
#ifdef NANOMSG_FOUND
else if (transport == "nanomsg")
{
tr = make_shared<FairMQTransportFactoryNN>();
}
#endif
else
{
LOG(ERROR) << "Unavailable transport requested: " << "\"" << transport << "\"" << ". Available are: "
<< "\"zeromq\""
<< "\"shmem\""
#ifdef NANOMSG_FOUND
<< ", \"nanomsg\""
#endif
<< ". Exiting.";
exit(EXIT_FAILURE);
}
auto tr = FairMQTransportFactory::CreateTransportFactory(transport);
LOG(DEBUG) << "Adding '" << transport << "' transport to the device.";

View File

@ -1,20 +1,24 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2012-2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQDevice.h
*
* @since 2012-10-25
* @author D. Klein, A. Rybalchenko
*/
#ifndef FAIRMQDEVICE_H_
#define FAIRMQDEVICE_H_
#include "FairMQConfigurable.h"
#include "FairMQStateMachine.h"
#include "FairMQTransportFactory.h"
#include "FairMQTransports.h"
#include "FairMQSocket.h"
#include "FairMQChannel.h"
#include "FairMQMessage.h"
#include "FairMQParts.h"
#include <vector>
#include <memory> // unique_ptr
#include <algorithm> // std::sort()
@ -28,16 +32,6 @@
#include <mutex>
#include <condition_variable>
#include "FairMQConfigurable.h"
#include "FairMQStateMachine.h"
#include "FairMQTransportFactory.h"
#include "FairMQTransports.h"
#include "FairMQSocket.h"
#include "FairMQChannel.h"
#include "FairMQMessage.h"
#include "FairMQParts.h"
typedef std::unordered_map<std::string, std::vector<FairMQChannel>> FairMQChannelMap;
typedef std::function<bool(FairMQMessagePtr&, int)> InputMsgCallback;
@ -321,7 +315,7 @@ class FairMQDevice : public FairMQStateMachine, public FairMQConfigurable
/// Get property description for a given property name
/// @param key Property name/key
/// @return String with the property description
/// @return String with the property description
virtual std::string GetPropertyDescription(const int key);
/// Print all properties of this and the parent class to LOG(INFO)
virtual void ListProperties();

View File

@ -1,13 +1,45 @@
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence version 3 (LGPL) version 3, *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
/**
* FairMQTransportFactory.cxx
*
* @since 2014-01-20
* @author: A. Rybalchenko
*/
#include <FairMQTransportFactory.h>
#include <zeromq/FairMQTransportFactoryZMQ.h>
#include <shmem/FairMQTransportFactorySHM.h>
#ifdef NANOMSG_FOUND
#include <nanomsg/FairMQTransportFactoryNN.h>
#endif /* NANOMSG_FOUND */
#include <FairMQLogger.h>
#include <memory>
auto FairMQTransportFactory::CreateTransportFactory(const std::string& type) -> std::shared_ptr<FairMQTransportFactory>
{
if (type == "zeromq")
{
return std::make_shared<FairMQTransportFactoryZMQ>();
}
else if (type == "shmem")
{
return std::make_shared<FairMQTransportFactorySHM>();
}
#ifdef NANOMSG_FOUND
else if (type == "nanomsg")
{
return std::make_shared<FairMQTransportFactoryNN>();
}
#endif /* NANOMSG_FOUND */
else
{
LOG(ERROR) << "Unavailable transport requested: " << "\"" << type << "\"" << ". Available are: "
<< "\"zeromq\""
<< "\"shmem\""
#ifdef NANOMSG_FOUND
<< ", \"nanomsg\""
#endif /* NANOMSG_FOUND */
<< ". Exiting.";
exit(EXIT_FAILURE);
}
}

View File

@ -61,6 +61,8 @@ class FairMQTransportFactory
virtual void Terminate() = 0;
virtual ~FairMQTransportFactory() {};
static auto CreateTransportFactory(const std::string& type) -> std::shared_ptr<FairMQTransportFactory>;
};
#endif /* FAIRMQTRANSPORTFACTORY_H_ */

View File

@ -13,6 +13,7 @@
#include <string>
#include <sstream>
#include <algorithm>
#include <memory>
namespace
{
@ -22,7 +23,7 @@ using namespace std;
class RandomAccessIterator : public ::testing::Test {
protected:
FairMQParts mParts;
FairMQTransportFactoryZMQ mFactory;
shared_ptr<FairMQTransportFactory> mFactory;
const string mS1, mS2, mS3;
RandomAccessIterator()
@ -32,13 +33,9 @@ class RandomAccessIterator : public ::testing::Test {
mS2("2"),
mS3("3")
{
mParts.AddPart(mFactory.CreateMessage(const_cast<char*>(mS1.c_str()),
mS1.length(), FairMQDevice::FairMQSimpleMsgCleanup<string>));
mParts.AddPart(mFactory.CreateMessage(const_cast<char*>(mS2.c_str()),
mS2.length(), FairMQDevice::FairMQSimpleMsgCleanup<string>));
mParts.AddPart(mFactory.CreateMessage(const_cast<char*>(mS3.c_str()),
mS3.length(), FairMQDevice::FairMQSimpleMsgCleanup<string>));
mParts.AddPart(mFactory->NewSimpleMessage(mS1));
mParts.AddPart(mFactory->NewSimpleMessage(mS2));
mParts.AddPart(mFactory->NewSimpleMessage(mS3));
}
};
@ -57,8 +54,7 @@ TEST_F(RandomAccessIterator, RangeForLoopMutation)
auto s = string{"4"};
for (auto&& part : mParts) {
part = mFactory.CreateMessage(const_cast<char*>(s.c_str()),
s.length(), FairMQDevice::FairMQSimpleMsgCleanup<string>);
part = mFactory->NewSimpleMessage(s);
}
stringstream out;