msgLogger.c File Reference

#include "minosDaq.h"
#include "msgLog.h"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <argp.h>
#include <time.h>

Go to the source code of this file.

Classes

struct  arguments_t

Typedefs

typedef struct arguments_t arguments

Functions

static error_t parse_opt (int key, char *arg, struct argp_state *state)
int main (int argc, char **argv)

Variables

const char * argp_program_bug_address = "Caius Howcroft<howcroft@hep.phy.cam.ac.uk>"
const char * argp_program_version = "msgLogger 0.1"
static char args_doc [] = "USER MESSAGE"
static struct argp_option options []
static const char doc []
static struct argp argparms

Typedef Documentation

typedef struct arguments_t arguments

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 100 of file msgLogger.c.

References argparms, arguments_t::count, arguments_t::echo, logCritical(), logDebug(), logDebugLevelSet(), logError(), logInfo(), logNotice(), logWarn(), arguments_t::message, MINOS_QUASI_ONLINE, msgLogCleanup(), msgLogGetMsgCount(), msgLogInit(), msgLogLocalEchoSet(), msgLogNodeIdSet(), msgLogPidSet(), msgLogResetMsgCount(), arguments_t::nodeId, arguments_t::pid, arguments_t::prio, arguments_t::procname, and arguments_t::stime.

00101 {
00102   long defaultId = MINOS_QUASI_ONLINE;
00103   //default args
00104   arguments dargs;
00105   strcpy(dargs.prio, "I");
00106   dargs.pid=getppid();
00107   strcpy(dargs.procname, "?");
00108   dargs.count=-1;
00109   dargs.stime = time(NULL);
00110   dargs.echo=0;
00111   dargs.nodeId = defaultId;
00112   strcpy(dargs.message, "");
00113   //process args
00114   argp_parse (&argparms, argc, argv, 0, 0, &dargs);
00115   
00116   msgLogInit(dargs.procname);
00117   msgLogNodeIdSet(dargs.nodeId);
00118   logDebugLevelSet(10);
00119   if(dargs.count!=-1) msgLogResetMsgCount(dargs.count);
00120   msgLogPidSet(dargs.pid);
00121   if(dargs.echo)msgLogLocalEchoSet(1);
00122   else msgLogLocalEchoSet(0);
00123   switch(dargs.prio[0])
00124     {
00125     case 'I':
00126     case 'i':
00127       logInfo("%s", dargs.message);
00128       break;
00129     case 'N':
00130     case 'n':
00131       logNotice("%s", dargs.message);
00132       break;
00133     case 'W':
00134     case 'w':
00135       logWarn("%s", dargs.message);
00136       break;
00137     case 'E':
00138     case 'e':
00139       logError("%s", dargs.message);
00140       break;
00141     case 'C':
00142     case 'c':
00143       logCritical("%s", dargs.message);
00144       break;
00145     case 'D':
00146     case 'd':
00147       {
00148         int dbl=0;
00149         switch(dargs.prio[1]){
00150         case '3':dbl=3; break;
00151         case '2':dbl=2; break;
00152         case '1':dbl=3; break;
00153         default: break;
00154         };
00155         logDebug(dbl, "%s", dargs.message);
00156         break;
00157       }
00158     };
00159   msgLogCleanup();
00160   return msgLogGetMsgCount();
00161 }

static error_t parse_opt ( int  key,
char *  arg,
struct argp_state *  state 
) [static]

Definition at line 44 of file msgLogger.c.

References arguments_t::count, arguments_t::echo, arguments_t::message, arguments_t::nodeId, arguments_t::pid, arguments_t::prio, arguments_t::procname, and arguments_t::stime.

00045 {
00046   arguments* args = (arguments*)state->input;
00047   switch (key)
00048     {
00049     case 'l':
00050       strncpy(args->prio, arg, 5);
00051       break;
00052     case 'e':    
00053       args->echo = 1;
00054       break;
00055     case 'c':
00056       args->count = strtol(arg, (char**)NULL, 0);
00057       break;
00058     case 't':
00059       args->stime = strtol(arg, (char**)NULL, 0);
00060       break;
00061     case 's':
00062       strncpy(args->procname,arg , 126);
00063       break;
00064     case 'n':
00065       args->nodeId = strtol(arg, (char**)NULL, 0);
00066       break;
00067     case 'p':
00068       args->pid = strtol(arg, (char**)NULL, 0);
00069       break;
00070     case ARGP_KEY_ARG:
00071       return ARGP_ERR_UNKNOWN;
00072       break;
00073     case ARGP_KEY_ARGS:
00074       { 
00075         int i=0;
00076         for(i=state->next ; i<state->argc;++i)
00077           {
00078             strncat(args->message, " ", 100);
00079             strncat(args->message, state->argv[i], 100);        
00080           }
00081         break;
00082       }
00083     case ARGP_KEY_END:
00084       break;
00085     default:
00086       return ARGP_ERR_UNKNOWN;
00087     }
00088   return 0;
00089 }


Variable Documentation

const char* argp_program_bug_address = "Caius Howcroft<howcroft@hep.phy.cam.ac.uk>"

Definition at line 13 of file msgLogger.c.

const char* argp_program_version = "msgLogger 0.1"

Definition at line 14 of file msgLogger.c.

struct argp argparms [static]
Initial value:

Definition at line 94 of file msgLogger.c.

Referenced by main().

char args_doc[] = "USER MESSAGE" [static]

Definition at line 15 of file msgLogger.c.

const char doc[] [static]
Initial value:
"msgLogger - MINOS Logger script\v Forwards messages to Run Control over UDP."

Definition at line 91 of file msgLogger.c.

Referenced by TiXmlNode::Identify(), and GeoValidate::TestStrip_GetTPos().

struct argp_option options[] [static]
Initial value:
{
  {"priority", 'l', "D1/D2/D3/I/N/W/E/C", 0, "Message Priority", 0},
  {"node", 'n', "INT", 0, "Minos Node ID", 0},
  {"name", 's', "PROCNAME", 0, "Process Name", 0},
  {0,  0, 0, 0,"Expert Actions:",0},
  {"count", 'c', "INT", 0, "Set message count number", 1},
  {"time", 't', "INT", 0, "Set message time (UNIX time)", 1},
  {"echo", 'e', 0, 0, "Echo message to stdout", 1},
  {"pid", 'p', "INT", 0, "Process PID", 0},
  {0}
}

Definition at line 31 of file msgLogger.c.


Generated on 15 Nov 2018 for loon by  doxygen 1.6.1