Skip to content
Snippets Groups Projects
Commit 158f1b23 authored by Eric Cano's avatar Eric Cano
Browse files

Turned the C dlf global variable connection into a C++ class allowing cleanup.

Added cleanup in the pending list of the c++ version of the library (for cases when dlf_init is not called.
parent 147fd4c9
Branches
Tags
No related merge requests found
......@@ -31,13 +31,12 @@
#include <errno.h>
//-----------------------------------------------------------------------------
// dlf_getPendingMessages
//-----------------------------------------------------------------------------
std::vector<std::pair<int, castor::dlf::Message*> >&
castor::dlf::dlf_getPendingMessages () throw() {
static std::vector<std::pair<int, castor::dlf::Message*> > pendingMessages;
static dlg_pengindMessagesVector pendingMessages;
return pendingMessages;
}
......@@ -58,12 +57,13 @@ void castor::dlf::dlf_init
// logging
dlf_addMessages(0, messages);
// Also register the pending messages
for (std::vector<std::pair<int, Message*> >::const_iterator it =
for (std::vector<std::pair<int, Message*> >::iterator it =
dlf_getPendingMessages().begin();
it != dlf_getPendingMessages().end();
it++) {
dlf_addMessages(it->first, it->second);
delete[](it->second);
it->second = NULL;
}
dlf_getPendingMessages().clear();
}
......
......@@ -72,6 +72,26 @@ namespace castor {
*/
std::vector<std::pair<int, castor::dlf::Message*> >&
dlf_getPendingMessages() throw();
/**
* Helper class adding a cleanup for unclaimed pending
* messages. This is for the case when dlf_init never gets
* called (new done in castor::dlf::dlf_addMessages for
* static data from castorclient (?) library.
*/
class dlg_pengindMessagesVector:
public std::vector<std::pair<int, castor::dlf::Message*> > {
public:
~dlg_pengindMessagesVector() {
for (std::vector<std::pair<int, Message*> >::iterator it =
dlf_getPendingMessages().begin();
it != dlf_getPendingMessages().end();
it++) {
delete[](it->second);
it->second = NULL;
}
}
};
/**
* Initialization of the DLF logging system
......
......@@ -25,7 +25,7 @@ cmake_minimum_required (VERSION 2.6)
################################################################################
# Rules to build and install libcastordlf.so
################################################################################
set (DLF_LIB_SRC_FILES dlf_lib.c)
set (DLF_LIB_SRC_FILES dlf_lib.cpp)
add_library (castordlf SHARED ${DLF_LIB_SRC_FILES})
CastorSetLibraryVersions (castordlf)
target_link_libraries (castordlf castorcommon)
......
This diff is collapsed.
......@@ -52,14 +52,14 @@ static struct {
int value; /* The priority's numeric representation in syslog */
char *text; /* Textual representation of the priority */
} prioritylist[] = {
{ "LOG_EMERG", LOG_EMERG, "Emerg" },
{ "LOG_ALERT", LOG_ALERT, "Alert" },
{ "LOG_CRIT", LOG_CRIT, "Crit" },
{ "LOG_ERR", LOG_ERR, "Error" },
{ "LOG_WARNING", LOG_WARNING, "Warn" },
{ "LOG_NOTICE", LOG_NOTICE, "Notice" },
{ "LOG_INFO", LOG_INFO, "Info" },
{ "LOG_DEBUG", LOG_DEBUG, "Debug" },
{ (char *)"LOG_EMERG", LOG_EMERG, (char *)"Emerg" },
{ (char *)"LOG_ALERT", LOG_ALERT, (char *)"Alert" },
{ (char *)"LOG_CRIT", LOG_CRIT, (char *)"Crit" },
{ (char *)"LOG_ERR", LOG_ERR, (char *)"Error" },
{ (char *)"LOG_WARNING", LOG_WARNING, (char *)"Warn" },
{ (char *)"LOG_NOTICE", LOG_NOTICE, (char *)"Notice" },
{ (char *)"LOG_INFO", LOG_INFO, (char *)"Info" },
{ (char *)"LOG_DEBUG", LOG_DEBUG, (char *)"Debug" },
{ NULL, 0, NULL }
};
......
......@@ -225,19 +225,6 @@ EXTERN_C int dlf_writep (Cuuid_t reqid,
unsigned int numparams,
dlf_write_param_t params[]);
/* This function is a wrapper around the dlf_writep function.
* the only difference is that it takes a variable argument list '...'
* rather than an array of dlf_write_param_t structures
* This is deprecated
*/
EXTERN_C int dlf_write (Cuuid_t reqid,
unsigned int priority,
unsigned int msgno,
struct Cns_fileid *ns,
int numparams,
...);
/* Check to see if the DLF interface has been initialized
* @returns 1 if the interface is initialized, 0 if not
* @see dlf_init()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment