Commit 7723e149 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Import of the new castor prototype

parent 50730259
COMM @(#)Imakefile,v 1.12 2002/11/28 06:54:12 CERN IT-PDP/DM Jean-Philippe Baud
COMM
COMM Copyright (C) 1990-2002 by CERN/IT/PDP/DM
COMM All rights reserved
COMM
COMM Make CASTOR libraries and executables
#include <Project.tmpl>
SUBDIRS = $(LIBDIR) $(SHLIBDIR) $(COMMONDIR) $(MONITORDIR) $(UPVDIR) $(DBDIR) \
$(MSGDIR) $(NSDIR) $(RFIODIR) $(DLFDIR)\
$(RMCDIR) $(SYSREQDIR) $(RTCOPYDIR) $(STAGEDIR) $(TAPEDIR) \
$(VDQMDIR) $(VMGRDIR) $(COMMANDSDIR) $(COPYTAPEDIR) $(EXAMPLESDIR) \
$(HPSSDIR) $(HSMTOOLSDIR) h $(COMMONCPPDIR)
EXPORTSUBDIRS = $(LIBDIR) $(SHLIBDIR) $(COMMONDIR) $(MONITORDIR) $(UPVDIR) $(DBDIR) \
$(MSGDIR) $(NSDIR) $(RFIODIR) $(DLFDIR)\
$(RMCDIR) $(SYSREQDIR) $(RTCOPYDIR) $(STAGEDIR) $(TAPEDIR) \
$(VDQMDIR) $(VMGRDIR) $(COMMANDSDIR) $(COPYTAPEDIR) $(EXAMPLESDIR) \
$(HPSSDIR) $(HSMTOOLSDIR) h
DEPENDDIRS = $(COMMONDIR) $(MONITORDIR) $(UPVDIR) $(DBDIR) \
$(MSGDIR) $(NSDIR) $(RFIODIR) $(DLFDIR) \
$(RMCDIR) $(SYSREQDIR) $(RTCOPYDIR) $(STAGEDIR) $(TAPEDIR) \
$(VDQMDIR) $(VMGRDIR) $(COMMANDSDIR) $(COPYTAPEDIR) $(EXAMPLESDIR) \
$(HPSSDIR) $(HSMTOOLSDIR) $(COMMONCPPDIR)
EXPORTBIN=$(EXPORT)/bin
EXPORTLIB=$(EXPORT)/lib
EXPORTINC=$(EXPORTSHR)/include
EXPORTH=$(EXPORTINC)/shift
MakeSubdirs(all,$(SUBDIRS))
MakeSubdirs(install,$(SUBDIRS))
MakeSubdirs(install.man,$(SUBDIRS))
MakeCondSubdirs(clean,$(SUBDIRS),imakeclean)
MakeCondSubdirs(clobber,$(SUBDIRS),imakeclobber)
#if defined(_WIN32)
cernlib:
@(cd lib & $(MAKE) $(MFLAGS) & cd ..)
imakeclean:
@(cd imake & $(MAKE) $(MFLAGS) -f Makefile.ini.Win32 clean & cd ..)
imakeclobber:
@(cd imake & $(MAKE) $(MFLAGS) -f Makefile.ini.Win32 clobber & cd ..)
#else
cernlib:
@(cd lib; $(MAKE) $(MFLAGS))
imakeclean:
@(cd imake; $(MAKE) $(MFLAGS) -f Makefile.ini clean)
imakeclobber:
@(cd imake; $(MAKE) $(MFLAGS) -f Makefile.ini clobber)
#endif
export:
(if [ "x$(EXPORT)" = "x" ] ; \
then \
echo "EXPORT must be set (thru make or environment)" ; exit 1 ; \
else \
echo "exporting to $(EXPORT)" ; \
fi ; \
for i in $(EXPORTSUBDIRS) ;\
do (echo " $$i (EXPORT):" ; cd $$i ; \
$(MAKE) $(MFLAGS) EXPORTBIN=$(EXPORTBIN) EXPORTLIB=$(EXPORTLIB) $@ ; \
) ; done ; \
) ;
exportman:
(if [ "x$(EXPORTMAN)" = "x" ] ; \
then \
echo "EXPORTMAN must be set (thru make or environment)" ; exit 1 ; \
else \
echo "exporting to $(EXPORTMAN)" ; \
fi ; \
for i in $(EXPORTSUBDIRS) ;\
do (echo " $$i (EXPORTMAN):" ; cd $$i ; \
$(MAKE) $(MFLAGS) EXPORTMAN=$(EXPORTMAN) $@ ; \
) ; done ; \
) ;
exportshr:
(if [ "x$(EXPORTSHR)" = "x" ] ; \
then \
echo "EXPORTSHR must be set (thru make or environment)" ; exit 1 ; \
else \
echo "exporting to $(EXPORTSHR)" ; \
fi ; \
for i in $(EXPORTSUBDIRS) ;\
do (echo " $$i (EXPORTSHR):" ; cd $$i ; \
$(MAKE) $(MFLAGS) EXPORTSHR=$(EXPORTSHR) EXPORTINC=$(EXPORTINC) EXPORTH=$(EXPORTH) $@ ; \
) ; done ; \
) ;
#if defined(_WIN32)
test: Makefiles
cd test & $(MAKE) all & cd ..
Makefiles:
@for %i in ( $(SUBDIRS) test ) \
do @(echo %i - & cd %i & \
..\imake\imake -I..\config & \
$(MAKE) $(MFLAGS) $@ & cd .. )
depend:
@echo Not supported on this platform
#else
test: Makefiles
(cd test; $(MAKE) all)
Makefiles:
@. ./setosflags ;\
for i in $(SUBDIRS) test ;\
do (if [ -d $$i ] ;\
then \
(echo " $$i:" ; cd $$i ;\
../imake/imake -I../config -DOSMajorVersion="$$OSMAJNO" -DOSMinorVersion="$$OSMINNO" ;\
$(MAKE) $(MFLAGS) $@) ;\
else \
(echo "ERROR : No directory $$i" ;\
exit 1) ;\
fi )\
done ;
depend:
for i in $(DEPENDDIRS) test ;\
do (if [ -d $$i ] ;\
then \
(echo " $$i:" ; cd $$i ;\
$(MAKE) $(MFLAGS) $@) ;\
else \
(echo "ERROR : No directory $$i" ;\
exit 1) ;\
fi )\
done ;
#endif
/******************************************************************************
* BaseAddress.cpp
*
* 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.
*
* @(#)$RCSfile$ $Revision$ $Release$ $Date$ $Author$
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "Constants.hpp"
#include "BaseAddress.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::BaseAddress::BaseAddress(const std::string cnvSvcName,
const unsigned int cnvSvcType,
const unsigned int objType) :
m_objType(objType), m_cnvSvcName(cnvSvcName),
m_cnvSvcType(cnvSvcType) {}
//------------------------------------------------------------------------------
// print
//------------------------------------------------------------------------------
void castor::BaseAddress::print(std::ostream& s) const {
s << "ObjType " << m_objType << ", CnvSvc " << m_cnvSvcName;
}
/******************************************************************************
* BaseAddress.h
*
* 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.
*
* @(#)$RCSfile$ $Revision$ $Release$ $Date$ $Author$
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_BASEADDRESS_H
#define CASTOR_BASEADDRESS_H 1
/**
* Forward declaration of IAddress for the C world
*/
struct C_BaseAddress_t;
/*
* constructor
*/
int C_BaseAddress_create(const char* cnvSvcName,
const unsigned int cnvSvcType,
struct C_BaseAddress_t** addr);
/*
* destructor
*/
int C_BaseAddress_delete(struct C_BaseAddress_t* addr);
/**
* Cast into IAddress
*/
struct C_IAddress_t* C_BaseAddress_getIAddress(struct C_BaseAddress_t* obj);
/**
* Dynamic cast from Request
*/
struct C_BaseAddress_t* C_BaseAddress_fromIAddress(struct C_IAddress_t* obj);
#endif // CASTOR_BASEADDRESS_H
/******************************************************************************
* BaseAddress.hpp
*
* 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.
*
* @(#)$RCSfile$ $Revision$ $Release$ $Date$ $Author$
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_BASEADDRESS_HPP
#define CASTOR_BASEADDRESS_HPP 1
// Include Files
#include "IAddress.hpp"
#include "Constants.hpp"
namespace castor {
/**
* The most basic address : only a type.
*/
class BaseAddress : public IAddress {
public:
/**
* constructor
*/
BaseAddress(const std::string cnvSvcName,
const unsigned int cnvSvcType,
const unsigned int objType = OBJ_INVALID);
/*
* destructor
*/
virtual ~BaseAddress() {}
/**
* gets the object type, that is the type of
* object whose representation is pointed to by
* this address.
*/
virtual const unsigned int objType() const { return m_objType; }
/**
* sets the object type, that is the type of
* object whose representation is pointed to by
* this address.
*/
void setObjType(unsigned int type) { m_objType = type; }
/**
* gets the name of the conversion service able
* to deal with this address
*/
virtual const std::string cnvSvcName() const { return m_cnvSvcName; }
/**
* gets the type of the conversion service able
* to deal with this address
*/
virtual const unsigned int cnvSvcType() const { return m_cnvSvcType; }
/**
* prints the address into an output stream
*/
virtual void print(std::ostream& s) const;
private:
/**
* the object type of this address
*/
unsigned long m_objType;
/**
* the name of the conversion service able to deal
* with this address
*/
const std::string m_cnvSvcName;
/**
* the type of the conversion service able to deal
* with this address
*/
const unsigned int m_cnvSvcType;
};
} // end of namespace castor
#endif // CASTOR_BASEADDRESS_HPP
/******************************************************************************
* BaseAddressCInt.cpp
*
* 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.
*
* @(#)$RCSfile$ $Revision$ $Release$ $Date$ $Author$
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/BaseAddress.hpp"
extern "C" {
//----------------------------------------------------------------------------
// C_BaseAddress_create
//----------------------------------------------------------------------------
int C_BaseAddress_create(const char* cnvSvcName,
const unsigned int cnvSvcType,
castor::BaseAddress** addr) {
*addr = new castor::BaseAddress(cnvSvcName, cnvSvcType);
return 0;
}
//----------------------------------------------------------------------------
// C_BaseAddress_delete
//----------------------------------------------------------------------------
int C_BaseAddress_delete(castor::BaseAddress* addr) {
delete addr;
return 0;
}
//----------------------------------------------------------------------------
// C_BaseAddress_getIAddress
//----------------------------------------------------------------------------
castor::IAddress* C_BaseAddress_getIAddress(castor::BaseAddress* obj) {
return obj;
}
//----------------------------------------------------------------------------
// C_BaseAddress_fromIAddress
//----------------------------------------------------------------------------
castor::BaseAddress* C_BaseAddress_fromIAddress(castor::IAddress* obj) {
return dynamic_cast<castor::BaseAddress*>(obj);
}
} // End of extern "C"
/******************************************************************************
* BaseCnvSvc.cpp
*
* 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.
*
* @(#)$RCSfile: BaseCnvSvc.cpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include <map>
// Local Includes
#include "ICnvFactory.hpp"
#include "BaseCnvSvc.hpp"
#include "Converters.hpp"
#include "IConverter.hpp"
#include "IAddress.hpp"
#include "IObject.hpp"
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
castor::BaseCnvSvc::BaseCnvSvc(const std::string name) :
BaseSvc(name) {}
//-----------------------------------------------------------------------------
// addConverter
//-----------------------------------------------------------------------------
bool castor::BaseCnvSvc::addConverter(IConverter* pConverter) {
if (pConverter !=0) {
unsigned int id = pConverter->repType();
if (m_converters[id] != 0) removeConverter(id);
m_converters[id] = pConverter;
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// removeConverter
//-----------------------------------------------------------------------------
bool castor::BaseCnvSvc::removeConverter(const unsigned int id) {
IConverter* c = m_converters[id];
if (c != 0) delete c;
m_converters.erase(id);
return true;
}
//-----------------------------------------------------------------------------
// converter
//-----------------------------------------------------------------------------
castor::IConverter* castor::BaseCnvSvc::converter(const unsigned int objType)
throw (Exception) {
// check if we have one
IConverter* conv = m_converters[objType];
if (0 != conv) return conv;
// Try to find one
const castor::ICnvFactory* fac =
castor::Converters::instance()->cnvFactory(repType(), objType);
if (0 == fac) {
Exception e;
e.getMessage() << "No factory found for object type "
<< objType << " and representation type "
<< repType() << std::endl;
throw e;
}
m_converters[objType] = fac->instantiate();
if (0!= m_converters[objType]) return m_converters[objType];
// Throw an exception since we did not find any suitable converter
Exception e;
e.getMessage() << "No converter for object type "
<< objType << " and representation type "
<< repType() << std::endl;
throw e;
};
// -----------------------------------------------------------------------
// createRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::createRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
return conv->createRep(address, object,
alreadyDone, autocommit);
}
// -----------------------------------------------------------------------
// updateRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::updateRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
return conv->updateRep(address, object,
alreadyDone, autocommit);
}
// -----------------------------------------------------------------------
// deleteRep
// -----------------------------------------------------------------------
void castor::BaseCnvSvc::deleteRep(castor::IAddress* address,
castor::IObject* object,
ObjectSet& alreadyDone,
bool autocommit)
throw (castor::Exception) {
// Look for an adapted converter
IConverter* conv = converter(object->type());
// convert
return conv->deleteRep(address, object,
alreadyDone, autocommit);
}
// -----------------------------------------------------------------------
// createObj
// -----------------------------------------------------------------------
castor::IObject* castor::BaseCnvSvc::createObj
(castor::IAddress* address, castor::ObjectCatalog& newlyCreated)
throw (castor::Exception) {
// Look for an adapted converter
castor::IConverter* conv = converter(address->objType());
return conv->createObj(address, newlyCreated);
}
/******************************************************************************
* BaseCnvSvc.hpp
*
* 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.
*
* @(#)$RCSfile: BaseCnvSvc.hpp,v $ $Revision: 1.1.1.1 $ $Release$ $Date: 2004/05/12 12:13:34 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_BASECNVSVC_HPP
#define CASTOR_BASECNVSVC_HPP 1
// Include Files
#include <map>
// Local Includes
#include "ICnvSvc.hpp"
#include "BaseSvc.hpp"
#include "Exception.hpp"
#include "ObjectSet.hpp"
#include "ObjectCatalog.hpp"
namespace castor {
// Forward Declarations
class IConverter;
class IAddress;
class IObject;
/**
* Base class for conversion services.
* It essentially handles a map of converters.
*/
class BaseCnvSvc : public BaseSvc, public virtual ICnvSvc {
public:
/**
* constructor
*/
BaseCnvSvc(const std::string name);
/**
* Add converter object to conversion service.
* @param pConverter Pointer to converter object
* @return boolean indicating success or failure.
*/
virtual bool addConverter(IConverter* pConverter);
/**
* Remove converter object from conversion service (if present).
* The converter is defined by the class type of the objects created.