Skip to content
Snippets Groups Projects
Commit 0b194ad6 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

IStagerSvc C interface + small modification to the C++ one

parent 312db14f
Branches
Tags
No related merge requests found
......@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.5 $ $Release$ $Date: 2004/05/25 15:30:52 $ $Author: sponcec3 $
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.6 $ $Release$ $Date: 2004/05/26 15:46:25 $ $Author: sponcec3 $
#
# Make Castor libraries and executables
#
......@@ -125,6 +125,7 @@ STGLIB_OBJS = IAddressCInt.Osuf \
rh/RequestCInt.Osuf \
rh/StageInRequest.Osuf \
rh/StageInRequestCInt.Osuf \
stager/IStagerSvcCInt.Osuf \
stager/CastorFile.Osuf \
stager/CastorFileCInt.Osuf \
stager/Cuuid.Osuf \
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: OraStagerSvc.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/26 10:11:44 $ $Author: sponcec3 $
* @(#)$RCSfile: OraStagerSvc.cpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/26 15:46:25 $ $Author: sponcec3 $
*
*
*
......@@ -118,7 +118,7 @@ castor::db::ora::OraStagerSvc::segmentsForTape
// -----------------------------------------------------------------------
// anySegmentsForTape
// -----------------------------------------------------------------------
bool castor::db::ora::OraStagerSvc::anySegmentsForTape
int castor::db::ora::OraStagerSvc::anySegmentsForTape
(castor::stager::Tape* searchItem)
throw (castor::exception::Exception) {
// XXX This is a first version. Has to be improved from
......@@ -129,9 +129,8 @@ bool castor::db::ora::OraStagerSvc::anySegmentsForTape
searchItem->setStatus(castor::stager::TAPE_WAITMOUNT);
castor::ObjectSet alreadyDone;
updateRep(0, searchItem, alreadyDone, true);
return true;
}
return false;
return result.size();
}
// -----------------------------------------------------------------------
......
......@@ -101,10 +101,10 @@ namespace castor {
* copies should be cancelled unless there are outstanding requests
* for other files that reside on that tape.
* @param searchItem the tape information used for the search
* @return whether waiting segments exist
* @return >0 : number of waiting requests found. 0 : no requests found
* @exception in case of error
*/
virtual bool anySegmentsForTape(castor::stager::Tape* searchItem)
virtual int anySegmentsForTape(castor::stager::Tape* searchItem)
throw (castor::exception::Exception);
/**
......
/******************************************************************************
* IStagerSvc.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_ISTAGERSVC_H
#define CASTOR_ISTAGERSVC_H 1
/// Forward declarations for the C world
struct C_IService_t;
struct Cstager_IStagerSvc_t;
struct Cstager_Tape_t;
struct Cstager_Segment_t;
/**
* Dynamic cast from IService
*/
struct Cstager_IStagerSvc_t*
Cstager_IStagerSvc_fromIService(struct C_IService_t* obj);
/**
* Destructor
*/
int Cstager_IStagerSvc_delete(struct Cstager_IStagerSvc_t* svcs);
/*
* Get the array of segments currently waiting for a given tape.
* Search the catalog for all eligible tape files (segments) that
* are waiting for the given tape VID to become ready.
* The matching Segment entries must have one of the
* following status values: SEGMENT_UNPROCESSED,
* SEGMENT_WAITFSEQ, SEGMENT_WAITPATH or SEGMENT_WAITCOPY.
* Before return this function atomically updates the
* matching catalog entries Tape status to TAPE_MOUNTED.
* @param stgSvc the IStagerSvc used
* @param searchItem the tape information used for the search
* @param segmentArray array with pointers to all waiting segments
* @param nbItems number of items in the array
* @return 0 : OK.
* -1 : an error occurred and serrno is set to the corresponding error code
* A detailed error message can be retrieved by calling
* Cstager_IStagerSvc_errorMsg
*/
int Cstager_IStagerSvc_segmentsForTape (Cstager_IStagerSvc_t* stgSvc,
Cstager_Tape_t* searchItem,
Cstager_Segment_t*** segmentArray,
int* nbItems);
/**
* Check if there still are any segments waiting for a given tape.
* Before a tape is physically mounted, the VidWorker process will
* check if there still are Segments entries waiting for this tape.
* If not, the tape request is cancelled. If there is at least one
* matching entry, the matching catalog entries Tape status should be
* updated to TAPE_WAITMOUNT before return.
* TAPE_WAITMOUNT indicates that the tape request will continue
* mounting the tape and the matching Segments entries should normally
* wait for this tape to be mounted. This means that if the CASTOR
* file has multiple tape copies, the tape requests for the other
* copies should be cancelled unless there are outstanding requests
* for other files that reside on that tape.
* @param stgSvc the IStagerSvc used
* @param searchItem the tape information used for the search
* @return >0 : number of waiting requests found. 0 : no requests found
* -1 : an error occurred and serrno is set to the corresponding error code
* A detailed error message can be retrieved by calling
* Cstager_IStagerSvc_errorMsg
*/
int Cstager_IStagerSvc_anySegmentsForTape(Cstager_IStagerSvc_t* stgSvc,
Cstager_Tape_t* searchItem);
/**
* Get an array of the tapes to be processed.
* This method searches the request catalog for all tapes that are
* in TAPE_PENDING status. It atomically updates the status to
* TAPE_WAITVDQM and returns the corresponding Tape objects.
* This means that a subsequent call to this method will not return
* the same entries. Objects may be present n times in the returned
* vector of tapes. The rtcpclientd will notice multiple identical
* requests and only submit one of them to VDQM.
* @param stgSvc the IStagerSvc used
* @param tapeArray output array of pointers to tape objects
* @param nbItems output number of items returned in the tapeArray
* @return 0 : OK.
* -1 : an error occurred and serrno is set to the corresponding error code
* A detailed error message can be retrieved by calling
* Cstager_IStagerSvc_errorMsg
*/
int Cstager_IStagerSvc_tapesToDo(Cstager_IStagerSvc_t* stgSvc,
Cstager_Tape_t*** tapeArray,
int *nbItems);
/**
* Returns the error message associated to the last error.
* Note that the error message string should be deallocated
* by the caller.
* @param stgSvc the IStagerSvc used
* @return the error message
*/
const char* Cstager_IStagerSvc_errorMsg(Cstager_IStagerSvc_t* stgSvc);
#endif // CASTOR_ISTAGERSVC_H
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: IStagerSvc.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/26 10:11:44 $ $Author: sponcec3 $
* @(#)$RCSfile: IStagerSvc.hpp,v $ $Revision: 1.2 $ $Release$ $Date: 2004/05/26 15:46:25 $ $Author: sponcec3 $
*
* This class provides methods usefull to the stager to
* deal with database queries
......@@ -57,11 +57,7 @@ namespace castor {
* following status values: SEGMENT_UNPROCESSED,
* SEGMENT_WAITFSEQ, SEGMENT_WAITPATH or SEGMENT_WAITCOPY.
* Before return this function atomically updates the
* matching catalog entries Tape status to TAPE_MOUNTED
* and Segment status to:
* SEGMENT_WAITFSEQ - if no tape fseq or blockid has been decided yet
* SEGMENT_WAITPATH - if physical disk path has not been decided yet
* SEGMENT_WAITCOPY - if both tape fseq (or blockid) and path are defined
* matching catalog entries Tape status to TAPE_MOUNTED.
* @param searchItem the tape information used for the search
* @return vector with all waiting segments
* @exception in case of error
......@@ -84,10 +80,10 @@ namespace castor {
* copies should be cancelled unless there are outstanding requests
* for other files that reside on that tape.
* @param searchItem the tape information used for the search
* @return whether waiting segments exist
* @return >0 : number of waiting requests found. 0 : no requests found
* @exception in case of error
*/
virtual bool anySegmentsForTape(castor::stager::Tape* searchItem)
virtual int anySegmentsForTape(castor::stager::Tape* searchItem)
throw (castor::exception::Exception) = 0;
/**
......
/******************************************************************************
* IStagerSvcCInt.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: IStagerSvcCInt.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/26 15:46:25 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/stager/IStagerSvc.hpp"
#include "castor/Services.hpp"
#include <string>
extern "C" {
// C include files
#include "castor/ServicesCInt.hpp"
#include "castor/stager/IStagerSvcCInt.hpp"
//------------------------------------------------------------------------------
// Cstager_IStagerSvc_fromIService
//------------------------------------------------------------------------------
Cstager_IStagerSvc_t*
Cstager_IStagerSvc_fromIService(castor::IService* obj) {
Cstager_IStagerSvc_t* stgSvc = new Cstager_IStagerSvc_t();
stgSvc->errorMsg = "";
stgSvc->stgSvc = dynamic_cast<castor::stager::IStagerSvc*>(obj);
return stgSvc;
}
//------------------------------------------------------------------------------
// Cstager_IStagerSvc_delete
//------------------------------------------------------------------------------
int Cstager_IStagerSvc_delete(Cstager_IStagerSvc_t* stgSvc) {
try {
if (0 != stgSvc->stgSvc) delete stgSvc->stgSvc;
} catch (castor::exception::Exception e) {
serrno = e.code();
stgSvc->errorMsg = e.getMessage().str();
return -1;
}
free(stgSvc);
return 0;
}
//---------------------------------------------------------------------------
// Cstager_IStagerSvc_segmentsForTape
//---------------------------------------------------------------------------
int Cstager_IStagerSvc_segmentsForTape(Cstager_IStagerSvc_t* stgSvc,
castor::stager::Tape* searchItem,
castor::stager::Segment*** segmentArray,
int* nbItems) {
try {
std::vector<castor::stager::Segment*> result =
stgSvc->stgSvc->segmentsForTape(searchItem);
*nbItems = result.size();
*segmentArray = (castor::stager::Segment**)
malloc((*nbItems) * sizeof(castor::stager::Segment*));
for (int i = 0; i < *nbItems; i++) {
(*segmentArray)[i] = result[i];
}
} catch (castor::exception::Exception e) {
serrno = e.code();
stgSvc->errorMsg = e.getMessage().str();
return -1;
}
return 0;
}
//---------------------------------------------------------------------------
// Cstager_IStagerSvc_anySegmentsForTape
//---------------------------------------------------------------------------
int Cstager_IStagerSvc_anySegmentsForTape(Cstager_IStagerSvc_t* stgSvc,
castor::stager::Tape* searchItem) {
try {
return stgSvc->stgSvc->anySegmentsForTape(searchItem);
} catch (castor::exception::Exception e) {
serrno = e.code();
stgSvc->errorMsg = e.getMessage().str();
return -1;
}
}
//---------------------------------------------------------------------------
// Cstager_IStagerSvc_tapesToDo
//---------------------------------------------------------------------------
int Cstager_IStagerSvc_tapesToDo(Cstager_IStagerSvc_t* stgSvc,
castor::stager::Tape*** tapeArray,
int *nbItems) {
try {
std::vector<castor::stager::Tape*> result =
stgSvc->stgSvc->tapesToDo();
*nbItems = result.size();
*tapeArray = (castor::stager::Tape**)
malloc((*nbItems) * sizeof(castor::stager::Tape*));
for (int i = 0; i < *nbItems; i++) {
(*tapeArray)[i] = result[i];
}
} catch (castor::exception::Exception e) {
serrno = e.code();
stgSvc->errorMsg = e.getMessage().str();
return -1;
}
return 0;
}
//---------------------------------------------------------------------------
// Cstager_IStagerSvc_errorMsg
//---------------------------------------------------------------------------
const char* Cstager_IStagerSvc_errorMsg(Cstager_IStagerSvc_t* stgSvc) {
return stgSvc->errorMsg.c_str();
}
}
/******************************************************************************
* IStagerSvcCInt.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: IStagerSvcCInt.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/05/26 15:46:25 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef STAGER_ISTAGERSVCCINT_HPP
#define STAGER_ISTAGERSVCCINT_HPP 1
/// Definition of the IStagerSvc C struct
struct Cstager_IStagerSvc_t {
/// The C++ object
castor::stager::IStagerSvc* stgSvc;
/// A placeholder for an error message
std::string errorMsg;
};
#endif // STAGER_ISTAGERSVCCINT_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment