pvAccessCPP  7.1.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
channelSearchManager.h
1 
7 #ifndef CHANNELSEARCHMANAGER_H
8 #define CHANNELSEARCHMANAGER_H
9 
10 #ifdef epicsExportSharedSymbols
11 # define channelSearchManagerEpicsExportSharedSymbols
12 # undef epicsExportSharedSymbols
13 #endif
14 
15 #include <osiSock.h>
16 
17 #ifdef channelSearchManagerEpicsExportSharedSymbols
18 # define epicsExportSharedSymbols
19 # undef channelSearchManagerEpicsExportSharedSymbols
20 #endif
21 
22 #include <pv/pvaDefs.h>
23 #include <pv/remote.h>
24 
25 namespace epics {
26 namespace pvAccess {
27 
28 class SearchInstance {
29 public:
30  POINTER_DEFINITIONS(SearchInstance);
31 
35  virtual ~SearchInstance() {}
36 
37  virtual pvAccessID getSearchInstanceID() = 0;
38 
39  virtual const std::string& getSearchInstanceName() = 0;
40 
41  virtual int32_t& getUserValue() = 0;
42 
49  // TODO make serverAddress an URI or similar
50  virtual void searchResponse(const ServerGUID & guid, int8_t minorRevision, osiSockAddr* serverAddress) = 0;
51 };
52 
53 
54 class ChannelSearchManager :
55  public epics::pvData::TimerCallback,
56  public std::tr1::enable_shared_from_this<ChannelSearchManager>
57 {
58 public:
59  POINTER_DEFINITIONS(ChannelSearchManager);
60 
61  virtual ~ChannelSearchManager();
65  void cancel();
70  int32_t registeredCount();
75  void registerSearchInstance(SearchInstance::shared_pointer const & channel, bool penalize = false);
80  void unregisterSearchInstance(SearchInstance::shared_pointer const & channel);
89  void searchResponse(const ServerGUID & guid, pvAccessID cid, int32_t seqNo, int8_t minorRevision, osiSockAddr* serverAddress);
94  void newServerDetected();
95 
97  virtual void callback() OVERRIDE FINAL;
98 
100  virtual void timerStopped() OVERRIDE FINAL;
101 
106  ChannelSearchManager(Context::shared_pointer const & context);
107  void activate();
108 
109 private:
110 
111  bool generateSearchRequestMessage(SearchInstance::shared_pointer const & channel, bool allowNewFrame, bool flush);
112 
113  static bool generateSearchRequestMessage(SearchInstance::shared_pointer const & channel,
114  epics::pvData::ByteBuffer* byteBuffer, TransportSendControl* control);
115 
116  void boost();
117 
118  void initializeSendBuffer();
119  void flushSendBuffer();
120 
121  static bool isPowerOfTwo(int32_t x);
122 
126  Context::weak_pointer m_context;
127 
131  osiSockAddr m_responseAddress;
132 
136  AtomicBoolean m_canceled;
137 
141  int32_t m_sequenceNumber;
142 
146  epics::pvData::ByteBuffer m_sendBuffer;
147 
151  typedef std::map<pvAccessID,SearchInstance::weak_pointer> m_channels_t;
152  m_channels_t m_channels;
153 
157  int64_t m_lastTimeSent;
158 
162  epics::pvData::Mutex m_channelMutex;
163 
167  epics::pvData::Mutex m_userValueMutex;
168 
172  epics::pvData::Mutex m_mutex;
173 };
174 
175 }
176 }
177 
178 #endif