Commit 58951ff8 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

C++ interface to DLF. This is supposed to replace the current logging facility...

C++ interface to DLF. This is supposed to replace the current logging facility without loosing the possibility to give objects to the interface.
parent 64dc0fea
......@@ -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: BaseObject.hpp,v $ $Revision: 1.10 $ $Release$ $Date: 2004/12/16 18:29:02 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseObject.hpp,v $ $Revision: 1.11 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* Basic object support, including pointer to Services and log support
*
......@@ -29,6 +29,7 @@
// Include Files
#include "castor/logstream.h"
#include "castor/dlf/Dlf.hpp"
#include "castor/exception/Exception.hpp"
namespace castor {
......
......@@ -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.82 $ $Release$ $Date: 2005/03/22 17:48:07 $ $Author: sponcec3 $
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.83 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
#
# Make Castor libraries and executables
#
......@@ -109,6 +109,9 @@ STGLIB_SRCS = IAddressCInt.cpp \
client/BaseClient.cpp \
client/BasicResponseHandler.cpp \
client/VectorResponseHandler.cpp \
dlf/Message.cpp \
dlf/Param.cpp \
dlf/Dlf.cpp \
io/AbstractSocket.cpp \
io/ClientSocket.cpp \
io/ServerSocket.cpp \
......@@ -312,6 +315,7 @@ STGLIB_SRCS = IAddressCInt.cpp \
stager/TapePoolCInt.cpp \
stager/TapeStatusCodes.cpp \
stager/TapeCopyStatusCodes.cpp \
stager/TapeVid.cpp \
exception/BadVersion.cpp \
exception/Exception.cpp \
exception/InvalidArgument.cpp \
......
/******************************************************************************
* dlf_write.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: Dlf.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* C++ interface to DLF
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/dlf/Dlf.hpp"
// -----------------------------------------------------------------------
// dlf_writep
// -----------------------------------------------------------------------
void castor::dlf::dlf_init
(char* facilityName, Message messages[]) {
// First set the DLF error buffer. Otherwise it may
// write to standard ouput
char *dlfErrBuf;
dlfErrBuf = (char *)malloc(CA_MAXLINELEN+1);
(void)dlf_seterrbuf(dlfErrBuf,CA_MAXLINELEN);
// initialize DLF, ignore output so that we don't give up
// if the DLF server is not available
::dlf_init(facilityName);
// Enter messages in the facility, even if initialization
// was not successful since it could be used for local
// logging
int i = 0;
extern dlf_facility_info_t g_dlf_fac_info;
while (messages[i].number >= 0) {
::dlf_add_to_text_list(messages[i].number,
messages[i].text.c_str(),
&g_dlf_fac_info.text_list);
::dlf_entertext(facilityName,
messages[i].number,
messages[i].text.c_str());
i++;
}
}
// -----------------------------------------------------------------------
// dlf_writep
// -----------------------------------------------------------------------
void castor::dlf::dlf_writep
(Cuuid_t uuid,
int severity,
int message_no,
int numparams,
castor::dlf::Param params[],
struct Cns_fileid *ns_invariant) {
// Place holder for the C version of the parameters
dlf_write_param_t cparams[numparams];
// Translate paramters from C++ to C
for (int i = 0; i < numparams; i++) {
cparams[i] = params[i].cParam();
}
::dlf_writep(uuid, severity, message_no,
ns_invariant, numparams, cparams);
}
/******************************************************************************
* dlf_write.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: Dlf.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* C++ interface to DLF
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef DLF_DLF_WRITE_HPP
#define DLF_DLF_WRITE_HPP 1
// Include Files
#include "dlf_constants.h"
#include "castor/dlf/Message.hpp"
#include "castor/dlf/Param.hpp"
namespace castor {
namespace dlf {
/**
* Initialization of the DLF logging system
* @param facilityName name of the DLF facility to use
* @param messages array of messages to decalre in the
* facility. The end of the array is marked by a
* message with negative number.
*/
void dlf_init(char* facilityName,
Message messages[]);
/**
* prints a message into dlf.
* @param uuid the uuid of the component issuing the message
* @param message_no the message number in the facility.
* @param severity the severity of the message.
* @param numparams the number of parameters in the message
* @param params the parameters of the message, given as an array
* @ns_invariant the castor file concerned by the message
* (if any), given as a name server fileId.
*/
void dlf_writep (Cuuid_t uuid,
int severity,
int message_no,
int numparams = 0,
castor::dlf::Param params[] = 0,
struct Cns_fileid *ns_invariant = 0);
} // end of namespace dlf
} // end of namespace castor
#endif // DLF_DLF_WRITE_HPP
/******************************************************************************
* Message.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: Message.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* Container for a DLF message
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/dlf/Message.hpp"
/******************************************************************************
* Message.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: Message.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* Container for a DLF message
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef DLF_MESSAGE_HPP
#define DLF_MESSAGE_HPP 1
// Include Files
#include <string>
namespace castor {
namespace dlf {
/**
* Container for a DLF message
*/
struct Message {
/// Message number
int number;
/// Message text
std::string text;
};
} // end of namespace dlf
} // end of namespace castor
#endif // DLF_MESSAGE_HPP
/******************************************************************************
* Param.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: Param.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
*
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include <sstream>
#include "castor/dlf/Param.hpp"
#include "castor/ObjectSet.hpp"
#include "castor/IObject.hpp"
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
castor::dlf::Param::Param(char* name,
castor::IObject* value) :
m_deallocate(true) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_STR;
std::ostringstream s;
castor::ObjectSet set;
value->print(s, "", set);
m_cParam.par.par_string = strdup(s.str().c_str());
}
/******************************************************************************
* Param.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: Param.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* A parameter for the DLF (Distributed Logging System)
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef DLF_PARAM_HPP
#define DLF_PARAM_HPP 1
// Include Files
#include "dlf_api.h"
#include "dlf_struct.h"
#include "castor/IObject.hpp"
#include "castor/stager/TapeVid.hpp"
namespace castor {
namespace dlf {
/**
* A parameter for the DLF.
*/
class Param {
public:
/**
* Constructor for strings
*/
Param(char* name, char* value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_STR;
m_cParam.par.par_string = value;
};
/**
* Constructor for uuids
*/
Param(char* name, Cuuid_t value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_UUID;
m_cParam.par.par_uuid = value;
};
/**
* Constructor for int
*/
Param(char* name, int value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_INT;
m_cParam.par.par_int = value;
};
/**
* Constructor for u_signed64
*/
Param(char* name, u_signed64 value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_INT64;
m_cParam.par.par_u64 = value;
};
/**
* Constructor for floats
*/
Param(char* name, float value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_FLOAT;
m_cParam.par.par_double = value;
};
/**
* Constructor for doubles
*/
Param(char* name, double value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_DOUBLE;
m_cParam.par.par_double = value;
};
/**
* Constructor for Tape VIDS
*/
Param(char* name, castor::stager::TapeVid value) :
m_deallocate(false) {
m_cParam.name = name;
m_cParam.type = DLF_MSG_PARAM_TPVID;
m_cParam.par.par_string = value.vid();
};
/**
* Constructor for objects
*/
Param(char* name, castor::IObject* value);
/**
*
*/
~Param() {
if (m_deallocate) {
free(m_cParam.par.par_string);
}
};
public:
/**
* Gets the corresponding C parameter for the
* DLF C interface
*/
dlf_write_param_t cParam() {
return m_cParam;
}
private:
/// the parameter, in a C structure
dlf_write_param_t m_cParam;
/// Whether the param value should be deallocated
bool m_deallocate;
};
} // end of namespace dlf
} // end of namespace castor
#endif // DLF_PARAM_HPP
/******************************************************************************
* TapeVid.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: TapeVid.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* A very simple class representing a Tape VID
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/stager/TapeVid.hpp"
/******************************************************************************
* TapeVid.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: TapeVid.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2005/04/05 11:51:33 $ $Author: sponcec3 $
*
* A very simple class representing a Tape VID
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef STAGER_TAPEVID_HPP
#define STAGER_TAPEVID_HPP 1
namespace castor {
namespace stager {
/**
* A very simple class representing a Tape VID
*/
class TapeVid {
public:
/**
* Constructor
*/
TapeVid(char* vid) : m_vid(vid){};
/**
* getter
*/
char* vid() { return m_vid; };
private:
/// The VID
char* m_vid;
};
} // end of namespace stager
} // end of namespace castor
#endif // STAGER_TAPEVID_HPP
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