EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
SampleMechanism.h
1 #ifndef SAMPLEMECHANISM_H_
2 #define SAMPLEMECHANISM_H_
3 
4 // storage
5 #include "storage/Index.h"
6 
7 // engine
8 #include "engine/Named.h"
9 #include "engine/EngineConfig.h"
10 #include "engine/ProcessVariable.h"
11 #include "engine/DisableFilter.h"
12 
34  public Guardable,
35  public virtual Named {
36  public:
37 
53  SampleMechanism(const EngineConfig& config,
55  const char* name,
56  double period,
57  ProcessVariableListener* disable_filt_listener);
58 
59  virtual ~SampleMechanism();
60 
61  public:
62 
66  virtual unsigned long write(Guard& guard, Index& index) = 0;
67 
68  protected:
69 
75  virtual void addEvent(Guard& guard, short severity, const epicsTime& when) = 0;
76 
77  public:
78 
79  // SampleMechanism API
80 
82  virtual std::string getInfo(Guard& guard);
83 
88  virtual void start(Guard& guard);
89 
95  virtual void stop(Guard& guard);
96 
98  virtual void addToFUX(Guard& guard, FUX::Element* doc);
99 
100  public:
101 
102  // ProcessVariableListener API
103 
108  virtual void pvConnected(ProcessVariable& pv, const epicsTime& when) = 0;
109 
114  void pvDisconnected(ProcessVariable& pv, const epicsTime& when);
115 
125  virtual void pvValue(ProcessVariable& pv, const RawValue::Data* data) = 0;
126 
127  public:
128 
129  // Guardable API
130 
133  virtual OrderedMutex& getMutex();
134 
135  public:
136 
137  // Named API
138 
142  virtual const std::string& getName() const;
143 
144  public:
145 
147  bool isRunning(Guard& guard);
148 
151 
154  void disable(const epicsTime& when);
155 
158  void enable(const epicsTime& when);
159 
160  public:
161 
163  inline void addStateListener(ProcessVariableStateListener* listener);
164 
166  inline void removeStateListener(ProcessVariableStateListener* listener);
167 
169  inline void addValueListener(ProcessVariableValueListener* listener);
170 
172  inline void removeValueListener(ProcessVariableValueListener* listener);
173 
174  protected:
175 
176  // These have their own mutex or don't need one.
177  const EngineConfig& config;
178  ProcessVariable pv;
179  DisableFilter disable_filter;
180 
181  OrderedMutex mutex; // Mutex for the remaining data.
182  bool running;
183  double period; // .. in seconds
184 
185  bool last_stamp_set; // For catching 'back-in-time' at the
186  epicsTime last_stamp; // buffer level.
187  bool have_sample_after_connection;
188 };
189 
190 inline void
192  pv.addStateListener(listener);
193 }
194 
195 inline void
197  pv.removeStateListener(listener);
198 }
199 
200 inline void
202  pv.addValueListener(listener);
203 }
204 
205 inline void
207  pv.removeValueListener(listener);
208 }
209 
210 
211 #endif /*SAMPLEMECHANISM_H_*/
void removeValueListener(ProcessVariableValueListener *listener)
Remove a listener from the underlying PV.
Definition: SampleMechanism.h:206
A filter to block samples while disabled.
Definition: DisableFilter.h:19
Listener for ProcessVariable info.
Definition: ProcessVariableListener.h:31
void addStateListener(ProcessVariableStateListener *listener)
Add a listener to the underlying PV.
Definition: SampleMechanism.h:191
A mutex with informational name and lock order.
Definition: OrderedMutex.h:34
virtual void start(Guard &guard)
Start the sample mechanism.
virtual const std::string & getName() const
Gets the ProcessVariable name.
void disable(const epicsTime &when)
Temporarily disable sampling.
void removeStateListener(ProcessVariableStateListener *listener)
Remove a ProcessVariableStateListener.
Definition: ProcessVariable.h:193
virtual std::string getInfo(Guard &guard)
void pvDisconnected(ProcessVariable &pv, const epicsTime &when)
ProcessVariableStateListener.
void addValueListener(ProcessVariableValueListener *listener)
Add a ProcessVariableValueListener.
Definition: ProcessVariable.h:199
bool isRunning(Guard &guard)
One process variable.
Definition: ProcessVariable.h:39
Global engine configuration parameters.
Definition: EngineConfig.h:14
virtual void pvValue(ProcessVariable &pv, const RawValue::Data *data)=0
ProcessVariableValueListener.
Listener for ProcessVariable state info.
Definition: ProcessVariableListener.h:10
void addStateListener(ProcessVariableStateListener *listener)
Add a ProcessVariableStateListener.
Definition: ProcessVariable.h:187
Abstract base for a named thingy, does not actually contain the name.
Definition: Named.h:15
virtual void addToFUX(Guard &guard, FUX::Element *doc)
Append this sample mechanism to a FUX document.
Automatically takes and releases an epicsMutex.
Definition: Guard.h:63
void removeStateListener(ProcessVariableStateListener *listener)
Remove a listener from the underlying PV.
Definition: SampleMechanism.h:196
Sample Mechanism base, has a ProcessVariable and filters its values.
Definition: SampleMechanism.h:33
Listener for ProcessVariable info.
Definition: ProcessVariableListener.h:47
void removeValueListener(ProcessVariableValueListener *listener)
Remove a ProcessVariableValueListener.
Definition: ProcessVariable.h:205
virtual OrderedMutex & getMutex()
virtual unsigned long write(Guard &guard, Index &index)=0
Write current buffer to index.
void enable(const epicsTime &when)
Re-enable sampling.
Interface for something that can be protected by a Guard.
Definition: Guard.h:49
Context for ProcessVariable instances.
Definition: ProcessVariableContext.h:18
SampleMechanism(const EngineConfig &config, ProcessVariableContext &ctx, const char *name, double period, ProcessVariableListener *disable_filt_listener)
Construct mechanism for given period.
void addValueListener(ProcessVariableValueListener *listener)
Add a listener to the underlying PV.
Definition: SampleMechanism.h:201
ProcessVariable::State getPVState()
virtual void pvConnected(ProcessVariable &pv, const epicsTime &when)=0
ProcessVariableStateListener.
virtual void stop(Guard &guard)
Stop sampling.
Base interface for the archiver's indices.
Definition: Index.h:16
One element in the FUX tree.
Definition: FUX.h:51
dbr_time_double Data
Type for accessing the raw data and its common fields.
Definition: RawValue.h:55
State
Possible states of a ProcessVariable.
Definition: ProcessVariable.h:52