This is Unofficial EPICS BASE Doxygen Site
decimate.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2019 UChicago Argonne LLC, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2010 Brookhaven National Laboratory.
5 * Copyright (c) 2010 Helmholtz-Zentrum Berlin
6 * fuer Materialien und Energie GmbH.
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /*
12  * Authors: Ralph Lange <Ralph.Lange@bessy.de>,
13  * Andrew Johnson <anj@anl.gov>
14  */
15 
16 #include <stdio.h>
17 
18 #include "freeList.h"
19 #include "db_field_log.h"
20 #include "chfPlugin.h"
21 #include "epicsExport.h"
22 
23 typedef struct myStruct {
25 } myStruct;
26 
27 static void *myStructFreeList;
28 
29 static const
30 chfPluginArgDef opts[] = {
31  chfInt32(myStruct, n, "n", 1, 0),
32  chfPluginArgEnd
33 };
34 
35 static void * allocPvt(void)
36 {
37  myStruct *my = (myStruct*) freeListCalloc(myStructFreeList);
38  return (void *) my;
39 }
40 
41 static void freePvt(void *pvt)
42 {
43  freeListFree(myStructFreeList, pvt);
44 }
45 
46 static int parse_ok(void *pvt)
47 {
48  myStruct *my = (myStruct*) pvt;
49 
50  if (my->n < 1)
51  return -1;
52 
53  return 0;
54 }
55 
56 static db_field_log* filter(void* pvt, dbChannel *chan, db_field_log *pfl) {
57  db_field_log *passfl = NULL;
58  myStruct *my = (myStruct*) pvt;
59  epicsInt32 i = my->i;
60 
61  if (pfl->ctx == dbfl_context_read)
62  return pfl;
63 
64  if (i++ == 0)
65  passfl = pfl;
66  else
67  db_delete_field_log(pfl);
68 
69  if (i >= my->n)
70  i = 0;
71 
72  my->i = i;
73  return passfl;
74 }
75 
76 static void channelRegisterPre(dbChannel *chan, void *pvt,
77  chPostEventFunc **cb_out, void **arg_out, db_field_log *probe)
78 {
79  *cb_out = filter;
80  *arg_out = pvt;
81 }
82 
83 static void channel_report(dbChannel *chan, void *pvt, int level, const unsigned short indent)
84 {
85  myStruct *my = (myStruct*) pvt;
86  printf("%*sDecimate (dec): n=%d, i=%d\n", indent, "",
87  my->n, my->i);
88 }
89 
90 static chfPluginIf pif = {
91  allocPvt,
92  freePvt,
93 
94  NULL, /* parse_error, */
95  parse_ok,
96 
97  NULL, /* channel_open, */
98  channelRegisterPre,
99  NULL, /* channelRegisterPost, */
100  channel_report,
101  NULL /* channel_close */
102 };
103 
104 static void decInitialize(void)
105 {
106  static int firstTime = 1;
107 
108  if (!firstTime) return;
109  firstTime = 0;
110 
111  if (!myStructFreeList)
112  freeListInitPvt(&myStructFreeList, sizeof(myStruct), 64);
113 
114  chfPluginRegister("dec", &pif, opts);
115 }
116 
117 epicsExportRegistrar(decInitialize);
LIBCOM_API void *epicsStdCall freeListCalloc(void *pvt)
Definition: freeListLib.c:60
Definition: arr.c:26
epicsInt32 i
Definition: decimate.c:24
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
epicsInt32 n
Definition: decimate.c:24
LIBCOM_API void epicsStdCall freeListInitPvt(void **ppvt, int size, int nmalloc)
Definition: freeListLib.c:44
struct myStruct myStruct
epicsExportRegistrar(decInitialize)
LIBCOM_API void epicsStdCall freeListFree(void *pvt, void *pmem)
Definition: freeListLib.c:131
int epicsInt32
Definition: epicsTypes.h:42
Exporting IOC objects.