RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 &) {};
261  {
262  return *getInstance();
263  };
264 
265  static Manager *instance;
266 
267  void insertWorkspace(Instance *);
268  void removeWorkspace(Instance *);
269 
271  std::list<Instance *> instanceList;
272 
273 }; // class Manager
274 
275 } // namespace Workspace
276 
277 #endif // WORKSPACE_H
static Manager * instance
Definition: workspace.h:263
void removeWorkspace(Instance *)
Definition: workspace.cpp:308
void insertWorkspace(Instance *)
Definition: workspace.cpp:289
Definition: io.h:187
std::string getDescription(IO::flags_t type, size_t index) const
Definition: workspace.cpp:168
void foreachWorkspace(void(*callback)(Instance *, void *), void *param)
Definition: workspace.cpp:282
std::vector< var_t > parameter
Definition: workspace.h:203
Instance(std::string name, variable_t *variables, size_t size)
Definition: workspace.cpp:67
Manager & operator=(const Manager &)
Definition: workspace.h:260
std::vector< comment_t > comment
Definition: workspace.h:214
std::vector< var_t > event
Definition: workspace.h:205
Definition: mutex.h:28
double * getData(IO::flags_t type, size_t index)
Definition: workspace.cpp:261
static Manager * getInstance(void)
Definition: workspace.cpp:323
std::list< Instance * > instanceList
Definition: workspace.h:271
std::string getName(void) const
Definition: io.h:214
unsigned long flags_t
Definition: io.h:40
size_t getCount(IO::flags_t type) const
Definition: workspace.cpp:136
std::vector< var_t > state
Definition: workspace.h:204
void setValue(size_t index, double value)
Definition: workspace.cpp:231
void setData(IO::flags_t type, size_t index, double *value)
Definition: workspace.cpp:272
std::string getValueString(IO::flags_t type, size_t index) const
Definition: workspace.cpp:204
Internal Control Oriented Classes.
Definition: workspace.h:30
void setComment(size_t index, std::string comment)
Definition: workspace.cpp:253
std::string name
Definition: io.h:325
IO::channel_t variable_t
Definition: workspace.h:68
double getValue(IO::flags_t type, size_t index) const
Definition: workspace.cpp:182
virtual ~Instance(void)
Definition: workspace.cpp:128
Manager(const Manager &)
Definition: workspace.h:259