This is Unofficial EPICS BASE Doxygen Site
beaconHandler.cpp
Go to the documentation of this file.
1 
7 #define epicsExportSharedSymbols
8 #include <pv/beaconHandler.h>
9 #include <pv/transportRegistry.h>
10 
11 using namespace std;
12 using namespace epics::pvData;
13 using namespace epics::pvAccess;
14 
15 namespace epics {
16 namespace pvAccess {
17 
18 BeaconHandler::BeaconHandler(Context::shared_pointer const & context,
19  const osiSockAddr* responseFrom) :
20  _context(Context::weak_pointer(context)),
21  _mutex(),
22  _serverGUID(),
23  _serverChangeCount(-1),
24  _first(true)
25 {
26 
27 }
28 
30 {
31 }
32 
33 void BeaconHandler::beaconNotify(osiSockAddr* /*from*/, int8 remoteTransportRevision,
34  TimeStamp* timestamp, ServerGUID const & guid, int16 sequentalID,
35  int16 changeCount,
36  const PVFieldPtr& /*data*/)
37 {
38  bool networkChanged = updateBeacon(remoteTransportRevision, timestamp, guid, sequentalID, changeCount);
39  // TODO: reduce search timers
40  (void)networkChanged;
41 }
42 
43 bool BeaconHandler::updateBeacon(int8 /*remoteTransportRevision*/, TimeStamp* /*timestamp*/,
44  ServerGUID const & guid, int16 /*sequentalID*/, int16 changeCount)
45 {
46  Lock guard(_mutex);
47  // first beacon notification check
48  if (_first)
49  {
50  _first = false;
51  _serverGUID = guid;
52  _serverChangeCount = changeCount;
53 
54  // new server up..
55  _context.lock()->newServerDetected();
56 
57  return false;
58  }
59 
60  bool networkChange = (memcmp(_serverGUID.value, guid.value, sizeof(guid.value)) != 0);
61  if (networkChange)
62  {
63  // update startup time and change count
64  _serverGUID = guid;
65  _serverChangeCount = changeCount;
66 
67  _context.lock()->newServerDetected();
68 
69  return true;
70  }
71  else if (_serverChangeCount != changeCount)
72  {
73  // update change count
74  _serverChangeCount = changeCount;
75 
76  // TODO be more specific (possible optimizations)
77  _context.lock()->newServerDetected();
78 
79  return true;
80  }
81 
82  return false;
83 }
84 
85 }
86 }
int8_t int8
Definition: pvType.h:75
#define true
Definition: flexdef.h:84
Definition: memory.hpp:41
TODO only here because of the Lockable.
Definition: ntaggregate.cpp:16
A lock for multithreading.
Definition: lock.h:36
Holds all PVA related.
Definition: pvif.h:34
pvData
Definition: monitor.h:428
std::tr1::shared_ptr< PVField > PVFieldPtr
Definition: pvData.h:66
int16_t int16
Definition: pvType.h:79
void beaconNotify(osiSockAddr *from, epics::pvData::int8 remoteTransportRevision, epics::pvData::TimeStamp *timestamp, ServerGUID const &guid, epics::pvData::int16 sequentalID, epics::pvData::int16 changeCount, const epics::pvData::PVFieldPtr &data)
Methods for manipulating timeStamp.
Definition: timeStamp.h:43