pvAccessCPP  7.1.1
channelSearchManager.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 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 
32  /**
33  * Destructor
34  */
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 
43  /**
44  * Search response from server (channel found).
45  * @param guid server GUID.
46  * @param minorRevision server minor PVA revision.
47  * @param serverAddress server address.
48  */
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();
62  /**
63  * Cancel.
64  */
65  void cancel();
66  /**
67  * Get number of registered channels.
68  * @return number of registered channels.
69  */
70  int32_t registeredCount();
71  /**
72  * Register channel.
73  * @param channel to register.
74  */
75  void registerSearchInstance(SearchInstance::shared_pointer const & channel, bool penalize = false);
76  /**
77  * Unregister channel.
78  * @param channel to unregister.
79  */
80  void unregisterSearchInstance(SearchInstance::shared_pointer const & channel);
81  /**
82  * Search response from server (channel found).
83  * @param guid server GUID.
84  * @param cid client channel ID.
85  * @param seqNo search sequence number.
86  * @param minorRevision server minor PVA revision.
87  * @param serverAddress server address.
88  */
89  void searchResponse(const ServerGUID & guid, pvAccessID cid, int32_t seqNo, int8_t minorRevision, osiSockAddr* serverAddress);
90  /**
91  * New server detected.
92  * Boost searching of all channels.
93  */
94  void newServerDetected();
95 
96  /// Timer callback.
97  virtual void callback() OVERRIDE FINAL;
98 
99  /// Timer stooped callback.
100  virtual void timerStopped() OVERRIDE FINAL;
101 
102  /**
103  * Private constructor.
104  * @param context
105  */
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 
123  /**
124  * Context.
125  */
126  Context::weak_pointer m_context;
127 
128  /**
129  * Response address.
130  */
131  osiSockAddr m_responseAddress;
132 
133  /**
134  * Canceled flag.
135  */
136  AtomicBoolean m_canceled;
137 
138  /**
139  * Search (datagram) sequence number.
140  */
141  int32_t m_sequenceNumber;
142 
143  /**
144  * Send byte buffer (frame)
145  */
146  epics::pvData::ByteBuffer m_sendBuffer;
147 
148  /**
149  * Set of registered channels.
150  */
151  typedef std::map<pvAccessID,SearchInstance::weak_pointer> m_channels_t;
152  m_channels_t m_channels;
153 
154  /**
155  * Time of last frame send.
156  */
157  int64_t m_lastTimeSent;
158 
159  /**
160  * This instance mutex.
161  */
162  epics::pvData::Mutex m_channelMutex;
163 
164  /**
165  * User value lock.
166  */
167  epics::pvData::Mutex m_userValueMutex;
168 
169  /**
170  * m_channels mutex.
171  */
172  epics::pvData::Mutex m_mutex;
173 };
174 
175 }
176 }
177 
178 #endif
virtual void authNZMessage(epics::pvData::PVStructure::shared_pointer const &data)=0
Pass data to the active security plug-in session.
#define OVERRIDE
Definition: pvAccess.h:55
#define FINAL
Copyright - See the COPYRIGHT that is included with this distribution.
Definition: pvAccess.h:48