diff --git a/mediachanger/DismountCmdMain.cpp b/mediachanger/DismountCmdMain.cpp index 42e17fc9be855eed623cc4905f3c87de3fa5172a..643077eb44ff096d5817342fb00b928b7512c557 100644 --- a/mediachanger/DismountCmdMain.cpp +++ b/mediachanger/DismountCmdMain.cpp @@ -39,15 +39,6 @@ */ static int exceptionThrowingMain(const int argc, char *const *const argv); -/** - * Instantiates a ZMQ context. - * - * @param sizeOfIOThreadPoolForZMQ The size of the thread pool used to perform - * IO. This is usually 1 thread. - * @return A pointer to the newly created ZMQ context. - */ -static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ); - //------------------------------------------------------------------------------ // main //------------------------------------------------------------------------------ @@ -76,7 +67,6 @@ int main(const int argc, char *const *const argv) { return 1; } - //------------------------------------------------------------------------------ // exceptionThrowingMain //------------------------------------------------------------------------------ @@ -84,8 +74,8 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) { using namespace cta; const int sizeOfIOThreadPoolForZMQ = 1; - mediachanger::SmartZmqContext zmqContext(instantiateZmqContext( - sizeOfIOThreadPoolForZMQ)); + mediachanger::SmartZmqContext + zmqContext(mediachanger::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ)); mediachanger::AcsProxyZmq acs(mediachanger::ACS_PORT, zmqContext.get()); mediachanger::MmcProxyNotSupported mmc; @@ -106,18 +96,3 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) { return cmd.exceptionThrowingMain(argc, argv); } - -//------------------------------------------------------------------------------ -// instantiateZmqContext -//------------------------------------------------------------------------------ -static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ) { - using namespace cta; - void *const zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ); - if(NULL == zmqContext) { - const std::string message = utils::errnoToString(errno); - cta::exception::Exception ex; - ex.getMessage() << "Failed to instantiate ZMQ context: " << message; - throw ex; - } - return zmqContext; -} diff --git a/mediachanger/MountCmdMain.cpp b/mediachanger/MountCmdMain.cpp index 06144c686bdc1def5839a53b9a0af5929c88b250..27a51b391ce71c9d7a6571b298aa5c1ad0ca1884 100644 --- a/mediachanger/MountCmdMain.cpp +++ b/mediachanger/MountCmdMain.cpp @@ -39,15 +39,6 @@ */ static int exceptionThrowingMain(const int argc, char *const *const argv); -/** - * Instantiates a ZMQ context. - * - * @param sizeOfIOThreadPoolForZMQ The size of the thread pool used to perform - * IO. This is usually 1 thread. - * @return A pointer to the newly created ZMQ context. - */ -static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ); - //------------------------------------------------------------------------------ // main //------------------------------------------------------------------------------ @@ -82,7 +73,8 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) { using namespace cta; const int sizeOfIOThreadPoolForZMQ = 1; - mediachanger::SmartZmqContext zmqContext(instantiateZmqContext(sizeOfIOThreadPoolForZMQ)); + mediachanger::SmartZmqContext + zmqContext(mediachanger::SmartZmqContext::instantiateZmqContext(sizeOfIOThreadPoolForZMQ)); mediachanger::AcsProxyZmq acs(mediachanger::ACS_PORT, zmqContext.get()); mediachanger::MmcProxyNotSupported mmc; @@ -103,18 +95,3 @@ static int exceptionThrowingMain(const int argc, char *const *const argv) { return cmd.exceptionThrowingMain(argc, argv); } - -//------------------------------------------------------------------------------ -// instantiateZmqContext -//------------------------------------------------------------------------------ -static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ) { - using namespace cta; - void *const zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ); - if(NULL == zmqContext) { - const std::string message = utils::errnoToString(errno); - cta::exception::Exception ex; - ex.getMessage() << "Failed to instantiate ZMQ context: " << message; - throw ex; - } - return zmqContext; -} diff --git a/mediachanger/SmartZmqContext.cpp b/mediachanger/SmartZmqContext.cpp index ea2582e5123dade15605e31a0fbeb5f9eceb697a..3a011a44bc5a452606a1ce52f30f3cf522b11651 100644 --- a/mediachanger/SmartZmqContext.cpp +++ b/mediachanger/SmartZmqContext.cpp @@ -17,6 +17,7 @@ */ #include "mediachanger/SmartZmqContext.hpp" +#include "common/utils/utils.hpp" #include <errno.h> #include <unistd.h> @@ -104,5 +105,18 @@ void *SmartZmqContext::release() { return tmp; } +//------------------------------------------------------------------------------ +// instantiateZmqContext +//------------------------------------------------------------------------------ +void *SmartZmqContext::instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ) { + using namespace cta; + void *const zmqContext = zmq_init(sizeOfIOThreadPoolForZMQ); + if(NULL == zmqContext) { + const std::string message = utils::errnoToString(errno); + throw exception::Exception(std::string(__FUNCTION__) + ": Failed to instantiate ZMQ context: " + message); + } + return zmqContext; +} + } // namespace mediachanger } // namespace cta diff --git a/mediachanger/SmartZmqContext.hpp b/mediachanger/SmartZmqContext.hpp index 52f3812586742d3a9d0594db2900abd7e91b560e..ad7491b8afcdfdff1fea38f05109d70fb385befb 100644 --- a/mediachanger/SmartZmqContext.hpp +++ b/mediachanger/SmartZmqContext.hpp @@ -94,6 +94,15 @@ public: */ void *release() ; + /** + * Instantiates a ZMQ context. + * + * @param sizeOfIOThreadPoolForZMQ The size of the thread pool used to perform + * IO. This is usually 1 thread. + * @return A pointer to the newly created ZMQ context. + */ + static void *instantiateZmqContext(const int sizeOfIOThreadPoolForZMQ); + private: /**