pvAccessCPP  7.1.6
beaconEmitter.h
1 /**
2  * Copyright - See the COPYRIGHT that is included with this distribution.
3  * pvAccessCPP is distributed subject to a Software License Agreement found
4  * in file LICENSE that is included with this distribution.
5  */
6 
7 #ifndef BEACONEMITTER_H
8 #define BEACONEMITTER_H
9 
10 #ifdef epicsExportSharedSymbols
11 # define beaconEmitterEpicsExportSharedSymbols
12 # undef epicsExportSharedSymbols
13 #endif
14 
15 #include <osiSock.h>
16 
17 #include <pv/timer.h>
18 #include <pv/timeStamp.h>
19 #include <pv/sharedPtr.h>
20 
21 #ifdef beaconEmitterEpicsExportSharedSymbols
22 # define epicsExportSharedSymbols
23 # undef beaconEmitterEpicsExportSharedSymbols
24 #endif
25 
26 #include <pv/remote.h>
27 #include <pv/beaconServerStatusProvider.h>
28 //#include <pv/serverContext.h>
29 
30 namespace epics {
31 namespace pvAccess {
32 
33 class ServerContextImpl;
34 
35 /**
36  * BeaconEmitter
37  *
38  * @author gjansa
39  */
40 class BeaconEmitter:
41  public TransportSender,
42  public epics::pvData::TimerCallback,
43  public std::tr1::enable_shared_from_this<BeaconEmitter>
44 {
45 public:
46  typedef std::tr1::shared_ptr<BeaconEmitter> shared_pointer;
47  typedef std::tr1::shared_ptr<const BeaconEmitter> const_shared_pointer;
48 
49  /**
50  * Constructor.
51  * @param protocol a protocol (transport) name to report.
52  * @param transport transport to be used to send beacons.
53  * @param context PVA context.
54  */
55 // BeaconEmitter(std::sting const & protocol,
56 // Transport::shared_pointer const & transport, ServerContextImpl::shared_pointer const & context);
59 
60  virtual ~BeaconEmitter();
61 
62  void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control);
63 
64  void timerStopped();
65 
66  /**
67  * Start emitting.
68  */
69  void start();
70 
71  /**
72  * Reschedule timer.
73  */
74  void reschedule();
75 
76  /**
77  * Timer callback.
78  */
79  void callback();
80 
81  void destroy();
82 
83 private:
84 
85  /**
86  * Minimal (initial) PVA beacon period (in seconds).
87  */
88  static const float EPICS_PVA_MIN_BEACON_PERIOD;
89 
90  /**
91  * Minimal PVA beacon count limit.
92  */
93  static const float EPICS_PVA_MIN_BEACON_COUNT_LIMIT;
94 
95  /**
96  * Protocol.
97  */
98  const std::string _protocol;
99 
100  /**
101  * Transport.
102  */
103  Transport::shared_pointer _transport;
104 
105  /**
106  * Beacon sequence ID.
107  */
108  epics::pvData::int8 _beaconSequenceID;
109 
110  /**
111  * Server GUID.
112  */
113  const ServerGUID _guid;
114 
115  /**
116  * Fast (at startup) beacon period (in sec).
117  */
118  const double _fastBeaconPeriod;
119 
120  /**
121  * Slow (after beaconCountLimit is reached) beacon period (in sec).
122  */
123  const double _slowBeaconPeriod;
124 
125  /**
126  * Limit on number of beacons issued.
127  */
128  const epics::pvData::int16 _beaconCountLimit;
129 
130  /**
131  * Server address.
132  */
133  const osiSockAddr _serverAddress;
134 
135  /**
136  * Server port.
137  */
138  const epics::pvData::int32 _serverPort;
139 
140  /**
141  * Server status provider implementation (optional).
142  */
143  BeaconServerStatusProvider::shared_pointer _serverStatusProvider;
144 
145  /** Timer is referenced by server context, which also references us.
146  * We will also be queuing ourselves, and be referenced by Timer.
147  * So keep only a weak ref to Timer to avoid possible ref. loop.
148  */
149  epics::pvData::Timer::weak_pointer _timer;
150 };
151 
152 }
153 }
154 
155 #endif /* BEACONEMITTER_H */
void send(epics::pvData::ByteBuffer *buffer, TransportSendControl *control)
Called by transport.
void reschedule()
Reschedule timer.
void start()
Start emitting.
virtual void authNZMessage(epics::pvData::PVStructure::shared_pointer const &data)=0
Pass data to the active security plug-in session.
void callback()
Timer callback.
BeaconEmitter(std::string const &protocol, Transport::shared_pointer const &transport, std::tr1::shared_ptr< ServerContextImpl > &context)
Constructor.