This is Unofficial EPICS BASE Doxygen Site
online_notify.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 /*
11  * tell CA clients this a server has joined the network
12  *
13  * Author: Jeffrey O. Hill
14  * hill@luke.lanl.gov
15  * (505) 665 1831
16  * Date: 103090
17  *
18  */
19 
20 #include <stddef.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <cantProceed.h>
26 
27 #include "addrList.h"
28 #include "dbDefs.h"
29 #include "envDefs.h"
30 #include "errlog.h"
31 #include "osiSock.h"
32 #include "taskwd.h"
33 
34 #define epicsExportSharedSymbols
35 #include "server.h"
36 
37 /*
38  * RSRV_ONLINE_NOTIFY_TASK
39  */
40 void rsrv_online_notify_task(void *pParm)
41 {
42  double delay;
43  double maxdelay;
44  long longStatus;
45  double maxPeriod;
46  caHdr msg;
47  int status;
48  ca_uint32_t beaconCounter = 0;
49  int *lastError;
50 
52 
54  longStatus = envGetDoubleConfigParam ( & EPICS_CAS_BEACON_PERIOD, & maxPeriod );
55  }
56  else {
57  longStatus = envGetDoubleConfigParam ( & EPICS_CA_BEACON_PERIOD, & maxPeriod );
58  }
59  if (longStatus || maxPeriod<=0.0) {
60  maxPeriod = 15.0;
61  epicsPrintf ("EPICS \"%s\" float fetch failed\n",
63  epicsPrintf ("Setting \"%s\" = %f\n",
64  EPICS_CAS_BEACON_PERIOD.name, maxPeriod);
65  }
66 
67  delay = 0.02; /* initial beacon period in sec */
68  maxdelay = maxPeriod;
69 
70  memset((char *)&msg, 0, sizeof msg);
71  msg.m_cmmd = htons (CA_PROTO_RSRV_IS_UP);
72  msg.m_count = htons (ca_server_port);
74 
75  /* beaconAddrList should not change after rsrv_init(), which then starts this thread */
76  lastError = callocMustSucceed(ellCount(&beaconAddrList), sizeof(*lastError), "rsrv_online_notify_task lastError");
77 
79 
80  while (TRUE) {
81  ELLNODE *cur;
82  unsigned i;
83 
84  /* send beacon to each interface */
85  for(i=0, cur=ellFirst(&beaconAddrList); cur; i++, cur=ellNext(cur))
86  {
88  status = sendto (beaconSocket, (char *)&msg, sizeof(msg), 0,
89  &pAddr->addr.sa, sizeof(pAddr->addr));
90  if (status < 0) {
91  int err = SOCKERRNO;
92  if(err != lastError[i]) {
93  char sockErrBuf[64];
94  char sockDipBuf[22];
95 
96  epicsSocketConvertErrorToString(sockErrBuf, sizeof(sockErrBuf), err);
97  ipAddrToDottedIP(&pAddr->addr.ia, sockDipBuf, sizeof(sockDipBuf));
98  errlogPrintf ( "CAS: CA beacon send to %s error: %s\n",
99  sockDipBuf, sockErrBuf);
100 
101  lastError[i] = err;
102  }
103  }
104  else {
105  assert (status == sizeof(msg));
106  if(lastError[i]) {
107  char sockDipBuf[22];
108 
109  ipAddrToDottedIP(&pAddr->addr.ia, sockDipBuf, sizeof(sockDipBuf));
110  errlogPrintf ( "CAS: CA beacon send to %s ok\n",
111  sockDipBuf);
112  }
113  lastError[i] = 0;
114  }
115  }
116 
117  epicsThreadSleep(delay);
118  if (delay<maxdelay) {
119  delay *= 2.0;
120  if (delay>maxdelay) {
121  delay = maxdelay;
122  }
123  }
124 
125  msg.m_cid = htonl ( beaconCounter++ ); /* expected to overflow */
126 
127  while (beacon_ctl == ctlPause) {
128  epicsThreadSleep(0.1);
129  delay = 0.02; /* Restart beacon timing if paused */
130  }
131  }
132 
133  free(lastError);
134 }
135 
136 
void taskwdInsert(epicsThreadId tid, TASKWDFUNC callback, void *usr)
Definition: taskwd.c:176
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
#define ellCount(PLIST)
Report the number of nodes in a list.
Definition: ellLib.h:84
osiSockAddr addr
Definition: osiSock.h:163
pvd::Status status
LIBCOM_API const ENV_PARAM EPICS_CA_BEACON_PERIOD
deprecated
char * name
Name of the parameter.
Definition: envDefs.h:42
#define CONTAINER(ptr, structure, member)
Find parent object from a member pointer.
Definition: dbDefs.h:66
int i
Definition: scan.c:967
LIBCOM_API const char *epicsStdCall envGetConfigParamPtr(const ENV_PARAM *pParam)
Get a configuration parameter&#39;s value or default string.
Definition: envSubr.c:81
struct sockaddr sa
Definition: osiSock.h:158
GLBLTYPE SOCKET beaconSocket
Definition: server.h:195
struct sockaddr_in ia
Definition: osiSock.h:157
Routines to get and set EPICS environment parameters.
void rsrv_online_notify_task(void *pParm)
Definition: online_notify.c:40
unsigned int ca_uint32_t
Definition: caProto.h:76
#define NULL
Definition: catime.c:38
Miscellaneous macro definitions.
#define CA_MINOR_PROTOCOL_REVISION
Definition: nciu.h:35
GLBLTYPE ELLLIST beaconAddrList
Definition: server.h:194
ca_uint16_t m_cmmd
Definition: caProto.h:161
#define ellNext(PNODE)
Find the next node in list.
Definition: ellLib.h:99
LIBCOM_API long epicsStdCall envGetDoubleConfigParam(const ENV_PARAM *pParam, double *pDouble)
Get value of a double configuration parameter.
Definition: envSubr.c:191
#define epicsEventSignal(ID)
A synonym for epicsEventTrigger().
Definition: epicsEvent.h:172
ca_uint32_t m_cid
Definition: caProto.h:165
#define epicsPrintf
Definition: errlog.h:51
LIBCOM_API const ENV_PARAM EPICS_CAS_BEACON_PERIOD
ca_uint16_t m_dataType
Definition: caProto.h:163
LIBCOM_API void * callocMustSucceed(size_t count, size_t size, const char *msg)
A calloc() that never returns NULL.
Definition: cantProceed.c:22
int errlogPrintf(const char *pFormat,...)
Definition: errlog.c:105
List node type.
Definition: ellLib.h:45
ca_uint16_t m_count
Definition: caProto.h:164
#define SOCKERRNO
Definition: osdSock.h:33
GLBLTYPE enum ctl beacon_ctl
Definition: server.h:213
#define TRUE
Definition: dbDefs.h:27
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
GLBLTYPE unsigned short ca_server_port
Definition: server.h:191
GLBLTYPE epicsEventId beacon_startStopEvent
Definition: server.h:210
Routines for code that can&#39;t continue or return after an error.
ELLNODE node
Definition: server.h:77
#define CA_PROTO_RSRV_IS_UP
Definition: caProto.h:96
void epicsSocketConvertErrorToString(char *pBuf, unsigned bufSize, int theSockError)
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144
#define ellFirst(PLIST)
Find the first node in list.
Definition: ellLib.h:89
LIBCOM_API epicsThreadId epicsStdCall epicsThreadGetIdSelf(void)
Definition: osdThread.c:810