diff --git a/fairmq/FairMQDevice.cxx b/fairmq/FairMQDevice.cxx index 725309c6..d2d91100 100644 --- a/fairmq/FairMQDevice.cxx +++ b/fairmq/FairMQDevice.cxx @@ -874,33 +874,7 @@ shared_ptr FairMQDevice::AddTransport(const string& tran if (i == fTransports.end()) { - shared_ptr tr; - - if (transport == "zeromq") - { - tr = make_shared(); - } - else if (transport == "shmem") - { - tr = make_shared(); - } -#ifdef NANOMSG_FOUND - else if (transport == "nanomsg") - { - tr = make_shared(); - } -#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."; diff --git a/fairmq/FairMQDevice.h b/fairmq/FairMQDevice.h index fb5e891e..ca9443d3 100644 --- a/fairmq/FairMQDevice.h +++ b/fairmq/FairMQDevice.h @@ -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 #include // unique_ptr #include // std::sort() @@ -28,16 +32,6 @@ #include #include -#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> FairMQChannelMap; typedef std::function 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(); diff --git a/fairmq/FairMQTransportFactory.cxx b/fairmq/FairMQTransportFactory.cxx index 558a2e0e..aff14a79 100644 --- a/fairmq/FairMQTransportFactory.cxx +++ b/fairmq/FairMQTransportFactory.cxx @@ -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 +#include +#include +#ifdef NANOMSG_FOUND +#include +#endif /* NANOMSG_FOUND */ +#include +#include + +auto FairMQTransportFactory::CreateTransportFactory(const std::string& type) -> std::shared_ptr +{ + if (type == "zeromq") + { + return std::make_shared(); + } + else if (type == "shmem") + { + return std::make_shared(); + } +#ifdef NANOMSG_FOUND + else if (type == "nanomsg") + { + return std::make_shared(); + } +#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); + } +} diff --git a/fairmq/FairMQTransportFactory.h b/fairmq/FairMQTransportFactory.h index fdd72dc1..bf8a9ad0 100644 --- a/fairmq/FairMQTransportFactory.h +++ b/fairmq/FairMQTransportFactory.h @@ -61,6 +61,8 @@ class FairMQTransportFactory virtual void Terminate() = 0; virtual ~FairMQTransportFactory() {}; + + static auto CreateTransportFactory(const std::string& type) -> std::shared_ptr; }; #endif /* FAIRMQTRANSPORTFACTORY_H_ */ diff --git a/fairmq/test/parts/_iterator_interface.cxx b/fairmq/test/parts/_iterator_interface.cxx index 28e2845d..387ccf28 100644 --- a/fairmq/test/parts/_iterator_interface.cxx +++ b/fairmq/test/parts/_iterator_interface.cxx @@ -13,6 +13,7 @@ #include #include #include +#include namespace { @@ -22,7 +23,7 @@ using namespace std; class RandomAccessIterator : public ::testing::Test { protected: FairMQParts mParts; - FairMQTransportFactoryZMQ mFactory; + shared_ptr 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(mS1.c_str()), - mS1.length(), FairMQDevice::FairMQSimpleMsgCleanup)); - mParts.AddPart(mFactory.CreateMessage(const_cast(mS2.c_str()), - mS2.length(), FairMQDevice::FairMQSimpleMsgCleanup)); - mParts.AddPart(mFactory.CreateMessage(const_cast(mS3.c_str()), - mS3.length(), FairMQDevice::FairMQSimpleMsgCleanup)); + 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(s.c_str()), - s.length(), FairMQDevice::FairMQSimpleMsgCleanup); + part = mFactory->NewSimpleMessage(s); } stringstream out;