pva2pva 1.4.2
Loading...
Searching...
No Matches
MonitorUser Struct Reference
Inheritance diagram for MonitorUser:
Collaboration diagram for MonitorUser:

Public Member Functions

 POINTER_DEFINITIONS (MonitorUser)
epicsMutex & mutex () const
 MonitorUser (const MonitorCacheEntry::shared_pointer &, const epics::pvData::MonitorRequester::shared_pointer &, const std::tr1::shared_ptr< GWChannel > &)
virtual void destroy ()
virtual epics::pvData::Status start ()
virtual epics::pvData::Status stop ()
virtual epics::pvData::MonitorElementPtr poll ()
virtual void release (epics::pvData::MonitorElementPtr const &monitorElement)
virtual std::string getRequesterName ()

Public Attributes

weak_pointer weakref
const MonitorCacheEntry::shared_pointer entry
const epics::pvData::MonitorRequester::weak_pointer req
const std::tr1::weak_ptr< GWChannel > srvchan
bool initial
bool running
bool inoverflow
size_t nwakeups
size_t nevents
size_t ndropped
std::deque< epics::pvData::MonitorElementPtr > filled
std::deque< epics::pvData::MonitorElementPtr > empty
std::set< epics::pvData::MonitorElementPtr > inuse
epics::pvData::MonitorElementPtr overflowElement

Static Public Attributes

static size_t num_instances

Detailed Description

Definition at line 65 of file chancache.h.

Constructor & Destructor Documentation

◆ MonitorUser()

MonitorUser::MonitorUser ( const MonitorCacheEntry::shared_pointer & ,
const epics::pvData::MonitorRequester::shared_pointer & ,
const std::tr1::shared_ptr< GWChannel > &  )

Definition at line 249 of file moncache.cpp.

252 :entry(e)
253 ,req(req)
254 ,srvchan(srvchan)
255 ,initial(true)
256 ,running(false)
257 ,inoverflow(false)
258 ,nevents(0)
259 ,ndropped(0)
260{
261 epicsAtomicIncrSizeT(&num_instances);
262}

◆ ~MonitorUser()

MonitorUser::~MonitorUser ( )
virtual

Definition at line 264 of file moncache.cpp.

265{
266 epicsAtomicDecrSizeT(&num_instances);
267}

Member Function Documentation

◆ destroy()

void MonitorUser::destroy ( )
virtual

Definition at line 271 of file moncache.cpp.

272{
273 {
274 Guard G(mutex());
275 running = false;
276 }
277}

◆ getRequesterName()

std::string MonitorUser::getRequesterName ( )
virtual

Definition at line 387 of file moncache.cpp.

388{
389 return "MonitorCacheEntry";
390}

◆ mutex()

epicsMutex & MonitorUser::mutex ( ) const
inline

Definition at line 76 of file chancache.h.

76{ return entry->mutex(); }

◆ poll()

pva::MonitorElementPtr MonitorUser::poll ( )
virtual

Definition at line 341 of file moncache.cpp.

342{
343 Guard G(mutex());
344 pva::MonitorElementPtr ret;
345 if(!filled.empty()) {
346 ret = filled.front();
347 inuse.insert(ret); // track which ones are out for client use
348 filled.pop_front();
349 //TODO: track lost buffers w/ wrapped shared_ptr?
350 }
351 return ret;
352}

◆ release()

void MonitorUser::release ( epics::pvData::MonitorElementPtr const & monitorElement)
virtual

Definition at line 355 of file moncache.cpp.

356{
357 Guard G(mutex());
358 //TODO: ifdef DEBUG? (only track inuse when debugging?)
359 std::set<epics::pvData::MonitorElementPtr>::iterator it = inuse.find(monitorElement);
360 if(it!=inuse.end()) {
361 inuse.erase(it);
362
363 if(inoverflow) { // leaving overflow condition
364
365 // to avoid copy, enqueue the current overflowElement
366 // and replace it with the element being release()d
367
368 filled.push_back(overflowElement);
369 overflowElement = monitorElement;
370 overflowElement->changedBitSet->clear();
371 overflowElement->overrunBitSet->clear();
372
373 inoverflow = false;
374 } else {
375 // push_back empty element
376 empty.push_back(monitorElement);
377 }
378 } else {
379 // oh no, we've been given an element which we didn't give to downstream
380 //TODO: check empty and filled lists to see if this is one of ours, of from somewhere else
381 throw std::invalid_argument("Can't release MonitorElement not in use");
382 }
383 // TODO: pipeline window update?
384}

