#ifndef COLLECT_CA_H #define COLLECT_CA_H #include #include #include #include #include #include #include #include typedef epicsGuard Guard; typedef epicsGuardRelease UnGuard; // cf. cadef.h struct ca_client_context; struct oldChannelNotify; struct oldSubscription; struct connection_handler_args; struct Collector; struct DBRValue { struct Holder { static size_t num_instances; epicsTimeStamp ts; // in epics epoch epicsUInt16 sevr, // [0-3] or 4 (Disconnect) stat; // status code a la Base alarm.h epicsUInt32 count; epics::pvData::shared_vector buffer; // contains DBF_* mapped to pvd:pv* code Holder(); ~Holder(); }; private: std::tr1::shared_ptr held; public: DBRValue() {} DBRValue(Holder *H) :held(H) {} bool valid() const { return !!held; } Holder* operator->() {return held.get();} const Holder* operator->() const {return held.get();} void swap(DBRValue& o) { held.swap(o.held); } void reset() { held.reset(); } }; struct CAContext { static size_t num_instances; explicit CAContext(unsigned int prio, bool fake=false); ~CAContext(); struct ca_client_context *context; // manage attachment of a context to the current thread struct Attach { struct ca_client_context *previous; Attach(const CAContext&); ~Attach(); }; EPICS_NOT_COPYABLE(CAContext) }; struct Subscription { static size_t num_instances; const std::string pvname; const CAContext& context; Collector& collector; const size_t column; // set before callbacks are possible, cleared after callbacks are impossible struct oldChannelNotify *chid; // effectively a local of a CA worker, set and cleared from onConnect() struct oldSubscription *evid; mutable epicsMutex mutex; bool connected; // stats counters size_t nDisconnects, nErrors, nUpdates, nUpdateBytes, nOverflows; // previous values of counters for delta size_t lDisconnects, lErrors, lUpdates, lUpdateBytes, lOverflows; // current buffer limit size_t limit; epicsTimeStamp last_event; std::deque values; Subscription(const CAContext& context, size_t column, const std::string& pvname, Collector& collector); ~Subscription(); void close(); void clear(size_t remain); // dequeue one update DBRValue pop(); // for test code only void push(const DBRValue& v); private: void _push(DBRValue& v); static void onConnect (struct connection_handler_args args); static void onEvent (struct event_handler_args args); EPICS_NOT_COPYABLE(Subscription) }; #endif // COLLECT_CA_H