Skip to content
Snippets Groups Projects
Commit 848a9f6e authored by Steven Murray's avatar Steven Murray
Browse files

Removed unused SmartZmqContext

parent 158f0e35
No related branches found
No related tags found
No related merge requests found
......@@ -49,7 +49,6 @@ set (MEDIACHANGER_LIB_SRC_FILES
RmcProxyTcpIp.cpp
RmcUnmountMsgBody.cpp
ScsiLibrarySlot.cpp
SmartZmqContext.cpp
TapeLibraryType.cpp
ZmqContextSingleton.cpp
ZmqMsg.cpp
......
/*
* 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
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment