Commit 16b509a1 authored by Eric Cano's avatar Eric Cano
Browse files

Simplified the implementation of the typeId in the tmeplated decorator class

ObjectOps by adding a second parameter to the template.

Thanks to Steve Murray for findind the solution.
parent 20fbc5e3
......@@ -32,10 +32,10 @@
#include <json-c/json.h>
cta::objectstore::Agent::Agent(Backend & os):
ObjectOps<serializers::Agent>(os), m_nextId(0) {}
ObjectOps<serializers::Agent, serializers::Agent_t>(os), m_nextId(0) {}
cta::objectstore::Agent::Agent(GenericObject& go):
ObjectOps<serializers::Agent>(go.objectStore()) {
ObjectOps<serializers::Agent, serializers::Agent_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -43,10 +43,10 @@ cta::objectstore::Agent::Agent(GenericObject& go):
}
cta::objectstore::Agent::Agent(const std::string & name, Backend & os):
ObjectOps<serializers::Agent>(os, name), m_nextId(0) {}
ObjectOps<serializers::Agent, serializers::Agent_t>(os, name), m_nextId(0) {}
void cta::objectstore::Agent::initialize() {
ObjectOps<serializers::Agent>::initialize();
ObjectOps<serializers::Agent, serializers::Agent_t>::initialize();
m_payload.set_heartbeat(0);
m_payload.set_timeout_us(60*1000*1000);
m_payload.set_description("");
......
......@@ -37,7 +37,7 @@ class GenericObject;
* It handles (in the base class):
*/
class Agent: public ObjectOps<serializers::Agent> {
class Agent: public ObjectOps<serializers::Agent, serializers::Agent_t> {
public:
CTA_GENERATE_EXCEPTION_CLASS(AgentStillOwnsObjects);
Agent(Backend & os);
......
......@@ -22,10 +22,10 @@
#include <json-c/json_object.h>
cta::objectstore::AgentRegister::AgentRegister(Backend & os):
ObjectOps<serializers::AgentRegister>(os) {}
ObjectOps<serializers::AgentRegister, serializers::AgentRegister_t>(os) {}
cta::objectstore::AgentRegister::AgentRegister(GenericObject& go):
ObjectOps<serializers::AgentRegister>(go.objectStore()) {
ObjectOps<serializers::AgentRegister, serializers::AgentRegister_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -33,10 +33,10 @@ cta::objectstore::AgentRegister::AgentRegister(GenericObject& go):
}
cta::objectstore::AgentRegister::AgentRegister(const std::string & name, Backend & os):
ObjectOps<serializers::AgentRegister>(os, name) {}
ObjectOps<serializers::AgentRegister, serializers::AgentRegister_t>(os, name) {}
void cta::objectstore::AgentRegister::initialize() {
ObjectOps<serializers::AgentRegister>::initialize();
ObjectOps<serializers::AgentRegister, serializers::AgentRegister_t>::initialize();
// There is nothing to do for the payload.
m_payloadInterpreted = true;
}
......
......@@ -27,7 +27,7 @@ class Backend;
class Agent;
class GenericObject;
class AgentRegister: public ObjectOps<serializers::AgentRegister> {
class AgentRegister: public ObjectOps<serializers::AgentRegister, serializers::AgentRegister_t> {
public:
AgentRegister(Backend & os);
AgentRegister(GenericObject & go);
......
......@@ -23,13 +23,13 @@
#include <json-c/json.h>
cta::objectstore::ArchiveRequest::ArchiveRequest(const std::string& address, Backend& os):
ObjectOps<serializers::ArchiveRequest>(os, address){ }
ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t>(os, address){ }
cta::objectstore::ArchiveRequest::ArchiveRequest(Backend& os):
ObjectOps<serializers::ArchiveRequest>(os) { }
ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t>(os) { }
cta::objectstore::ArchiveRequest::ArchiveRequest(GenericObject& go):
ObjectOps<serializers::ArchiveRequest>(go.objectStore()) {
ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -38,7 +38,7 @@ cta::objectstore::ArchiveRequest::ArchiveRequest(GenericObject& go):
void cta::objectstore::ArchiveRequest::initialize() {
// Setup underlying object
ObjectOps<serializers::ArchiveRequest>::initialize();
ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t>::initialize();
// This object is good to go (to storage)
m_payloadInterpreted = true;
}
......
......@@ -34,7 +34,7 @@ class Agent;
class GenericObject;
class CreationLog;
class ArchiveRequest: public ObjectOps<serializers::ArchiveRequest> {
class ArchiveRequest: public ObjectOps<serializers::ArchiveRequest, serializers::ArchiveRequest_t> {
public:
ArchiveRequest(const std::string & address, Backend & os);
ArchiveRequest(Backend & os);
......
......@@ -25,14 +25,14 @@
cta::objectstore::ArchiveToFileRequest::ArchiveToFileRequest(
const std::string& address, Backend& os):
ObjectOps<serializers::ArchiveToFileRequest>(os, address) { }
ObjectOps<serializers::ArchiveToFileRequest, serializers::ArchiveToFileRequest_t>(os, address) { }
cta::objectstore::ArchiveToFileRequest::ArchiveToFileRequest(
Backend& os):
ObjectOps<serializers::ArchiveToFileRequest>(os) { }
ObjectOps<serializers::ArchiveToFileRequest, serializers::ArchiveToFileRequest_t>(os) { }
cta::objectstore::ArchiveToFileRequest::ArchiveToFileRequest(GenericObject& go):
ObjectOps<serializers::ArchiveToFileRequest>(go.objectStore()) {
ObjectOps<serializers::ArchiveToFileRequest, serializers::ArchiveToFileRequest_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -41,7 +41,7 @@ cta::objectstore::ArchiveToFileRequest::ArchiveToFileRequest(GenericObject& go):
void cta::objectstore::ArchiveToFileRequest::initialize() {
// Setup underlying object
ObjectOps<serializers::ArchiveToFileRequest>::initialize();
ObjectOps<serializers::ArchiveToFileRequest, serializers::ArchiveToFileRequest_t>::initialize();
// This object is good to go (to storage)
m_payloadInterpreted = true;
}
......
......@@ -31,7 +31,7 @@ class Agent;
class GenericObject;
class CreationLog;
class ArchiveToFileRequest: public ObjectOps<serializers::ArchiveToFileRequest> {
class ArchiveToFileRequest: public ObjectOps<serializers::ArchiveToFileRequest, serializers::ArchiveToFileRequest_t> {
public:
ArchiveToFileRequest(const std::string & address, Backend & os);
ArchiveToFileRequest(Backend & os);
......
......@@ -16,7 +16,6 @@ set (CTAProtoDependants objectstore/Agent.hpp
objectstore/ArchiveRequest.hpp
objectstore/CreationLog.hpp
objectstore/GenericObject.hpp
objectstore/ObjectOps.cpp
objectstore/ObjectOps.hpp
objectstore/RetrieveRequest.hpp
objectstore/RetrieveToFileRequest.cpp
......@@ -49,7 +48,6 @@ add_library (ctaobjectstore SHARED
BackendRados.cpp
BackendPopulator.cpp
BackendFactory.cpp
ObjectOps.cpp
ProtocolBuffersAlgorithms.cpp
GenericObject.cpp
GarbageCollector.cpp
......
......@@ -26,10 +26,10 @@
#include <iostream>
cta::objectstore::DriveRegister::DriveRegister(const std::string & address, Backend & os):
ObjectOps<serializers::DriveRegister>(os, address) { }
ObjectOps<serializers::DriveRegister, serializers::DriveRegister_t>(os, address) { }
cta::objectstore::DriveRegister::DriveRegister(GenericObject& go):
ObjectOps<serializers::DriveRegister>(go.objectStore()) {
ObjectOps<serializers::DriveRegister, serializers::DriveRegister_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -88,7 +88,7 @@ std::string cta::objectstore::DriveRegister::dump() {
void cta::objectstore::DriveRegister::initialize() {
// Setup underlying object
ObjectOps<serializers::DriveRegister>::initialize();
ObjectOps<serializers::DriveRegister, serializers::DriveRegister_t>::initialize();
m_payloadInterpreted = true;
}
......
......@@ -30,7 +30,7 @@ class Agent;
class GenericObject;
class CreationLog;
class DriveRegister: public ObjectOps<serializers::DriveRegister> {
class DriveRegister: public ObjectOps<serializers::DriveRegister, serializers::DriveRegister_t> {
CTA_GENERATE_EXCEPTION_CLASS(DuplicateEntry);
public:
DriveRegister(const std::string & address, Backend & os);
......
......@@ -23,10 +23,10 @@
namespace cta { namespace objectstore {
class GenericObject: public ObjectOps<serializers::GenericObject> {
class GenericObject: public ObjectOps<serializers::GenericObject, serializers::GenericObject_t> {
public:
GenericObject(const std::string & name, Backend & os):
ObjectOps<serializers::GenericObject>(os, name) {};
ObjectOps<serializers::GenericObject, serializers::GenericObject_t>(os, name) {};
class ForbiddenOperation: public cta::exception::Exception {
public:
......
/*
* 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 "ObjectOps.hpp"
#include "objectstore/cta.pb.h"
namespace cta { namespace objectstore {
#define MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(A) \
template <> const serializers::ObjectType ObjectOps<serializers::A>::typeId = serializers::A##_t
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(GenericObject);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(RootEntry);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(AgentRegister);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(Agent);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(TapePool);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(DriveRegister);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(Tape);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(ArchiveToFileRequest);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(ArchiveRequest);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(RetrieveToFileRequest);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(RetrieveRequest);
MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID(SchedulerGlobalLock);
#undef MAKE_CTA_OBJECTSTORE_OBJECTOPS_TYPEID
}}
\ No newline at end of file
......@@ -223,7 +223,7 @@ protected:
}
};
template <class C>
template <class PayloadType, serializers::ObjectType PayloadTypeId>
class ObjectOps: public ObjectOpsBase {
protected:
ObjectOps(Backend & os, const std::string & name): ObjectOpsBase(os) {
......@@ -272,10 +272,10 @@ protected:
void getHeaderFromObjectStore () {
m_header.ParseFromString(m_objectStore.read(getAddressIfSet()));
if (m_header.type() != typeId) {
if (m_header.type() != payloadTypeId) {
std::stringstream err;
err << "In ObjectOps::getHeaderFromObjectStore wrong object type: "
<< "found=" << m_header.type() << " expected=" << typeId;
<< "found=" << m_header.type() << " expected=" << payloadTypeId;
throw ObjectOpsBase::WrongType(err.str());
}
m_headerInterpreted = true;
......@@ -288,7 +288,7 @@ public:
void initialize() {
if (m_headerInterpreted || m_existingObject)
throw NotNewObject("In ObjectOps::initialize: trying to initialize an exitsting object");
m_header.set_type(typeId);
m_header.set_type(payloadTypeId);
m_header.set_version(0);
m_header.set_owner("");
m_header.set_backupowner("");
......@@ -315,8 +315,8 @@ public:
}
private:
template <class C2>
void writeChild (const std::string & name, C2 & val) {
template <class ChildType>
void writeChild (const std::string & name, ChildType & val) {
m_objectStore.create(name, val.SerializeAsString());
}
......@@ -334,8 +334,8 @@ private:
}
protected:
static const serializers::ObjectType typeId;
C m_payload;
static const serializers::ObjectType payloadTypeId = PayloadTypeId;
PayloadType m_payload;
};
}}
......@@ -24,10 +24,10 @@
cta::objectstore::RetrieveRequest::RetrieveRequest(
const std::string& address, Backend& os):
ObjectOps<serializers::RetrieveRequest>(os, address) { }
ObjectOps<serializers::RetrieveRequest, serializers::RetrieveRequest_t>(os, address) { }
cta::objectstore::RetrieveRequest::RetrieveRequest(GenericObject& go):
ObjectOps<serializers::RetrieveRequest>(go.objectStore()) {
ObjectOps<serializers::RetrieveRequest, serializers::RetrieveRequest_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -36,7 +36,7 @@ cta::objectstore::RetrieveRequest::RetrieveRequest(GenericObject& go):
void cta::objectstore::RetrieveRequest::initialize() {
// Setup underlying object
ObjectOps<serializers::RetrieveRequest>::initialize();
ObjectOps<serializers::RetrieveRequest, serializers::RetrieveRequest_t>::initialize();
// This object is good to go (to storage)
m_payloadInterpreted = true;
}
......
......@@ -33,7 +33,7 @@ class Agent;
class GenericObject;
class CreationLog;
class RetrieveRequest: public ObjectOps<serializers::RetrieveRequest> {
class RetrieveRequest: public ObjectOps<serializers::RetrieveRequest, serializers::RetrieveRequest_t> {
public:
RetrieveRequest(const std::string & address, Backend & os);
RetrieveRequest(GenericObject & go);
......
......@@ -24,10 +24,10 @@
cta::objectstore::RetrieveToFileRequest::RetrieveToFileRequest(
const std::string& address, Backend& os):
ObjectOps<serializers::RetrieveToFileRequest>(os, address) { }
ObjectOps<serializers::RetrieveToFileRequest, serializers::RetrieveToFileRequest_t>(os, address) { }
cta::objectstore::RetrieveToFileRequest::RetrieveToFileRequest(GenericObject& go):
ObjectOps<serializers::RetrieveToFileRequest>(go.objectStore()) {
ObjectOps<serializers::RetrieveToFileRequest, serializers::RetrieveToFileRequest_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -36,7 +36,7 @@ cta::objectstore::RetrieveToFileRequest::RetrieveToFileRequest(GenericObject& go
void cta::objectstore::RetrieveToFileRequest::initialize() {
// Setup underlying object
ObjectOps<serializers::RetrieveToFileRequest>::initialize();
ObjectOps<serializers::RetrieveToFileRequest, serializers::RetrieveToFileRequest_t>::initialize();
// This object is good to go (to storage)
m_payloadInterpreted = true;
}
......
......@@ -31,7 +31,7 @@ class Agent;
class GenericObject;
class CreationLog;
class RetrieveToFileRequest: public ObjectOps<serializers::RetrieveToFileRequest> {
class RetrieveToFileRequest: public ObjectOps<serializers::RetrieveToFileRequest, serializers::RetrieveToFileRequest_t> {
public:
RetrieveToFileRequest(const std::string & address, Backend & os);
RetrieveToFileRequest(GenericObject & go);
......
......@@ -30,10 +30,10 @@
// construtor, when the backend store exists.
// Checks the existence and correctness of the root entry
cta::objectstore::RootEntry::RootEntry(Backend & os):
ObjectOps<serializers::RootEntry>(os, "root") {}
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>(os, "root") {}
cta::objectstore::RootEntry::RootEntry(GenericObject& go):
ObjectOps<serializers::RootEntry>(go.objectStore()) {
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
......@@ -43,7 +43,7 @@ cta::objectstore::RootEntry::RootEntry(GenericObject& go):
// Initialiser. This uses the base object's initialiser and sets the defaults
// of payload.
void cta::objectstore::RootEntry::initialize() {
ObjectOps<serializers::RootEntry>::initialize();
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::initialize();
// There is nothing to do for the payload.
m_payloadInterpreted = true;
}
......@@ -479,7 +479,7 @@ std::string cta::objectstore::RootEntry::addOrGetTapePoolAndCommit(const std::st
agent.addToOwnership(tapePoolAddress);
agent.commit();
// Then create the tape pool object
TapePool tp(tapePoolAddress, ObjectOps<serializers::RootEntry>::m_objectStore);
TapePool tp(tapePoolAddress, ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
tp.initialize(tapePool);
tp.setOwner(agent.getAddressIfSet());
tp.setMaxRetriesWithinMount(maxRetriesPerMount);
......@@ -521,7 +521,7 @@ void cta::objectstore::RootEntry::removeTapePoolAndCommit(const std::string& tap
}
}
// Open the tape pool object
TapePool tp (tpp.address(), ObjectOps<serializers::RootEntry>::m_objectStore);
TapePool tp (tpp.address(), ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
ScopedExclusiveLock tpl(tp);
tp.fetch();
// Verify this is the tapepool we're looking for.
......@@ -621,7 +621,7 @@ void cta::objectstore::RootEntry::removeDriveRegisterAndCommit() {
!m_payload.driveregisterpointer().address().size())
return;
std::string drAddr = m_payload.driveregisterpointer().address();
DriveRegister dr(drAddr, ObjectOps<serializers::RootEntry>::m_objectStore);
DriveRegister dr(drAddr, ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
ScopedExclusiveLock drl(dr);
dr.fetch();
// Check the drive register is empty
......@@ -713,7 +713,7 @@ void cta::objectstore::RootEntry::removeAgentRegisterAndCommit() {
// well
if (m_payload.agentregisterintent().size()) {
AgentRegister iar(m_payload.agentregisterintent(),
ObjectOps<serializers::RootEntry>::m_objectStore);
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
ScopedExclusiveLock iarl(iar);
// An agent register only referenced in the intent should not be used
// and hence empty. We'll see that.
......@@ -729,7 +729,7 @@ void cta::objectstore::RootEntry::removeAgentRegisterAndCommit() {
if (m_payload.has_agentregisterpointer() &&
m_payload.agentregisterpointer().address().size()) {
AgentRegister ar(m_payload.agentregisterpointer().address(),
ObjectOps<serializers::RootEntry>::m_objectStore);
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
ScopedExclusiveLock arl(ar);
ar.fetch();
if (!ar.isEmpty()) {
......@@ -759,10 +759,10 @@ void cta::objectstore::RootEntry::addIntendedAgentRegistry(const std::string& ad
// If it did not, we clean up the object if present, clean up the intent
// and replace it with the new one.
// We do not recycle the object, as the state is doubtful.
if (ObjectOps<serializers::RootEntry>::m_objectStore.exists(
if (ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore.exists(
m_payload.agentregisterintent())) {
AgentRegister iar(m_payload.agentregisterintent(),
ObjectOps<serializers::RootEntry>::m_objectStore);
ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
iar.fetch();
if (!iar.isEmpty()) {
throw AgentRegisterNotEmpty("In RootEntry::addIntendedAgentRegistry, "
......@@ -833,7 +833,7 @@ void cta::objectstore::RootEntry::removeSchedulerGlobalLockAndCommit() {
!m_payload.schedulerlockpointer().address().size())
return;
std::string sglAddress = m_payload.schedulerlockpointer().address();
SchedulerGlobalLock sgl(sglAddress, ObjectOps<serializers::RootEntry>::m_objectStore);
SchedulerGlobalLock sgl(sglAddress, ObjectOps<serializers::RootEntry, serializers::RootEntry_t>::m_objectStore);
ScopedExclusiveLock sgll(sgl);
sgl.fetch();
// Check the drive register is empty
......
......@@ -32,7 +32,7 @@ namespace cta { namespace objectstore {
class Agent;
class GenericObject;
class RootEntry: public ObjectOps<serializers::RootEntry> {
class RootEntry: public ObjectOps<serializers::RootEntry, serializers::RootEntry_t> {
public:
// Constructor
RootEntry(Backend & os);
......
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