RTXI  2.4
The Real-Time eXperiment Interface Documentation
workspace.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef WORKSPACE_H
21 #define WORKSPACE_H
22 
23 #include <io.h>
24 
26 
30 namespace Workspace
31 {
32 
38 static const IO::flags_t INPUT = IO::INPUT;
44 static const IO::flags_t OUTPUT = IO::OUTPUT;
48 static const IO::flags_t PARAMETER = IO::OUTPUT<<1;
52 static const IO::flags_t STATE = IO::OUTPUT<<2;
56 static const IO::flags_t EVENT = IO::OUTPUT<<3;
60 static const IO::flags_t COMMENT = IO::OUTPUT<<4;
61 
69 
76 class Instance : public IO::Block
77 {
78 
79  friend class Manager;
80 
81 public:
82 
96  Instance(std::string name,variable_t *variables,size_t size);
97  virtual ~Instance(void);
98 
107  size_t getCount(IO::flags_t type) const;
117  std::string getName(IO::flags_t type,size_t index) const;
127  std::string getDescription(IO::flags_t type,size_t index) const;
138  double getValue(IO::flags_t type,size_t index) const;
149  std::string getValueString(IO::flags_t type,size_t index) const;
150 
159  void setValue(size_t index,double value);
168  void setComment(size_t index,std::string comment);
169 
170 protected:
171 
181  double *getData(IO::flags_t type,size_t index);
182 
192  void setData(IO::flags_t type,size_t index,double *value);
193 
194 private:
195 
196  typedef struct
197  {
198  std::string name;
199  std::string description;
200  double *data;
201  } var_t;
202 
203  std::vector<var_t> parameter;
204  std::vector<var_t> state;
205  std::vector<var_t> event;
206 
207  typedef struct
208  {
209  std::string name;
210  std::string description;
211  std::string comment;
212  } comment_t;
213 
214  std::vector<comment_t> comment;
215 
216 }; // class Object
217 
224 class Manager
225 {
226 
227  friend class Instance;
228 
229 public:
230 
237  static Manager *getInstance(void);
238 
248  void foreachWorkspace(void (*callback)(Instance *,void *),void *param);
249 
250 private:
251 
252  /*****************************************************************
253  * The constructor, destructor, and assignment operator are made *
254  * private to control instantiation of the class. *
255  *****************************************************************/
256 
257  Manager(void) : mutex(Mutex::RECURSIVE) {};
258  ~Manager(void) {};
259  Manager(const Manager &) {};
260  Manager &operator=(const Manager &)
261  {
262  return *getInstance();
263  };
264 
265  static Manager *instance;
266 
267  void insertWorkspace(Instance *);
268  void removeWorkspace(Instance *);
269 
270  Mutex mutex;
271  std::list<Instance *> instanceList;
272 
273 }; // class Manager
274 
275 } // namespace Workspace
276 
277 #endif // WORKSPACE_H
Workspace::Instance
Definition: workspace.h:76
Workspace::Instance::getDescription
std::string getDescription(IO::flags_t type, size_t index) const
Definition: workspace.cpp:168
IO::flags_t
unsigned long flags_t
Definition: io.h:40
Workspace::Instance::Instance
Instance(std::string name, variable_t *variables, size_t size)
Definition: workspace.cpp:67
Workspace::Manager
Definition: workspace.h:224
Workspace::Instance::getCount
size_t getCount(IO::flags_t type) const
Definition: workspace.cpp:136
Workspace::Manager::Instance
friend class Instance
Definition: workspace.h:227
Workspace::Instance::getValueString
std::string getValueString(IO::flags_t type, size_t index) const
Definition: workspace.cpp:204
Workspace::Instance::getValue
double getValue(IO::flags_t type, size_t index) const
Definition: workspace.cpp:182
Workspace::variable_t
IO::channel_t variable_t
Definition: workspace.h:68
Workspace::Instance::getData
double * getData(IO::flags_t type, size_t index)
Definition: workspace.cpp:261
IO::Block::getName
std::string getName(void) const
Definition: io.h:215
Mutex
Definition: mutex.h:28
IO::Block
Definition: io.h:188
IO::channel_t
Definition: io.h:56
Workspace
Internal Control Oriented Classes.
Definition: workspace.h:30
Workspace::Manager::foreachWorkspace
void foreachWorkspace(void(*callback)(Instance *, void *), void *param)
Definition: workspace.cpp:282
Workspace::Instance::setValue
void setValue(size_t index, double value)
Definition: workspace.cpp:231
io.h
Workspace::Instance::setData
void setData(IO::flags_t type, size_t index, double *value)
Definition: workspace.cpp:272
Workspace::Manager::getInstance
static Manager * getInstance(void)
Definition: workspace.cpp:323
Workspace::Instance::setComment
void setComment(size_t index, std::string comment)
Definition: workspace.cpp:253
Workspace::Instance::~Instance
virtual ~Instance(void)
Definition: workspace.cpp:128