Skip to content

Commit e7a3efb

Browse files
mdavidsaverralphlange
authored andcommitted
unconditional JSON
Support yajl_gen circa 3.15 remove vestiges of 3.14 support
1 parent ffaa002 commit e7a3efb

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

caPutLogApp/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,11 @@ INC += caPutLogAs.h
2828
DBD += caPutLog.dbd
2929

3030
# Add support for json format and arrays
31-
# This requires EPICS base version 7.0.1 or higher
32-
ifdef BASE_7_0
3331
USR_CPPFLAGS += -DJSON_AND_ARRAYS_SUPPORTED
3432
caPutLog_SRCS += caPutJsonLogTask.cpp
3533
caPutLog_SRCS += caPutJsonLogShellCommands.cpp
3634
INC += caPutJsonLogTask.h
3735
DBD += caPutJsonLog.dbd
38-
endif
3936

4037

4138
caPutLog_LIBS += $(EPICS_BASE_IOC_LIBS)

caPutLogApp/caPutJsonLogTask.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include <asLib.h>
3131
#include <logClient.h>
3232
#include <epicsThread.h>
33+
#include <epicsMutex.h>
34+
#include <epicsGuard.h>
3335
#include <epicsAtomic.h>
3436
#include <dbAccessDefs.h>
3537
#include <epicsMath.h>
@@ -43,6 +45,7 @@
4345
#include "caPutLogTask.h"
4446
#include "caPutJsonLogTask.h"
4547

48+
typedef epicsGuard<epicsMutex> guard_t;
4649

4750
#define isDbrNumeric(type) ((type) > DBR_STRING && (type) <= DBR_ENUM)
4851

