EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
ProcessVariable.h
1 #ifndef PROCESSVARIABLE_H_
2 #define PROCESSVARIABLE_H_
3 
4 // epics
5 #include <cadef.h>
6 
7 // tools
8 #include "tools/Guard.h"
9 #include "tools/ConcurrentList.h"
10 
11 // storage
12 #include "storage/RawValue.h"
13 #include "storage/CtrlInfo.h"
14 
15 // engine
16 #include "engine/Named.h"
17 #include "engine/ProcessVariableContext.h"
18 #include "engine/ProcessVariableListener.h"
19 
39 class ProcessVariable : public NamedBase, public Guardable
40 {
41 public:
43  ProcessVariable(ProcessVariableContext &ctx, const char *name);
44 
46  virtual ~ProcessVariable();
47 
50 
52  enum State
53  {
62  };
63 
65  State getState(Guard &guard) const;
66 
68  bool isConnected(Guard &guard) const;
69 
71  const char *getStateStr(Guard &guard) const;
72 
74  const char *getCAStateStr(Guard &guard) const;
75 
80  DbrType getDbrType(Guard &guard) const;
81 
86  DbrCount getDbrCount(Guard &guard) const;
87 
89  const CtrlInfo &getCtrlInfo(Guard &guard) const;
90 
93 
96 
99 
102 
104  void addListener(ProcessVariableListener *listener);
105 
107  void removeListener(ProcessVariableListener *listener);
108 
113  void start(Guard &guard);
114 
117  bool isRunning(Guard &guard);
118 
123  void getValue(Guard &guard);
124 
129  void subscribe(Guard &guard);
130 
132  bool isSubscribed(Guard &guard) const;
133 
135  void unsubscribe(Guard &guard);
136 
140  void stop(Guard &guard);
141 
142 private:
143  OrderedMutex mutex;
145  State state;
146  chid id;
147  evid ev_id;
148  DbrType dbr_type;
149  DbrCount dbr_count;
150  CtrlInfo ctrl_info;
151  size_t outstanding_gets;
152 
155 
156  // Channel Access callbacks
157  static void connection_handler(struct connection_handler_args arg);
158  static void control_callback(struct event_handler_args arg);
159  static void value_callback(struct event_handler_args);
160 
161  bool setup_ctrl_info(Guard &guard, DbrType type, const void *dbr_ctrl_xx);
162  void firePvConnected();
163  void firePvDisconnected();
164  void firePvValue(const RawValue::Data *value);
165 };
166 
167 inline bool ProcessVariable::isConnected(Guard &guard) const
168 {
169  return getState(guard) == CONNECTED;
170 }
171 
173 {
174  return dbr_type;
175 }
176 
178 {
179  return dbr_count;
180 }
181 
182 inline const CtrlInfo &ProcessVariable::getCtrlInfo(Guard &guard) const
183 {
184  return ctrl_info;
185 }
186 
189 {
190  state_listeners.add(listener);
191 }
192 
195 {
196  state_listeners.remove(listener);
197 }
198 
201 {
202  value_listeners.add(listener);
203 }
204 
207 {
208  value_listeners.remove(listener);
209 }
210 
212 {
213  addStateListener(listener);
214  addValueListener(listener);
215 }
216 
218 {
219  removeValueListener(listener);
220  removeStateListener(listener);
221 }
222 
223 inline bool ProcessVariable::isSubscribed(Guard &guard) const
224 {
225  return ev_id != 0;
226 }
227 
228 #endif /*PROCESSVARIABLE_H_*/
Listener for ProcessVariable info.
Definition: ProcessVariableListener.h:31
bool isRunning(Guard &guard)
unsigned short DbrType
DbrType is used to hold dbr_time_xxx types.
Definition: RawValue.h:24
Not connected, but trying to connect.
Definition: ProcessVariable.h:57
void remove(T *item)
Definition: ConcurrentList.h:178
A mutex with informational name and lock order.
Definition: OrderedMutex.h:34
Meta-information for values: Units, limits, etc .
Definition: CtrlInfo.h:75
A named thingy.
Definition: Named.h:28
void subscribe(Guard &guard)
Subscribe for value updates.
void removeStateListener(ProcessVariableStateListener *listener)
Remove a ProcessVariableStateListener.
Definition: ProcessVariable.h:193
ProcessVariable(ProcessVariableContext &ctx, const char *name)
Create a ProcessVariable with given name.
const char * getCAStateStr(Guard &guard) const
void addValueListener(ProcessVariableValueListener *listener)
Add a ProcessVariableValueListener.
Definition: ProcessVariable.h:199
One process variable.
Definition: ProcessVariable.h:39
State getState(Guard &guard) const
DbrCount getDbrCount(Guard &guard) const
Get the array size of this PV.
Definition: ProcessVariable.h:177
Listener for ProcessVariable state info.
Definition: ProcessVariableListener.h:10
void addStateListener(ProcessVariableStateListener *listener)
Add a ProcessVariableStateListener.
Definition: ProcessVariable.h:187
Automatically takes and releases an epicsMutex.
Definition: Guard.h:63
const char * getStateStr(Guard &guard) const
Listener for ProcessVariable info.
Definition: ProcessVariableListener.h:47
unsigned short DbrCount
DbrCount is used to hold the array size of CA channels.
Definition: RawValue.h:27
void removeValueListener(ProcessVariableValueListener *listener)
Remove a ProcessVariableValueListener.
Definition: ProcessVariable.h:205
void unsubscribe(Guard &guard)
Unsubscribe, no more updates.
Received CA connection callback, getting control info.
Definition: ProcessVariable.h:59
Fully connected.
Definition: ProcessVariable.h:61
Interface for something that can be protected by a Guard.
Definition: Guard.h:49
Context for ProcessVariable instances.
Definition: ProcessVariableContext.h:18
void removeListener(ProcessVariableListener *listener)
Remove a ProcessVariableListener.
Definition: ProcessVariable.h:217
const CtrlInfo & getCtrlInfo(Guard &guard) const
Definition: ProcessVariable.h:182
void start(Guard &guard)
Start the connection mechanism.
OrderedMutex & getMutex()
bool isSubscribed(Guard &guard) const
Definition: ProcessVariable.h:223
void getValue(Guard &guard)
Perform a single &#39;get&#39;.
bool isConnected(Guard &guard) const
Definition: ProcessVariable.h:167
virtual ~ProcessVariable()
Destructor.
void stop(Guard &guard)
Disconnect.
void add(T *item)
Definition: ConcurrentList.h:164
dbr_time_double Data
Type for accessing the raw data and its common fields.
Definition: RawValue.h:55
DbrType getDbrType(Guard &guard) const
Get the DBR_TIME_...
Definition: ProcessVariable.h:172
Not initialized.
Definition: ProcessVariable.h:55
void addListener(ProcessVariableListener *listener)
Add a ProcessVariableListener.
Definition: ProcessVariable.h:211
State
Possible states of a ProcessVariable.
Definition: ProcessVariable.h:52