Commit c58a8a1f authored by Steven Murray's avatar Steven Murray
Browse files

ZmqContextSingleton::instance() is now called on demand.

The ZmqContextSingleton::instance() method was being called
prematurely.  This led to unit tests that don't actually
communicate over zero mq having "still reachable" memory
leak when executed in valgrind.
parent 53db77b7
......@@ -25,6 +25,7 @@
#include "mediachanger/Constants.hpp"
#include "mediachanger/MediaChangerReturnValue.pb.h"
#include "mediachanger/messages.hpp"
#include "mediachanger/ZmqContextSingleton.hpp"
namespace cta {
namespace mediachanger {
......@@ -168,8 +169,7 @@ Frame createAcsForceDismountTapeFrame(const std::string &vid, const AcsLibrarySl
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
AcsProxy::AcsProxy(void *const zmqContext, const unsigned short serverPort) throw():
m_zmqContext(zmqContext),
AcsProxy::AcsProxy(const unsigned short serverPort) throw():
m_serverPort(serverPort) {
}
......@@ -290,7 +290,7 @@ void AcsProxy::forceDismountTape(const std::string &vid, const LibrarySlot &libr
//------------------------------------------------------------------------------
ZmqSocket &AcsProxy::serverSocketInstance() {
if(nullptr == m_serverSocket) {
m_serverSocket.reset(new ZmqSocket(m_zmqContext, ZMQ_REQ));
m_serverSocket.reset(new ZmqSocket(ZmqContextSingleton::instance(), ZMQ_REQ));
connectZmqSocketToLocalhost(*m_serverSocket, m_serverPort);
}
return *m_serverSocket;
......
......@@ -37,11 +37,10 @@ public:
/**
* Constructor.
*
* @param zmqContext The ZMQ context.
* @param serverPort The TCP/IP port on which the CASTOR ACS daemon is
* listening for ZMQ messages.
*/
AcsProxy(void *const zmqContext, const unsigned short serverPort = ACS_PORT) throw();
AcsProxy(const unsigned short serverPort = ACS_PORT) throw();
/**
* Request the CASTOR ACS daemon to mount the specified tape for read-only
......@@ -82,11 +81,6 @@ public:
private:
/**
* The ZMQ context.
*/
void *m_zmqContext;
/**
* Mutex used to implement a critical section around the enclosed
* ZMQ socket.
......
......@@ -25,9 +25,7 @@ namespace mediachanger {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
MediaChangerFacade::MediaChangerFacade(log::Logger &log, void *const zmqContext) throw():
m_zmqContext(zmqContext),
m_acsProxy(zmqContext),
MediaChangerFacade::MediaChangerFacade(log::Logger &log) throw():
m_mmcProxy(log) {
}
......
......@@ -24,7 +24,6 @@
#include "mediachanger/MediaChangerProxy.hpp"
#include "mediachanger/MmcProxy.hpp"
#include "mediachanger/RmcProxy.hpp"
#include "mediachanger/ZmqContextSingleton.hpp"
#include <memory>
#include <string>
......@@ -44,12 +43,8 @@ public:
* @param log Object representing the API to the CTA logging system. This log
* object will be used by the manual media changer to communicate with the
* tape operator.
* @param zmqContext The ZMQ context. There is usually one ZMQ context within
* a program. Set this parameter in order for the MediaChangerFacade to share
* an already existing ZMQ context. If this parameter is not set then the
* ZmqContextSingleton of the mediachanger namespace will be used.
*/
MediaChangerFacade(log::Logger &log, void *const zmqContext = ZmqContextSingleton::instance()) throw();
MediaChangerFacade(log::Logger &log) throw();
/**
* Requests the media changer to mount the specified tape for read-only
......@@ -96,11 +91,6 @@ public:
private:
/**
* The ZMQ context.
*/
void *m_zmqContext;
/**
* ACS media changer proxy.
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment