This is Unofficial EPICS BASE Doxygen Site
iocLog.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE Versions 3.13.7
7 * and higher are distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 /* logClient.c,v 1.25.2.6 2004/10/07 13:37:34 mrk Exp */
11 /*
12  * Author: Jeffrey O. Hill
13  * Date: 080791
14  */
15 
16 #include <stdio.h>
17 #include <limits.h>
18 
19 #include "envDefs.h"
20 #include "errlog.h"
21 #include "logClient.h"
22 #include "iocLog.h"
23 #include "epicsExit.h"
24 
25 int iocLogDisable = 0;
26 
27 static const int iocLogSuccess = 0;
28 static const int iocLogError = -1;
29 
31 
32 /*
33  * getConfig()
34  * Get Server Configuration
35  */
36 static int getConfig (struct in_addr *pserver_addr, unsigned short *pserver_port)
37 {
38  long status;
39  long epics_port;
40 
41  status = envGetLongConfigParam (&EPICS_IOC_LOG_PORT, &epics_port);
42  if (status<0) {
43  fprintf (stderr,
44  "iocLog: EPICS environment variable \"%s\" undefined\n",
46  return iocLogError;
47  }
48 
49  if (epics_port<0 || epics_port>USHRT_MAX) {
50  fprintf (stderr,
51  "iocLog: EPICS environment variable \"%s\" out of range\n",
53  return iocLogError;
54  }
55  *pserver_port = (unsigned short) epics_port;
56 
57  status = envGetInetAddrConfigParam (&EPICS_IOC_LOG_INET, pserver_addr);
58  if (status<0) {
59  fprintf (stderr,
60  "iocLog: EPICS environment variable \"%s\" undefined\n",
62  return iocLogError;
63  }
64 
65  return iocLogSuccess;
66 }
67 
68 /*
69  * iocLogFlush ()
70  */
71 void epicsStdCall epicsStdCall iocLogFlush (void)
72 {
73  if (iocLogClient!=NULL) {
75  }
76 }
77 
78 /*
79  * logClientSendMessage ()
80  */
81 static void logClientSendMessage ( logClientId id, const char * message )
82 {
83  if ( !iocLogDisable ) {
84  logClientSend (id, message);
85  }
86 }
87 
88 /*
89  * iocLogClientDestroy()
90  */
91 static void iocLogClientDestroy (logClientId id)
92 {
93  errlogRemoveListeners (logClientSendMessage, id);
94 }
95 
96 /*
97  * iocLogClientInit()
98  */
99 static logClientId iocLogClientInit (void)
100 {
101  int status;
102  logClientId id;
103  struct in_addr addr;
104  unsigned short port;
105 
106  status = getConfig (&addr, &port);
107  if (status) {
108  return NULL;
109  }
110  id = logClientCreate (addr, port);
111  if (id != NULL) {
112  errlogAddListener (logClientSendMessage, id);
113  epicsAtExit (iocLogClientDestroy, id);
114  }
115  return id;
116 }
117 
118 /*
119  * iocLogInit()
120  */
121 int epicsStdCall iocLogInit (void)
122 {
123  /*
124  * check for global disable
125  */
126  if (iocLogDisable) {
127  return iocLogSuccess;
128  }
129  /*
130  * dont init twice
131  */
132  if (iocLogClient!=NULL) {
133  return iocLogSuccess;
134  }
135  iocLogClient = iocLogClientInit ();
136  if (iocLogClient) {
137  return iocLogSuccess;
138  }
139  else {
140  return iocLogError;
141  }
142 }
143 
144 /*
145  * iocLogShow ()
146  */
147 void epicsStdCall iocLogShow (unsigned level)
148 {
149  if (iocLogClient!=NULL) {
150  logClientShow (iocLogClient, level);
151  }
152 }
153 
154 /*
155  * logClientInit(); deprecated
156  */
157 logClientId epicsStdCall logClientInit (void)
158 {
159  return iocLogClientInit ();
160 }
161 
pvd::Status status
char * name
Name of the parameter.
Definition: envDefs.h:42
Routines to get and set EPICS environment parameters.
void epicsStdCall epicsStdCall iocLogFlush(void)
Definition: iocLog.c:71
void epicsStdCall logClientSend(logClientId id, const char *message)
Definition: logClient.c:200
#define NULL
Definition: catime.c:38
void * logClientId
Definition: logClient.h:30
void epicsStdCall logClientFlush(logClientId id)
Definition: logClient.c:219
logClientId epicsStdCall logClientInit(void)
Definition: iocLog.c:157
void errlogAddListener(errlogListener listener, void *pPrivate)
Definition: errlog.c:317
int epicsStdCall iocLogInit(void)
Definition: iocLog.c:121
Extended replacement for the Posix exit and atexit routines.
LIBCOM_API const ENV_PARAM EPICS_IOC_LOG_INET
LIBCOM_API long epicsStdCall envGetInetAddrConfigParam(const ENV_PARAM *pParam, struct in_addr *pAddr)
Get value of an inet addr config parameter.
Definition: envSubr.c:246
LIBCOM_API long epicsStdCall envGetLongConfigParam(const ENV_PARAM *pParam, long *pLong)
Get value of a long configuration parameter.
Definition: envSubr.c:303
#define stderr
Definition: epicsStdio.h:32
void epicsStdCall iocLogShow(unsigned level)
Definition: iocLog.c:147
#define epicsAtExit(F, A)
Convenience macro to register a function and context value to be run when the process exits...
Definition: epicsExit.h:70
int errlogRemoveListeners(errlogListener listener, void *pPrivate)
Definition: errlog.c:334
logClientId epicsStdCall logClientCreate(struct in_addr server_addr, unsigned short server_port)
Definition: logClient.c:453
void epicsStdCall logClientShow(logClientId id, unsigned level)
Definition: logClient.c:516
int iocLogDisable
Definition: iocLog.c:25
LIBCOM_API const ENV_PARAM EPICS_IOC_LOG_PORT