◆ start()

pvd::Status MonitorUser::start ( )
virtual

Definition at line 280 of file moncache.cpp.

281{
282 pvd::MonitorRequester::shared_pointer req(this->req.lock());
283 if(!req)
284 return pvd::Status(pvd::Status::STATUSTYPE_FATAL, "already dead");
285
286 bool doEvt = false;
287 {
288 Guard G(entry->mutex()); // MCE and MU have share a lock
289
290 if(!entry->startresult.isSuccess())
291 return entry->startresult;
292
293 pvd::PVStructurePtr lval;
294 if(entry->havedata)
295 lval = entry->lastelem->pvStructurePtr;
296 pvd::StructureConstPtr typedesc(entry->typedesc);
297
298 if(initial) {
299 initial = false;
300
301 empty.resize(entry->bufferSize);
302 pvd::PVDataCreatePtr fact(pvd::getPVDataCreate());
303 for(unsigned i=0; i<empty.size(); i++) {
304 empty[i].reset(new pvd::MonitorElement(fact->createPVStructure(typedesc)));
305 }
306
307 // extra element to accumulate updates during overflow
308 overflowElement.reset(new pvd::MonitorElement(fact->createPVStructure(typedesc)));
309 }
310
311 doEvt = filled.empty();
312
313 if(lval && !empty.empty()) {
314 //already running, notify of initial element
315
316 const pva::MonitorElementPtr& elem(empty.front());
317 elem->pvStructurePtr->copy(*lval);
318 elem->changedBitSet->set(0); // indicate all changed
319 elem->overrunBitSet->clear();
320 filled.push_back(elem);
321 empty.pop_front();
322 }
323
324 doEvt &= !filled.empty();
325 running = true;
326 }
327 if(doEvt)
328 req->monitorEvent(shared_pointer(weakref)); // TODO: worker thread?
329 return pvd::Status();
330}

◆ stop()

pvd::Status MonitorUser::stop ( )
virtual

Definition at line 333 of file moncache.cpp.

334{
335 Guard G(mutex());
336 running = false;
337 return pvd::Status::Ok;
338}

Member Data Documentation

◆ empty

std::deque<epics::pvData::MonitorElementPtr> MonitorUser::empty

Definition at line 86 of file chancache.h.

◆ entry

const MonitorCacheEntry::shared_pointer MonitorUser::entry

Definition at line 72 of file chancache.h.

◆ filled

std::deque<epics::pvData::MonitorElementPtr> MonitorUser::filled

Definition at line 86 of file chancache.h.

◆ initial

bool MonitorUser::initial

Definition at line 79 of file chancache.h.

◆ inoverflow

bool MonitorUser::inoverflow

Definition at line 81 of file chancache.h.

◆ inuse

std::set<epics::pvData::MonitorElementPtr> MonitorUser::inuse

Definition at line 87 of file chancache.h.

◆ ndropped

size_t MonitorUser::ndropped

Definition at line 84 of file chancache.h.

◆ nevents

size_t MonitorUser::nevents

Definition at line 83 of file chancache.h.

◆ num_instances

size_t MonitorUser::num_instances
static

Definition at line 68 of file chancache.h.

◆ nwakeups

size_t MonitorUser::nwakeups

Definition at line 82 of file chancache.h.

◆ overflowElement

epics::pvData::MonitorElementPtr MonitorUser::overflowElement

Definition at line 89 of file chancache.h.

◆ req

const epics::pvData::MonitorRequester::weak_pointer MonitorUser::req

Definition at line 73 of file chancache.h.

◆ running

bool MonitorUser::running

Definition at line 80 of file chancache.h.

◆ srvchan

const std::tr1::weak_ptr<GWChannel> MonitorUser::srvchan

Definition at line 74 of file chancache.h.

◆ weakref

weak_pointer MonitorUser::weakref

Definition at line 70 of file chancache.h.


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