diff --git a/mediachanger/CMakeLists.txt b/mediachanger/CMakeLists.txt index 4059ee0ff56db329d21cf51a8ada6769db27d909..80f8edbb08af4869377d91ff5746da5170e1e8fc 100644 --- a/mediachanger/CMakeLists.txt +++ b/mediachanger/CMakeLists.txt @@ -49,7 +49,6 @@ set (MEDIACHANGER_LIB_SRC_FILES RmcProxyTcpIp.cpp RmcUnmountMsgBody.cpp ScsiLibrarySlot.cpp - SmartZmqContext.cpp TapeLibraryType.cpp ZmqContextSingleton.cpp ZmqMsg.cpp diff --git a/mediachanger/SmartZmqContext.cpp b/mediachanger/SmartZmqContext.cpp deleted file mode 100644 index 3a011a44bc5a452606a1ce52f30f3cf522b11651..0000000000000000000000000000000000000000 --- a/mediachanger/SmartZmqContext.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 CERN - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - *(at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "mediachanger/SmartZmqContext.hpp" -#include "common/utils/utils.hpp" - -#include <errno.h> -#include <unistd.h> -#include <zmq.h> - -namespace cta { -namespace mediachanger { - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -SmartZmqContext::SmartZmqContext() throw() : - m_zmqContext(NULL) { -} - -//----------------------------------------------------------------------------- -// constructor -//----------------------------------------------------------------------------- -SmartZmqContext::SmartZmqContext(void *const zmqContext) - throw() : m_zmqContext(zmqContext) { -} - -//----------------------------------------------------------------------------- -// reset -//----------------------------------------------------------------------------- -void SmartZmqContext::reset(void *const zmqContext) - throw() { - // If the new ZMQ context is not the one already owned - if(zmqContext != m_zmqContext) { - - // If this smart pointer still owns a ZMQ context, then terminate it - if(m_zmqContext != NULL) { - zmq_term(m_zmqContext); - } - - // Take ownership of the new ZMQ context - m_zmqContext = zmqContext; - } -} - -//----------------------------------------------------------------------------- -// SmartZmqContext assignment operator -//----------------------------------------------------------------------------- -SmartZmqContext - &SmartZmqContext::operator=(SmartZmqContext& obj) { - reset(obj.release()); - return *this; -} - -//----------------------------------------------------------------------------- -// destructor -//----------------------------------------------------------------------------- -SmartZmqContext::~SmartZmqContext() throw() { - // ZMQ sends an abort on exit when cleaned up this way under some - // circumstances, so we purposely do not clean up the context (zmq_term) and - // leave a resource leak, which in our use case is one-off situation - // per process, and it gets cleaned up on process termination, which happens - // very soon after this destructor being called. - //reset(); -} - -//----------------------------------------------------------------------------- -// get -//----------------------------------------------------------------------------- -void *SmartZmqContext::get() const throw() { - return m_zmqContext; -} - -//----------------------------------------------------------------------------- -// release -//----------------------------------------------------------------------------- -void *SmartZmqContext::release() { - // If this smart pointer does not own a ZMQ context - if(NULL == m_zmqContext) { - cta::exception::NotAnOwner ex; - ex.getMessage() << "Smart pointer does not own a ZMQ context"; - throw ex; - } - - void *const tmp = m_zmqContext; - - // A NULL value indicates this smart pointer does not own a ZMQ context - m_zmqContext = NULL; - - 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 deleted file mode 100644 index ad7491b8afcdfdff1fea38f05109d70fb385befb..0000000000000000000000000000000000000000 --- a/mediachanger/SmartZmqContext.hpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * The CERN Tape Archive(CTA) project - * Copyright(C) 2015 CERN - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - *(at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once - -#include "common/exception/NotAnOwner.hpp" - -#include <stdio.h> - - -namespace cta { -namespace mediachanger { - -/** - * A smart pointer that owns a ZMQ context. If the smart pointer goes out of - * scope and it owns a ZMQ context, then it will terminate that context by - * calling zmq_term(). - */ -class SmartZmqContext { - -public: - - /** - * Constructor. - */ - SmartZmqContext() throw(); - - /** - * Constructor. - * - * @param zmqContext The ZMQ context to be owned by the smart pointer. - */ - SmartZmqContext(void *const zmqContext) throw(); - - /** - * Take ownership of the specified ZMQ context, terminating the previously - * owned ZMQ context if there is one and it is not the same as the one - * specified. - * - * @param zmqContext The ZMQ context to be owned, defaults to NULL if not - * specified, where NULL means this smart pointer will not own a ZMQ context - * after the reset() method returns. - */ - void reset(void *const zmqContext = NULL) throw(); - - /** - * SmartZmqContext assignment operator. - * - * This function does the following: - * <ul> - * <li> Calls release on the previous owner (obj); - * <li> Terminates the ZMQ context of this object if it already owns one. - * <li> Makes this object the owner of the ZMQ context released from the - * previous owner (obj). - * </ul> - */ - SmartZmqContext &operator=(SmartZmqContext& obj); - - /** - * Destructor. - * - * If the smart pointer owns a ZMQ context, then the destructor will - * terminate it by calling zmq_term(). - */ - ~SmartZmqContext() throw(); - - /** - * Returns the owned ZMQ context or NULL if this smart pointer does not own - * one. - * - * @return The owned ZMQ context or NULL. - */ - void *get() const throw(); - - /** - * Releases the owned ZMQ context. - * - * @return The released ZMQ context. - */ - 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: - - /** - * The owned ZMQ context. A value of NULL means this smart pointer does not - * own a ZMQ context. - */ - void *m_zmqContext; - - /** - * Private copy-constructor to prevent users from trying to create a new - * copy of an object of this class. - * - * Not implemented so that it cannot be called. - */ - SmartZmqContext(const SmartZmqContext &obj) throw(); - -}; // class SmartZmqContext - -} // namespace mediachanger -} // namespace cta -