Commit 446d6ddc authored by Victor Kotlyar's avatar Victor Kotlyar
Browse files

Removed unsed and duplicate files

parent e041183f
......@@ -27,7 +27,7 @@
#include "castor/messages/AcsProxyZmq.hpp"
#include "castor/messages/Constants.hpp"
#include "castor/messages/messages.hpp"
#include "castor/messages/MutexLocker.hpp"
#include "common/threading/MutexLocker.hpp"
//------------------------------------------------------------------------------
// constructor
......@@ -44,7 +44,7 @@ castor::messages::AcsProxyZmq::AcsProxyZmq(const unsigned short serverPort,
//------------------------------------------------------------------------------
void castor::messages::AcsProxyZmq::mountTapeReadOnly(const std::string &vid,
const mediachanger::AcsLibrarySlot &librarySlot) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createAcsMountTapeReadOnlyFrame(vid, librarySlot);
......@@ -104,7 +104,7 @@ castor::messages::Frame castor::messages::AcsProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::AcsProxyZmq::mountTapeReadWrite(const std::string &vid,
const mediachanger::AcsLibrarySlot &librarySlot) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createAcsMountTapeReadWriteFrame(vid, librarySlot);
......@@ -164,7 +164,7 @@ castor::messages::Frame castor::messages::AcsProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::AcsProxyZmq::dismountTape(const std::string &vid,
const mediachanger::AcsLibrarySlot &librarySlot) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createAcsDismountTapeFrame(vid, librarySlot);
......@@ -224,7 +224,7 @@ castor::messages::Frame castor::messages::AcsProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::AcsProxyZmq::forceDismountTape(const std::string &vid,
const mediachanger::AcsLibrarySlot &librarySlot) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createAcsForceDismountTapeFrame(vid, librarySlot);
......
......@@ -23,7 +23,7 @@
#include "AcsProxy.hpp"
#include "Frame.hpp"
#include "Mutex.hpp"
#include "common/threading/Mutex.hpp"
#include "ZmqSocketMT.hpp"
namespace castor {
......@@ -91,7 +91,7 @@ private:
* Mutex used to implement a critical section around the enclosed
* ZMQ socket.
*/
Mutex m_mutex;
cta::threading::Mutex m_mutex;
/**
* The TCP/IP port on which the CASTOR ACS daemon is listening for ZMQ
......
......@@ -41,7 +41,6 @@ set(CtaMessageSrcs
Constants.cpp
Frame.cpp
messages.cpp
Mutex.cpp
SmartZmqContext.cpp
../../../tapeserver/daemon/TapedProxy.cpp
TapeserverProxyZmq.cpp
......@@ -67,9 +66,7 @@ target_link_libraries(ctamessages
zmq)
add_library(ctamessagesunittests SHARED
MessagesTest.cpp
MutexLockerTest.cpp
MutexTest.cpp)
MessagesTest.cpp)
install(TARGETS ctamessagesunittests DESTINATION usr/${CMAKE_INSTALL_LIBDIR})
add_dependencies(ctamessagesunittests ctamessagesprotobuf)
// This file is part of the Castor project.
// See http://castor.web.cern.ch/castor
//
// Copyright (C) 2003 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// @author Castor Dev team, castor-dev@cern.ch
package castor.messages;
message MigrationJobFromTapeGateway {
required string vid = 1;
required string unitname = 2;
}
// This file is part of the Castor project.
// See http://castor.web.cern.ch/castor
//
// Copyright (C) 2003 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// @author Castor Dev team, castor-dev@cern.ch
package castor.messages;
message MigrationJobFromWriteTp {
required string vid = 1;
required string unitname = 2;
}
#include "castor/messages/Mutex.hpp"
#include "common/exception/Errnum.hpp"
#include "common/exception/Exception.hpp"
//------------------------------------------------------------------------------
//constructor
//------------------------------------------------------------------------------
castor::messages::Mutex::Mutex() {
pthread_mutexattr_t attr;
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutexattr_init(&attr),
"Error from pthread_mutexattr_init in castor::messages::Mutex::Mutex()");
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK),
"Error from pthread_mutexattr_settype in castor::messages::Mutex::Mutex()");
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutex_init(&m_mutex, &attr),
"Error from pthread_mutex_init in castor::messages::Mutex::Mutex()");
try {
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutexattr_destroy(&attr),
"Error from pthread_mutexattr_destroy in"
" castor::messages::Mutex::Mutex()");
} catch (...) {
pthread_mutex_destroy(&m_mutex);
throw;
}
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
castor::messages::Mutex::~Mutex() throw() {
pthread_mutex_destroy(&m_mutex);
}
//------------------------------------------------------------------------------
// lock
//------------------------------------------------------------------------------
void castor::messages::Mutex::lock() {
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutex_lock(&m_mutex),
"Error from pthread_mutex_lock in castor::messages::Mutex::lock()");
}
//------------------------------------------------------------------------------
// unlock
//------------------------------------------------------------------------------
void castor::messages::Mutex::unlock() {
cta::exception::Errnum::throwOnReturnedErrno(
pthread_mutex_unlock(&m_mutex),
"Error from pthread_mutex_unlock in castor::messages::Mutex::unlock()");
}
/******************************************************************************
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include <pthread.h>
namespace castor {
namespace messages {
/**
* A simple exception throwing wrapper for pthread mutexes.
* Inspired from the interface of Qt.
*/
class Mutex {
public:
/**
* Constructor.
*/
Mutex();
/**
* Destructor.
*/
~Mutex() throw();
/**
* Takes a lock on the mutex.
*/
void lock();
/**
* Releases the current lock on the mutex.
*/
void unlock();
private:
/**
* The pthread mutex.
*/
pthread_mutex_t m_mutex;
};
} // namespace messages
} // namespace castor
/******************************************************************************
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/messages/Mutex.hpp"
#include <pthread.h>
#include <semaphore.h>
namespace castor {
namespace messages {
/**
* A simple scoped locker for mutexes. Highly recommended as
* the mutex will be released in all cases (exception, mid-code return, etc...)
* To use, simply instantiate and forget.
*/
class MutexLocker {
public:
/**
* Constructor.
*
* @param m pointer to Mutex to be owned.
*/
MutexLocker(Mutex *const m): m_mutex(m) {
m->lock();
}
/**
* Destructor.
*/
~MutexLocker() throw() {
try {
m_mutex->unlock();
} catch (...) {
// Ignore any exceptions
}
}
private:
/**
* The mutex owened by this MutexLocker.
*/
Mutex *const m_mutex;
}; // class MutexLocker
} // namespace messages
} // namespace castor
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "common/exception/Errnum.hpp"
#include "castor/messages/MutexLocker.hpp"
#include <gtest/gtest.h>
namespace unitTests {
class castor_messages_MutexLockerTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST(castor_messages_MutexLockerTest,
MutexLocker_locks_and_properly_throws_exceptions) {
using namespace castor::messages;
Mutex m;
{
MutexLocker ml(&m);
// This is a different flavour of duplicate locking
ASSERT_THROW(m.lock(),cta::exception::Errnum);
ASSERT_NO_THROW(m.unlock());
ASSERT_NO_THROW(m.lock());
}
// As the locker has been destroyed, and the mutex released, another
// lock/unlock should be possible
ASSERT_NO_THROW(m.lock());
ASSERT_NO_THROW(m.unlock());
}
} // namespace unitTests
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "common/exception/Errnum.hpp"
#include "castor/messages/Mutex.hpp"
#include <gtest/gtest.h>
namespace unitTests {
class castor_messages_MutexTest : public ::testing::Test {
protected:
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST(castor_messages_MutexTest, Mutex_properly_throws_exceptions) {
using namespace castor::messages;
// Check that we properly get exception when doing wrong semaphore operations
Mutex m;
ASSERT_NO_THROW(m.lock());
// Duplicate lock
ASSERT_THROW(m.lock(),cta::exception::Errnum);
ASSERT_NO_THROW(m.unlock());
// Duplicate release
ASSERT_THROW(m.unlock(),cta::exception::Errnum);
}
} // namespace unitTests
// This file is part of the Castor project.
// See http://castor.web.cern.ch/castor
//
// Copyright (C) 2003 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// @author Castor Dev team, castor-dev@cern.ch
package castor.messages;
message RecallJob {
required string vid = 1;
required string unitname = 2;
enum ClientType {
CLIENT_TYPE_GATEWAY = 1;
CLIENT_TYPE_READTP = 2;
}
required ClientType clienttype = 3;
}
// This file is part of the Castor project.
// See http://castor.web.cern.ch/castor
//
// Copyright (C) 2003 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// @author Castor Dev team, castor-dev@cern.ch
package castor.messages;
message RecallJobFromReadTp {
required string vid = 1;
required string unitname = 2;
}
// This file is part of the Castor project.
// See http://castor.web.cern.ch/castor
//
// Copyright (C) 2003 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 2
// 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, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// @author Castor Dev team, castor-dev@cern.ch
package castor.messages;
message RecallJobFromTapeGateway {
required string vid = 1;
required string unitname = 2;
}
......@@ -23,16 +23,12 @@
#include "castor/messages/ArchiveJobFromCTA.pb.h"
#include "castor/messages/Constants.hpp"
#include "castor/messages/DeleteLogParams.pb.h"
#include "castor/messages/MutexLocker.hpp"
#include "common/threading/MutexLocker.hpp"
#include "castor/messages/Header.pb.h"
#include "castor/messages/Heartbeat.pb.h"
#include "castor/messages/LabelError.pb.h"
#include "castor/messages/messages.hpp"
#include "castor/messages/MigrationJobFromTapeGateway.pb.h"
#include "castor/messages/MigrationJobFromWriteTp.pb.h"
#include "castor/messages/NbFilesOnTape.pb.h"
#include "castor/messages/RecallJobFromReadTp.pb.h"
#include "castor/messages/RecallJobFromTapeGateway.pb.h"
#include "castor/messages/RetrieveJobFromCTA.pb.h"
#include "castor/messages/ReturnValue.pb.h"
#include "castor/messages/TapeMountedForRecall.pb.h"
......@@ -97,7 +93,7 @@ void castor::messages::TapeserverProxyZmq::reportHeartbeat(uint64_t totalTapeByt
//------------------------------------------------------------------------------
uint32_t castor::messages::TapeserverProxyZmq::gotArchiveJobFromCTA(
const std::string &vid, const std::string &unitName, const uint32_t nbFiles) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createArchiveJobFromCTAFrame(vid, unitName, nbFiles);
......@@ -121,7 +117,7 @@ uint32_t castor::messages::TapeserverProxyZmq::gotArchiveJobFromCTA(
//------------------------------------------------------------------------------
void castor::messages::TapeserverProxyZmq::gotRetrieveJobFromCTA(
const std::string &vid, const std::string &unitName) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createRetrieveJobFromCTAFrame(vid, unitName);
......@@ -206,7 +202,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::TapeserverProxyZmq::tapeMountedForRecall(
const std::string &vid, const std::string &unitName) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createTapeMountedForRecallFrame(vid, unitName);
......@@ -263,7 +259,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::TapeserverProxyZmq::tapeMountedForMigration(
const std::string &vid, const std::string &unitName) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createTapeMountedForMigrationFrame(vid, unitName);
......@@ -320,7 +316,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
//-----------------------------------------------------------------------------
void castor::messages::TapeserverProxyZmq::notifyHeartbeat(
const std::string &unitName, const uint64_t nbBlocksMoved) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createHeartbeatFrame(unitName, nbBlocksMoved);
......@@ -378,7 +374,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
void castor::messages::TapeserverProxyZmq::addLogParams(
const std::string &unitName,
const std::list<cta::log::Param> & params) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createAddLogParamsFrame(unitName, params);
......@@ -441,7 +437,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
void castor::messages::TapeserverProxyZmq::deleteLogParams(
const std::string &unitName,
const std::list<std::string> & paramNames) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createDeleteLogParamsFrame(unitName, paramNames);
......@@ -501,7 +497,7 @@ castor::messages::Frame castor::messages::TapeserverProxyZmq::
//------------------------------------------------------------------------------
void castor::messages::TapeserverProxyZmq::labelError(
const std::string &unitName, const std::string &message) {
MutexLocker lock(&m_mutex);
cta::threading::MutexLocker lock(m_mutex);
try {
const Frame rqst = createLabelErrorFrame(unitName, message);
......
......@@ -23,7 +23,7 @@
#include "common/log/Logger.hpp"