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 |
|
---|
19 | class IODevice_impl;
|
---|
20 | class Thread_impl;
|
---|
21 | class FrameworkManager_impl;
|
---|
22 |
|
---|
23 | namespace flair {
|
---|
24 | namespace core {
|
---|
25 |
|
---|
26 | class io_data;
|
---|
27 | class 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 | */
|
---|
45 | class IODevice : public Object {
|
---|
46 | friend class ::IODevice_impl;
|
---|
47 | friend class ::Thread_impl;
|
---|
48 | friend class ::FrameworkManager_impl;
|
---|
49 |
|
---|
50 | public:
|
---|
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 | // TODO: these 2 method should be pure virtual
|
---|
114 | virtual DataType const &GetInputDataType() const;
|
---|
115 | virtual DataType const &GetOutputDataType() const;
|
---|
116 |
|
---|
117 | Time lastUpdate;
|
---|
118 | protected:
|
---|
119 | /*!
|
---|
120 | * \brief Process the childs of type IODevice, and log if needed
|
---|
121 | *
|
---|
122 | * This method must be called after computing datas;
|
---|
123 | * generally at the end of the reimplemented UpdateFrom or after acquiring datas in case of a sensor. \n
|
---|
124 | * It will call UpdateFrom methods of each child of type IODevice,
|
---|
125 | * and log all datas (this IODevice and its childs)
|
---|
126 | * if logging is enabled (see SetDataToLog(), AddDeviceToLog(),
|
---|
127 | * FrameworkManager::StartLog and FrameworkManager::AddDeviceToLog). \n
|
---|
128 | * If a thread is waiting on this IODevice (see Thread::WaitUpdate), it will be resumed.
|
---|
129 | *
|
---|
130 | * \param data data to process
|
---|
131 | */
|
---|
132 | void ProcessUpdate(io_data* data);
|
---|
133 |
|
---|
134 | private:
|
---|
135 | /*!
|
---|
136 | * \brief Update using provided datas
|
---|
137 | *
|
---|
138 | * This method is automatically called by ProcessUpdate()
|
---|
139 | * of the Object::Parent's if its Object::ObjectType is "IODevice". \n
|
---|
140 | * This method must be reimplemented, in order to process the data from the
|
---|
141 | *parent.
|
---|
142 | *
|
---|
143 | * \param data data from the parent to process
|
---|
144 | */
|
---|
145 | virtual void UpdateFrom(const io_data *data) = 0;
|
---|
146 |
|
---|
147 | class IODevice_impl *pimpl_;
|
---|
148 | };
|
---|
149 |
|
---|
150 | } // end namespace core
|
---|
151 | } // end namespace flair
|
---|
152 |
|
---|
153 | #endif // IO_DEVICE_H
|
---|