This is Unofficial EPICS BASE Doxygen Site
epics::pvAccess::ChannelSearchManager Class Reference

#include "channelSearchManager.h"

+ Inheritance diagram for epics::pvAccess::ChannelSearchManager:
+ Collaboration diagram for epics::pvAccess::ChannelSearchManager:

Public Member Functions

 POINTER_DEFINITIONS (ChannelSearchManager)
 
virtual ~ChannelSearchManager ()
 
void cancel ()
 
int32_t registeredCount ()
 
void registerSearchInstance (SearchInstance::shared_pointer const &channel, bool penalize=false)
 
void unregisterSearchInstance (SearchInstance::shared_pointer const &channel)
 
void searchResponse (const ServerGUID &guid, pvAccessID cid, int32_t seqNo, int8_t minorRevision, osiSockAddr *serverAddress)
 
void newServerDetected ()
 
virtual void callback () OVERRIDE FINAL
 Timer callback. More...
 
virtual void timerStopped () OVERRIDE FINAL
 Timer stooped callback. More...
 
 ChannelSearchManager (Context::shared_pointer const &context)
 
void activate ()
 
- Public Member Functions inherited from epics::pvData::TimerCallback
 POINTER_DEFINITIONS (TimerCallback)
 
 TimerCallback ()
 
virtual ~TimerCallback ()
 

Detailed Description

Definition at line 54 of file channelSearchManager.h.

Constructor & Destructor Documentation

epics::pvAccess::ChannelSearchManager::~ChannelSearchManager ( )
virtual

Definition at line 107 of file channelSearchManager.cpp.

108 {
109  Lock guard(m_mutex);
110  if (!m_canceled.get()) {
111  LOG(logLevelWarn, "Logic error: ChannelSearchManager destroyed w/o cancel()");
112  }
113 }
A lock for multithreading.
Definition: lock.h:36
#define LOG(level, format,...)
Definition: logger.h:48
epics::pvAccess::ChannelSearchManager::ChannelSearchManager ( Context::shared_pointer const &  context)

Private constructor.

Parameters
context

Definition at line 76 of file channelSearchManager.cpp.

76  :
77  m_context(context),
78  m_responseAddress(), // initialized in activate()
79  m_canceled(),
80  m_sequenceNumber(0),
81  m_sendBuffer(MAX_UDP_UNFRAGMENTED_SEND),
82  m_channels(),
83  m_lastTimeSent(),
84  m_channelMutex(),
85  m_userValueMutex(),
86  m_mutex()
87 {
88  // initialize random seed with some random value
89  srand ( time(NULL) );
90 }
#define NULL
Definition: catime.c:38
const epics::pvData::int32 MAX_UDP_UNFRAGMENTED_SEND
Definition: pvaConstants.h:55

Member Function Documentation

void epics::pvAccess::ChannelSearchManager::activate ( )

Definition at line 92 of file channelSearchManager.cpp.

93 {
94  m_responseAddress = Context::shared_pointer(m_context)->getSearchTransport()->getRemoteAddress();
95 
96  // initialize send buffer
97  initializeSendBuffer();
98 
99  // add some jitter so that all the clients do not send at the same time
100  double period = ATOMIC_PERIOD + double(rand())/RAND_MAX*PERIOD_JITTER_MS;
101 
102  Context::shared_pointer context(m_context.lock());
103  if (context)
104  context->getTimer()->schedulePeriodic(shared_from_this(), period, period);
105 }
void epics::pvAccess::ChannelSearchManager::callback ( )
virtual

Timer callback.

Implements epics::pvData::TimerCallback.

Definition at line 317 of file channelSearchManager.cpp.

318 {
319  // high-frequency beacon anomaly trigger guard
320  {
321  Lock guard(m_mutex);
322 
324  now.getCurrent();
325  int64_t nowMS = now.getMilliseconds();
326 
327  if (nowMS - m_lastTimeSent < 100)
328  return;
329  m_lastTimeSent = nowMS;
330  }
331 
332 
333  int count = 0;
334  int frameSent = 0;
335 
336  vector<SearchInstance::shared_pointer> toSend;
337  {
338  Lock guard(m_channelMutex);
339  toSend.reserve(m_channels.size());
340 
341  for(m_channels_t::iterator channelsIter = m_channels.begin();
342  channelsIter != m_channels.end(); channelsIter++)
343  {
344  SearchInstance::shared_pointer inst(channelsIter->second.lock());
345  if(!inst) continue;
346  toSend.push_back(inst);
347  }
348  }
349 
350  vector<SearchInstance::shared_pointer>::iterator siter = toSend.begin();
351  for (; siter != toSend.end(); siter++)
352  {
353  bool skip;
354  {
355  epicsGuard<epicsMutex> G(m_userValueMutex);
356  int32_t& countValue = (*siter)->getUserValue();
357  skip = !isPowerOfTwo(countValue);
358 
359  if (countValue >= MAX_COUNT_VALUE)
360  countValue = MAX_FALLBACK_COUNT_VALUE;
361  else
362  countValue++;
363  }
364 
365  // back-off
366  if (skip)
367  continue;
368 
369  count++;
370 
371  if (generateSearchRequestMessage(*siter, true, false))
372  frameSent++;
373  if (frameSent == MAX_FRAMES_AT_ONCE)
374  {
375  epicsThreadSleep(DELAY_BETWEEN_FRAMES_MS/(double)1000.0);
376  frameSent = 0;
377  }
378  }
379 
380  if (count > 0)
381  flushSendBuffer();
382 }
A lock for multithreading.
Definition: lock.h:36
LIBCOM_API void epicsStdCall epicsThreadSleep(double seconds)
Block the calling thread for at least the specified time.
Definition: osdThread.c:790
Methods for manipulating timeStamp.
Definition: timeStamp.h:43
void epics::pvAccess::ChannelSearchManager::cancel ( )

