EPICS ARCHIVER V4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
Engine.h
1 #ifndef __ENGINE_H_
2 #define __ENGINE_H_
3 
4 // tools
5 #include "tools/Guard.h"
6 
7 // engine
8 #include "engine/EngineConfig.h"
9 #include "engine/ScanList.h"
10 #include "engine/ProcessVariableContext.h"
11 
12 #include "engine/GroupInfo.h"
13 #include "engine/ArchiveChannel.h"
14 #include "engine/ArchiveChannelStateListener.h"
15 
18 class Engine : public Guardable, public EngineConfigListener {
19 
20  public:
21 
22  static const double MAX_DELAY;
23 
25  Engine(const std::string& index_name);
26 
28  virtual ~Engine();
29 
30  public:
31 
32  // Guardable API
33 
35  virtual OrderedMutex& getMutex();
36 
37  public:
38 
39  // EngineConfigListener API
40 
45  virtual void addChannel(const std::string& group_name,
46  const std::string& channel_name,
47  double scan_period,
48  bool disabling,
49  bool monitor) = 0;
50 
51  public:
52 
54  virtual void read_config(Guard& guard, const std::string& file_name) = 0;
55 
61  virtual unsigned long write(Guard& guard) = 0;
62 
63  public:
64 
66  inline const std::string& getIndexName(Guard& guard) const;
67 
69  inline void setDescription(Guard& guard, const std::string& description);
70 
72  inline const std::string& getDescription(Guard& guard) const;
73 
75  inline const epicsTime& getStartTime(Guard& guard) const;
76 
78  inline const epicsTime& getNextWriteTime(Guard& guard) const;
79 
87  inline void attachToProcessVariableContext(Guard& guard);
88 
90  inline double getWriteDuration(Guard& guard) const;
91 
93  inline size_t getWriteCount(Guard& guard) const;
94 
99  inline double getProcessDelayAvg(Guard& guard) const;
100 
101  public:
102 
104  inline const EngineConfig& getConfig(Guard& guard) const;
105 
108 
110  virtual void write_config(Guard& guard);
111 
112  public:
113 
119  GroupInfo* addGroup(Guard& guard, const std::string& group_name);
120 
122  inline const stdList<GroupInfo *>& getGroups(Guard& guard) const;
123 
125  GroupInfo* findGroup(Guard& engine_guard, const std::string& name);
126 
128  inline const stdList<ArchiveChannel *>& getChannels(Guard& guard) const;
129 
131  ArchiveChannel* findChannel(Guard& engine_guard, const std::string &name);
132 
134  size_t getNumConnected(Guard& guard) const;
135 
136 public:
137 
139  void start(Guard& guard);
140 
143  inline bool isRunning(Guard& guard) const;
144 
148  bool process();
149 
151  void stop(Guard& guard);
152 
153  protected:
154 
155  OrderedMutex mutex;
156 
157  bool is_running;
158  epicsTime start_time;
159  stdString index_name;
160  stdString description;
161  EngineConfigParser config;
162  ScanList scan_list;
163 
164  ProcessVariableContext pv_context;
165 
166  stdList<GroupInfo *> groups; // scan-groups of channels
167  stdList<ArchiveChannel *> channels; // all the channels
168 
169  double write_duration; // Updated by process()
170  size_t write_count; // process()
171  double process_delay_avg;// process()
172  epicsTime next_write_time; // process()
173 };
174 
175 
176 
177 inline const std::string&
178 Engine::getIndexName(Guard& guard) const {
179  return index_name;
180 }
181 
182 inline void
183 Engine::setDescription(Guard& guard, const std::string& description){
184  this->description = description;
185 }
186 
187 inline const std::string&
189  return description;
190 }
191 
192 inline const epicsTime&
193 Engine::getStartTime(Guard& guard) const {
194  return start_time;
195 }
196 
197 inline const epicsTime&
199  return next_write_time;
200 }
201 
202 inline void
204  Guard ctx_guard(__FILE__, __LINE__, pv_context);
205  pv_context.attach(ctx_guard);
206 }
207 
208 
209 inline double
211  return write_duration;
212 }
213 
214 inline size_t
215 Engine::getWriteCount(Guard& guard) const {
216  return write_count;
217 }
218 
219 inline double
221  return process_delay_avg;
222 }
223 
224 
225 inline const EngineConfig&
226 Engine::getConfig(Guard& guard) const {
227  return config;
228 }
229 
230 inline WritableEngineConfig&
232  return config;
233 }
234 
235 //
236 
237 inline const stdList<GroupInfo *>&
238 Engine::getGroups(Guard& guard) const {
239  return groups;
240 }
241 
242 inline const stdList<ArchiveChannel *>&
243 Engine::getChannels(Guard& guard) const {
244  return channels;
245 }
246 
247 
248 //
249 
250 inline bool Engine::isRunning(Guard& guard) const {
251  return is_running;
252 }
253 
254 #endif /* ENGINE_H_*/
virtual unsigned long write(Guard &guard)=0
Write all current buffers to disk.
ArchiveChannel * findChannel(Guard &engine_guard, const std::string &name)
size_t getNumConnected(Guard &guard) const
virtual void write_config(Guard &guard)
Write a new config file.
size_t getWriteCount(Guard &guard) const
Definition: Engine.h:215
const stdList< GroupInfo * > & getGroups(Guard &guard) const
Definition: Engine.h:238
virtual void read_config(Guard &guard, const std::string &file_name)=0
Read the given config file.
A mutex with informational name and lock order.
Definition: OrderedMutex.h:34
virtual OrderedMutex & getMutex()
Guardable interface.
void stop(Guard &guard)
Stop sampling.
const stdList< ArchiveChannel * > & getChannels(Guard &guard) const
Definition: Engine.h:243
The base class of the archive engines.
Definition: Engine.h:18
GroupInfo * findGroup(Guard &engine_guard, const std::string &name)
const std::string & getDescription(Guard &guard) const
Definition: Engine.h:188
void start(Guard &guard)
Start the sample mechanism.
static const double MAX_DELAY
max delay
Definition: Engine.h:22
Global engine configuration parameters.
Definition: EngineConfig.h:14
const epicsTime & getNextWriteTime(Guard &guard) const
Definition: Engine.h:198
bool process()
Main process routine.
Automatically takes and releases an epicsMutex.
Definition: Guard.h:63
void attachToProcessVariableContext(Guard &guard)
Join the engine&#39;s ProcessVariableContext.
Definition: Engine.h:203
Modifyable global engine configuration parameters.
Definition: EngineConfig.h:87
Interface for something that can be protected by a Guard.
Definition: Guard.h:49
Context for ProcessVariable instances.
Definition: ProcessVariableContext.h:18
const epicsTime & getStartTime(Guard &guard) const
Definition: Engine.h:193
WritableEngineConfig & getWritableConfig(Guard &guard)
Definition: Engine.h:231
Reads the config from an XML file that should conform to engineconfig.dtd.
Definition: EngineConfig.h:142
One archived channel.
Definition: ArchiveChannel.h:19
void setDescription(Guard &guard, const std::string &description)
Set the description string.
Definition: Engine.h:183
void attach(Guard &guard)
Attach current thread to this context.
const std::string & getIndexName(Guard &guard) const
Definition: Engine.h:178
GroupInfo * addGroup(Guard &guard, const std::string &group_name)
Add a group.
double getProcessDelayAvg(Guard &guard) const
Definition: Engine.h:220
A ScanList keeps track of Scannable items.
Definition: ScanList.h:43
const EngineConfig & getConfig(Guard &guard) const
Definition: Engine.h:226
virtual void addChannel(const std::string &group_name, const std::string &channel_name, double scan_period, bool disabling, bool monitor)=0
Add a channel.
virtual ~Engine()
Destructor.
A Group of channels.
Definition: GroupInfo.h:42
Listener to EngineConfigParser.
Definition: EngineConfig.h:124
bool isRunning(Guard &guard) const
Definition: Engine.h:250
double getWriteDuration(Guard &guard) const
Definition: Engine.h:210
Engine(const std::string &index_name)
Create Engine that writes to given index.