@@ -78,7 +81,7 @@ CaPutJsonLogTask::CaPutJsonLogTask()
7881
CaPutJsonLogTask::~CaPutJsonLogTask()
7982
{
8083
clientItem *client, *nextclient;
81-
epicsMutex::guard_t G(clientsMutex);
84+
guard_t G(clientsMutex);
8285
nextclient = clients;
8386
clients = NULL;
8487
while (nextclient) {
@@ -108,7 +111,7 @@ caPutJsonLogStatus CaPutJsonLogTask::report(int level)
108111

109112
if (clients != NULL) {
110113
clientItem *client;
111-
epicsMutex::guard_t G(clientsMutex);
114+
guard_t G(clientsMutex);
112115
for (client = clients; client; client = client->next) {
113116
logClientShow(client->caPutJsonLogClient, level);
114117
}
@@ -254,7 +257,7 @@ caPutJsonLogStatus CaPutJsonLogTask::configureServerLogging(const char* address)
254257
clientItem** pclient;
255258

256259
// Parse the address
257-
epicsMutex::guard_t G(clientsMutex);
260+
guard_t G(clientsMutex);
258261
for (pclient = &clients; *pclient; pclient = &(*pclient)->next) {
259262
if (strcmp(address, (*pclient)->address) == 0) {
260263
fprintf (stderr, "caPutJsonLog: address %s already configured\n", address);
@@ -463,7 +466,11 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const
463466
}
464467

465468
// Configure yajl generator
466-
yajl_gen handle = yajl_gen_alloc(NULL);
469+
yajl_gen handle = yajl_gen_alloc(
470+
#ifndef EPICS_YAJL_VERSION
471+
NULL, // v1 yajl_gen_config struct*. v2 switched to yajl_gen_config() function
472+
#endif
473+
NULL);
467474
if (handle == NULL) {
468475
errlogSevPrintf(errlogMinor, "caPutJsonLog: failed to allocate yajl handler\n");
469476
return caPutJsonLogError;
@@ -674,7 +681,12 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const
674681

675682
/* Get JSON as NULL terminated cstring */
676683
const unsigned char * buf;
677-
size_t len = 0;
684+
#ifdef EPICS_YAJL_VERSION
685+
size_t
686+
#else
687+
unsigned int
688+
#endif
689+
len = 0;
678690
yajl_gen_get_buf(handle, &buf, &len);
679691

680692
/* Get a JSON as a string */
@@ -690,7 +702,7 @@ caPutJsonLogStatus CaPutJsonLogTask::buildJsonMsg(const VALUE *pold_value, const
690702
void CaPutJsonLogTask::logToServer(std::string &msg)
691703
{
692704
clientItem* client;
693-
epicsMutex::guard_t G(clientsMutex);
705+
guard_t G(clientsMutex);
694706
for (client = clients; client; client = client->next) {
695707
logClientSend (client->caPutJsonLogClient, msg.c_str());
696708
}
@@ -742,19 +754,22 @@ void CaPutJsonLogTask::calculateMin(VALUE *pres, const VALUE *pa, const VALUE *p
742754
case DBR_ULONG:
743755
pres->v_uint32 = std::min(pa->v_uint32, pb->v_uint32);
744756
return;
757+
#ifdef DBR_INT64
745758
case DBR_INT64:
746759
pres->v_int64 = std::min(pa->v_int64, pb->v_int64);
747760
return;
748761
case DBR_UINT64:
749762
pres->v_uint64 = std::min(pa->v_uint64, pb->v_uint64);
750763
return;
764+
#endif
751765
case DBR_FLOAT:
752766
pres->v_float = std::min(pa->v_float, pb->v_float);
753767
return;
754768
case DBR_DOUBLE:
755769
pres->v_double = std::min(pa->v_double, pb->v_double);
756770
return;
757771
}
772+
memset(pres, 0, sizeof(*pres));
758773
}
759774

760775
void CaPutJsonLogTask::calculateMax(VALUE *pres, const VALUE *pa, const VALUE *pb, short type)
@@ -779,19 +794,22 @@ void CaPutJsonLogTask::calculateMax(VALUE *pres, const VALUE *pa, const VALUE *p
779794
case DBR_ULONG:
780795
pres->v_uint32 = std::max(pa->v_uint32, pb->v_uint32);
781796
return;
797+
#ifdef DBR_INT64
782798
case DBR_INT64:
783799
pres->v_int64 = std::max(pa->v_int64, pb->v_int64);
784800
return;
785801
case DBR_UINT64:
786802
pres->v_uint64 = std::max(pa->v_uint64, pb->v_uint64);
787803
return;
804+
#endif
788805
case DBR_FLOAT:
789806
pres->v_float = std::max(pa->v_float, pb->v_float);
790807
return;
791808
case DBR_DOUBLE:
792809
pres->v_double = std::max(pa->v_double, pb->v_double);
793810
return;
794811
}
812+
memset(pres, 0, sizeof(*pres));
795813
}
796814

797815
#define SINGLE_TYPE_COMPARE(_t, _s) \
@@ -860,10 +878,12 @@ int CaPutJsonLogTask::fieldVal2Str(char *pbuf, size_t buflen, const VALUE *pval,
860878
case DBR_DOUBLE:
861879
len = epicsSnprintf(pbuf, buflen, "%.17g", ((epicsFloat64 *)pval)[index]);
862880
break;
881+
#ifdef DBR_INT64
863882
case DBR_INT64:
864883
return epicsSnprintf(pbuf, buflen, "%lld", ((epicsInt64 *)pval)[index]);
865884
case DBR_UINT64:
866885
return epicsSnprintf(pbuf, buflen, "%llu", ((epicsUInt64 *)pval)[index]);
886+
#endif
867887
case DBR_STRING:
868888
return epicsSnprintf(pbuf, buflen, "%s", ((char *)pval) + index * MAX_STRING_SIZE);
869889
default:

caPutLogApp/caPutLogAs.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ static void caPutLogAs(asTrapWriteMessage *pmessage, int afterPut)
189189

190190
int caPutLogMaxArraySize(short type)
191191
{
192-
#if !JSON_AND_ARRAYS_SUPPORTED
193-
return 1;
194-
#else
195192
static int const arraySizeLookUpTable [] = {
196193
MAX_ARRAY_SIZE_BYTES/MAX_STRING_SIZE, /* DBR_STRING */
197194
MAX_ARRAY_SIZE_BYTES/sizeof(epicsInt8), /* DBR_CHAR */
@@ -213,7 +210,6 @@ int caPutLogMaxArraySize(short type)
213210
errlogSevPrintf(errlogMajor, "caPutLogAs: Array size for type %d can not be determind\n", type);
214211
return 1;
215212
}
216-
#endif
217213
}
218214

219215
long caPutLogActualArraySize(dbAddr * paddr)

caPutLogApp/caPutLogTask.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ extern "C" {
1212
#define MAX_USERID_SIZE 32
1313
#define MAX_HOSTID_SIZE 256
1414

15-
#if JSON_AND_ARRAYS_SUPPORTED
1615
#define MAX_ARRAY_SIZE_BYTES 400
17-
#else
18-
#define MAX_ARRAY_SIZE_BYTES 0
19-
#endif
2016

2117
#define DEFAULT_BURST_TIMEOUT 5.0
2218

@@ -35,7 +31,7 @@ typedef union {
3531
epicsFloat64 v_double;
3632
char v_string[MAX_STRING_SIZE];
3733

38-
#if JSON_AND_ARRAYS_SUPPORTED
34+
char a_bytes[MAX_ARRAY_SIZE_BYTES];
3935
epicsInt8 a_int8[MAX_ARRAY_SIZE_BYTES/sizeof(epicsInt8)];
4036
epicsUInt8 a_uint8[MAX_ARRAY_SIZE_BYTES/sizeof(epicsUInt8)];
4137
epicsInt16 a_int16[MAX_ARRAY_SIZE_BYTES/sizeof(epicsInt16)];
@@ -47,7 +43,6 @@ typedef union {
4743
epicsFloat32 a_float[MAX_ARRAY_SIZE_BYTES/sizeof(epicsFloat32)];
4844
epicsFloat64 a_double[MAX_ARRAY_SIZE_BYTES/sizeof(epicsFloat64)];
4945
char a_string[MAX_ARRAY_SIZE_BYTES/MAX_STRING_SIZE][MAX_STRING_SIZE];
50-
#endif
5146
} VALUE;
5247

5348
typedef struct {

0 commit comments

Comments
 (0)