source: flair-src/trunk/lib/FlairCore/src/IODevice.h@ 242

Last change on this file since 242 was 238, checked in by Bayard Gildas, 7 years ago

correction sémaphore. bloquant tout ça...

File size: 4.7 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// ---
6/*!
7 * \file IODevice.h
8 * \brief Abstract class for input/ouput system
9 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
10 * \date 2011/05/01
11 * \version 4.0
12 */
13
14#ifndef IO_DEVICE_H
15#define IO_DEVICE_H
16
17#include <Object.h>
18
19class IODevice_impl;
20class Thread_impl;
21class FrameworkManager_impl;
22
23namespace flair {
24namespace core {
25
26class io_data;
27class DataType;
28
29/*! \class IODevice
30*
31* \brief Abstract class for input/ouput system
32*
33* An input/output system is generally used to describe a sensor, an actuator or
34*a filter. \n
35* These systems can be linked (for exemple a sensor with a filter), when an
36*IODevice
37* is created with a parent of type IODevice.
38* In this case, an update of the parent's data will call an update
39* of the child's data (for exemple when a sensor gets new datas, a filter is
40*automatically called). \n
41* Output of this object can also be sent to a shared memory using the
42*OutputToShMem method; in order to use it with an
43* external program.
44*/
45class IODevice : public Object {
46 friend class ::IODevice_impl;
47 friend class ::Thread_impl;
48 friend class ::FrameworkManager_impl;
49
50public:
51 /*!
52 * \brief Constructor
53 *
54 * Construct an IODevice of Object's type "IODevice" (see Object::ObjectType).
55 *\n
56 * If parent's Object::ObjectType is also "IODevice", this IODevice will be
57 *linked to its parent
58 * (see ProcessUpdate()).
59 *
60 * \param parent parent
61 * \param name name
62 */
63 IODevice(const Object *parent, std::string name);
64
65 /*!
66 * \brief Destructor
67 *
68 */
69 virtual ~IODevice();
70
71 /*!
72 * \brief Add an IODevice to the logs
73 *
74 * The IODevice will be automatically logged among this IODevice logs,
75 * if logging is enabled (see SetDataToLog(), FrameworkManager::StartLog
76 * and FrameworkManager::AddDeviceToLog). \n
77 * Logging happens when ProcessUpdate() is called. \n
78 * Note that when an IODevice is just added for logs (ie. no parent/child
79 * link between the two IODevice),
80 * UpdateFrom() is not automatically called.
81 *
82 * \param device IODevice to log
83 */
84 void AddDeviceToLog(const IODevice *device);
85
86 /*!
87 * \brief Add an io_data to the log
88 *
89 * The io_data will be automatically logged if enabled (see
90 *FrameworkManager::StartLog
91 * and FrameworkManager::AddDeviceToLog),
92 * during call to ProcessUpdate().
93 *
94 * \param data data to log
95 */
96 void AddDataToLog(const io_data *data);
97
98 /*!
99 * \brief Send the output to a shared memory
100 *
101 * Use this method to output log datas to a shared memory.
102 * This can be usefull to get datas from an external progam. \n
103 * Output happens when ProcessUpdate() is called. \n
104 * The name and the structure of the shared memory will be displayed when
105 * this method is called with true as argument. \n
106 * By default it is not enabled.
107 *
108 *
109 * \param enabled true to enable the output, false otherwise
110 */
111 void OutputToShMem(bool enabled);
112
113 /*!
114 * \brief is device ready
115 *
116 * Use it check if a device is ready or not.
117 * See also setIsReady.
118 *
119 * \return true if device is ready
120 */
121 bool IsReady(void) const;
122
123 // TODO: these 2 method should be pure virtual
124 virtual DataType const &GetInputDataType() const;
125 virtual DataType const &GetOutputDataType() const;
126
127 protected:
128 /*!
129 * \brief Process the childs of type IODevice, and log if needed
130 *
131 * This method must be called after computing datas;
132 * generally at the end of the reimplemented UpdateFrom or after acquiring datas in case of a sensor. \n
133 * It will call UpdateFrom methods of each child of type IODevice,
134 * and log all datas (this IODevice and its childs)
135 * if logging is enabled (see SetDataToLog(), AddDeviceToLog(),
136 * FrameworkManager::StartLog and FrameworkManager::AddDeviceToLog). \n
137 * If a thread is waiting on this IODevice (see Thread::WaitUpdate), it will be resumed.
138 *
139 * \param data data to process
140 */
141 void ProcessUpdate(io_data* data);
142
143 /*!
144 * \brief set is ready
145 *
146 * Sets if the device is ready or not. By default the IODevice is not ready.\n
147 * See also isReady.
148 *
149 * \param status status
150 */
151 void SetIsReady(bool status);
152
153 /*!
154 * \brief Update using provided datas
155 *
156 * This method is automatically called by ProcessUpdate()
157 * of the Object::Parent's if its Object::ObjectType is "IODevice". \n
158 * This method must be reimplemented, in order to process the data from the
159 *parent.
160 *
161 * \param data data from the parent to process
162 */
163 virtual void UpdateFrom(const io_data *data) = 0;
164
165 private:
166 class IODevice_impl *pimpl_;
167};
168
169} // end namespace core
170} // end namespace flair
171
172#endif // IO_DEVICE_H
Note: See TracBrowser for help on using the repository browser.