Dlf.cpp 2.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/******************************************************************************
 *                      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.
 *
Vitali Motyakov's avatar
Vitali Motyakov committed
20
 * @(#)Dlf.cpp,v 1.1 $Release$ 2005/04/05 11:51:33 sponcec3
21
22
23
24
25
26
27
28
29
30
 *
 * C++ interface to DLF
 *
 * @author Sebastien Ponce
 *****************************************************************************/

// Include Files
#include "castor/dlf/Dlf.hpp"

// -----------------------------------------------------------------------
31
// dlf_init
32
33
34
// -----------------------------------------------------------------------
void castor::dlf::dlf_init
(char* facilityName, Message messages[]) {
35
36
37
  // Initialise the DLF interface, ignore any errors that may be generated
  char dlfErrBuf[CA_MAXLINELEN+1];  

38
  ::dlf_init(facilityName, dlfErrBuf, 0);
39
40
41

  // Register the facility's messages with the interface. We do this even
  // if the interface fails to initialisation as it is used for local 
42
  // logging
43
44
45
46
47
48
49
  dlf_addMessages(0, messages);
}

// -----------------------------------------------------------------------
// dlf_addMessages
// -----------------------------------------------------------------------
void castor::dlf::dlf_addMessages (int offset, Message messages[]) {
50
51
  int i = 0;
  while (messages[i].number >= 0) {
52
    ::dlf_regtext(offset + messages[i].number,
53
		  messages[i].text.c_str());
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    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
69
  // dlf_write_param_t cparams[numparams]; // Doesn't work on windows compiler!!!
Vitali Motyakov's avatar
Vitali Motyakov committed
70
  dlf_write_param_t* cparams = new dlf_write_param_t[numparams];
71
72
73
74
75
76
  // 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);
Vitali Motyakov's avatar
Vitali Motyakov committed
77
  delete[] cparams;
78
}