Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 44 additions & 8 deletions caPutLogApp/caPutJsonLogShellCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
* - Initial version
*/

#include <stdio.h>
#include <errlog.h>
#include <iocsh.h>
#include <epicsExport.h>

#include "caPutJsonLogTask.h"

// Use colored ERROR/WARNING text if available
#ifndef ERL_ERROR
# define ERL_ERROR "ERROR"
# define ERL_WARNING "WARNING"
#endif

/* EPICS iocsh shell commands */
extern "C"
{
Expand All @@ -35,7 +42,7 @@ extern "C"
&caPutJsonLogInitArg0,
&caPutJsonLogInitArg1
};
static const iocshFuncDef caPutjsonLogInitDef = {"caPutJsonLogInit", 2, caPutJsonLogInitArgs};
static const iocshFuncDef caPutJsonLogInitDef = {"caPutJsonLogInit", 2, caPutJsonLogInitArgs};
static void caPutJsonLogInitCall(const iocshArgBuf *args)
{
caPutJsonLogInit(args[0].sval, static_cast<caPutJsonLogConfig>(args[1].ival));
Expand Down Expand Up @@ -76,17 +83,46 @@ extern "C"
caPutJsonLogShow(args[0].ival);
}

/* Error message if caPutLogInit used */
static const iocshFuncDef caPutLogInitDef = {"caPutLogInit", 0, NULL};
static void caPutLogInitCall(const iocshArgBuf *args)
{
fprintf(stderr, ERL_ERROR
": The caPutLog module is configured for JSON put-logging,\n"
" only caPutJsonLog* commands are available. To use the plain\n"
" put-log format rebuild this IOC with 'caPutLog.dbd' instead\n"
" of 'caPutJsonLog.dbd'.\n");
#ifdef IOCSHFUNCDEF_HAS_USAGE
iocshSetError(-1);
#endif
}

/* Register IOCsh commands */
/* Register JSON IOCsh commands */
static void caPutJsonLogRegister(void)
{
static int done = FALSE;
if(done) return;
done = TRUE;
extern int caPutLogRegisterDone;

switch (caPutLogRegisterDone) {
case 0:
iocshRegister(&caPutJsonLogInitDef,caPutJsonLogInitCall);
iocshRegister(&caPutJsonLogReconfDef,caPutJsonLogReconfCall);
iocshRegister(&caPutJsonLogShowDef,caPutJsonLogShowCall);
iocshRegister(&caPutLogInitDef,caPutLogInitCall);
caPutLogRegisterDone = 2;
break;

case 1:
errlogPrintf(ERL_WARNING
": Registration of caPutJsonLog commands skipped, as\n"
" the caPutLog commands have already been registered.\n"
" This IOC may have been built with both 'caPutJsonLog.dbd'\n"
" and 'caPutLog.dbd', please rebuild it using only one.\n");
break;

iocshRegister(&caPutjsonLogInitDef,caPutJsonLogInitCall);
iocshRegister(&caPutJsonLogReconfDef,caPutJsonLogReconfCall);
iocshRegister(&caPutJsonLogShowDef,caPutJsonLogShowCall);
case 2:
// Second registration, no problem
break;
}
}
epicsExportRegistrar(caPutJsonLogRegister);

Expand Down
2 changes: 2 additions & 0 deletions caPutLogApp/caPutLogAs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#include "caPutLogTask.h"
#include "caPutLogAs.h"

int caPutLogRegisterDone = 0;

static asTrapWriteId listenerId = 0;

static void *logDataFreeList = 0;
Expand Down
55 changes: 47 additions & 8 deletions caPutLogApp/caPutLogShellCommands.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#include <stdio.h>

#include <dbDefs.h>
#include <errlog.h>
#include <iocsh.h>
#include <epicsExport.h>

#include "caPutLog.h"

/* Use colored ERROR/WARNING text if available */
#ifndef ERL_ERROR
# define ERL_ERROR "ERROR"
# define ERL_WARNING "WARNING"
#endif

static const iocshArg caPutLogInitArg0 = {"address", iocshArgString};
static const iocshArg caPutLogInitArg1 = {"config", iocshArgInt};
static const iocshArg *const caPutLogInitArgs[] = {
Expand Down Expand Up @@ -46,15 +55,45 @@ static void caPutLogSetTimeFmtCall(const iocshArgBuf *args)
caPutLogSetTimeFmt(args[0].sval);
}

/* Error message if caPutJsonLogInit used */
static const iocshFuncDef caPutJsonLogInitDef = {"caPutJsonLogInit", 0, NULL};
static void caPutJsonLogInitCall(const iocshArgBuf *args)
{
fprintf(stderr, ERL_ERROR
": The caPutLog module is configured for plain put-logging,\n"
" only caPutLog* commands are available. To use the new JSON\n"
" put-log format rebuild this IOC with 'caPutJsonLog.dbd'\n"
" instead of 'caPutLog.dbd'.\n");
#ifdef IOCSHFUNCDEF_HAS_USAGE
iocshSetError(-1);
#endif
}

static void caPutLogRegister(void)
{
static int done = FALSE;

if(done) return;
done = TRUE;
iocshRegister(&caPutLogInitDef,caPutLogInitCall);
iocshRegister(&caPutLogReconfDef,caPutLogReconfCall);
iocshRegister(&caPutLogShowDef,caPutLogShowCall);
iocshRegister(&caPutLogSetTimeFmtDef,caPutLogSetTimeFmtCall);
extern int caPutLogRegisterDone;

switch (caPutLogRegisterDone) {
case 0:
iocshRegister(&caPutLogInitDef,caPutLogInitCall);
iocshRegister(&caPutLogReconfDef,caPutLogReconfCall);
iocshRegister(&caPutLogShowDef,caPutLogShowCall);
iocshRegister(&caPutLogSetTimeFmtDef,caPutLogSetTimeFmtCall);
iocshRegister(&caPutJsonLogInitDef,caPutJsonLogInitCall);
caPutLogRegisterDone = 1;
break;

case 1:
/* Second registration, no problem */
break;

case 2:
errlogPrintf(ERL_WARNING
": Registration of caPutLog commands skipped, as\n"
" the caPutJsonLog commands have already been registered.\n"
" This IOC may have been built with both 'caPutJsonLog.dbd'\n"
" and 'caPutLog.dbd', please rebuild it using only one.\n");
break;
}
}
epicsExportRegistrar(caPutLogRegister);
Loading