Cancel.

Definition at line 115 of file channelSearchManager.cpp.

116 {
117  Lock guard(m_mutex);
118 
119  if (m_canceled.get())
120  return;
121  m_canceled.set();
122 
123  Context::shared_pointer context(m_context.lock());
124  if (context)
125  context->getTimer()->cancel(shared_from_this());
126 }
A lock for multithreading.
Definition: lock.h:36
void epics::pvAccess::ChannelSearchManager::newServerDetected ( )

New server detected. Boost searching of all channels.

Definition at line 194 of file channelSearchManager.cpp.

195 {
196  boost();
197  callback();
198 }
Definition: assert.hpp:91
virtual void callback() OVERRIDE FINAL
Timer callback.
epics::pvAccess::ChannelSearchManager::POINTER_DEFINITIONS ( ChannelSearchManager  )
int32_t epics::pvAccess::ChannelSearchManager::registeredCount ( )

Get number of registered channels.

Returns
number of registered channels.

Definition at line 128 of file channelSearchManager.cpp.

129 {
130  Lock guard(m_channelMutex);
131  return static_cast<int32_t>(m_channels.size());
132 }
A lock for multithreading.
Definition: lock.h:36
void epics::pvAccess::ChannelSearchManager::registerSearchInstance ( SearchInstance::shared_pointer const &  channel,
bool  penalize = false 
)

Register channel.

Parameters
channelto register.

Definition at line 134 of file channelSearchManager.cpp.

135 {
136  if (m_canceled.get())
137  return;
138 
139  bool immediateTrigger;
140  {
141  Lock guard(m_channelMutex);
142 
143  // overrides if already registered
144  m_channels[channel->getSearchInstanceID()] = channel;
145  immediateTrigger = (m_channels.size() == 1);
146 
147  Lock guard2(m_userValueMutex);
148  int32_t& userValue = channel->getUserValue();
149  userValue = (penalize ? MAX_FALLBACK_COUNT_VALUE : DEFAULT_USER_VALUE);
150  }
151 
152  if (immediateTrigger)
153  callback();
154 }
A lock for multithreading.
Definition: lock.h:36
virtual void callback() OVERRIDE FINAL
Timer callback.
void epics::pvAccess::ChannelSearchManager::searchResponse ( const ServerGUID guid,
pvAccessID  cid,
int32_t  seqNo,
int8_t  minorRevision,
osiSockAddr serverAddress 
)

Search response from server (channel found).

Parameters
guidserver GUID.
cidclient channel ID.
seqNosearch sequence number.
minorRevisionserver minor PVA revision.
serverAddressserver address.

Definition at line 163 of file channelSearchManager.cpp.

164 {
165  Lock guard(m_channelMutex);
166  m_channels_t::iterator channelsIter = m_channels.find(cid);
167  if(channelsIter == m_channels.end())
168  {
169  guard.unlock();
170  Context::shared_pointer ctxt(m_context.lock());
171  // TODO: proper action if !ctxt???
172  if(!ctxt) return;
173 
174  // enable duplicate reports
175  SearchInstance::shared_pointer si = std::tr1::dynamic_pointer_cast<SearchInstance>(ctxt->getChannel(cid));
176  if (si)
177  si->searchResponse(guid, minorRevision, serverAddress);
178  }
179  else
180  {
181  SearchInstance::shared_pointer si(channelsIter->second.lock());
182 
183  // remove from search list
184  m_channels.erase(cid);
185 
186  guard.unlock();
187 
188  // then notify SearchInstance
189  if(si)
190  si->searchResponse(guid, minorRevision, serverAddress);
191  }
192 }
A lock for multithreading.
Definition: lock.h:36
shared_ptr< T > dynamic_pointer_cast(shared_ptr< U > const &r) BOOST_NOEXCEPT
Definition: shared_ptr.hpp:808
void epics::pvAccess::ChannelSearchManager::timerStopped ( )
virtual

Timer stooped callback.

Implements epics::pvData::TimerCallback.

Definition at line 389 of file channelSearchManager.cpp.

390 {
391 }
void epics::pvAccess::ChannelSearchManager::unregisterSearchInstance ( SearchInstance::shared_pointer const &  channel)

Unregister channel.

Parameters
channelto unregister.

Definition at line 156 of file channelSearchManager.cpp.

157 {
158  Lock guard(m_channelMutex);
159  pvAccessID id = channel->getSearchInstanceID();
160  m_channels.erase(id);
161 }
epicsInt32 pvAccessID
Definition: pvaDefs.h:18
A lock for multithreading.
Definition: lock.h:36

The documentation for this class was generated from the following files: