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 | * \file IODevice.h
|
---|
7 | * \brief Abstract class for input/ouput system
|
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
9 | * \date 2011/05/01
|
---|
10 | * \version 4.0
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef IO_DEVICE_H
|
---|
14 | #define IO_DEVICE_H
|
---|
15 |
|
---|
16 | #include <Object.h>
|
---|
17 |
|
---|
18 | class IODevice_impl;
|
---|
19 | class Thread_impl;
|
---|
20 | class FrameworkManager_impl;
|
---|
21 |
|
---|
22 | namespace flair {
|
---|
23 | namespace core {
|
---|
24 |
|
---|
25 | class io_data;
|
---|
26 | class DataType;
|
---|
27 |
|
---|
28 | /*! \class IODevice
|
---|
29 | *
|
---|
30 | * \brief Abstract class for input/ouput system
|
---|
31 | *
|
---|
32 | * An input/output system is generally used to describe a sensor, an actuator or
|
---|
33 | *a filter. \n
|
---|
34 | * These systems can be linked (for exemple a sensor with a filter), when an
|
---|
35 | *IODevice
|
---|
36 | * is created with a parent of type IODevice.
|
---|
37 | * In this case, an update of the parent's data will call an update
|
---|
38 | * of the child's data (for exemple when a sensor gets new datas, a filter is
|
---|
39 | *automatically called). \n
|
---|
40 | * Output of this object can also be sent to a shared memory using the
|
---|
41 | *OutputToShMem method; in order to use it with an
|
---|
42 | * external program.
|
---|
43 | */
|
---|
44 | class IODevice : public Object {
|
---|
45 | friend class ::IODevice_impl;
|
---|
46 | friend class ::Thread_impl;
|
---|
47 | friend class ::FrameworkManager_impl;
|
---|
48 |
|
---|
49 | public:
|
---|
50 | /*!
|
---|
51 | * \brief Constructor
|
---|
52 | *
|
---|
53 | * Construct an IODevice of Object's type "IODevice" (see Object::ObjectType).
|
---|
54 | *\n
|
---|
55 | * If parent's Object::ObjectType is also "IODevice", this IODevice will be
|
---|
56 | *linked to its parent
|
---|
57 | * (see ProcessUpdate()).
|
---|
58 | *
|
---|
59 | * \param parent parent
|
---|
60 | * \param name name
|
---|
61 | */
|
---|
62 | IODevice(const Object *parent, std::string name);
|
---|
63 |
|
---|
64 | /*!
|
---|
65 | * \brief Destructor
|
---|
66 | *
|
---|
67 | */
|
---|
68 | virtual ~IODevice();
|
---|
69 |
|
---|
70 | /*!
|
---|
71 | * \brief Add an IODevice to the logs
|
---|
72 | *
|
---|
73 | * The IODevice will be automatically logged among this IODevice logs,
|
---|
74 | * if logging is enabled (see SetDataToLog(), FrameworkManager::StartLog
|
---|
75 | * and FrameworkManager::AddDeviceToLog). \n
|
---|
76 | * Logging happens when ProcessUpdate() is called. \n
|
---|
77 | * Note that when an IODevice is just added for logs (ie. no parent/child
|
---|
78 | * link between the two IODevice),
|
---|
79 | * UpdateFrom() is not automatically called.
|
---|
80 | *
|
---|
81 | * \param device IODevice to log
|
---|
82 | */
|
---|
83 | void AddDeviceToLog(const IODevice *device);
|
---|
84 |
|
---|
85 | /*!
|
---|
86 | * \brief Add an io_data to the log
|
---|
87 | *
|
---|
88 | * The io_data will be automatically logged if enabled (see
|
---|
89 | *FrameworkManager::StartLog
|
---|
90 | * and FrameworkManager::AddDeviceToLog),
|
---|
91 | * during call to ProcessUpdate().
|
---|
92 | *
|
---|
93 | * \param data data to log
|
---|
94 | */
|
---|
95 | void AddDataToLog(const io_data *data);
|
---|
96 |
|
---|
97 | /*!
|
---|
98 | * \brief Send the output to a shared memory
|
---|
99 | *
|
---|
100 | * Use this method to output log datas to a shared memory.
|
---|
101 | * This can be usefull to get datas from an external progam. \n
|
---|
102 | * Output happens when ProcessUpdate() is called. \n
|
---|
103 | * The name and the structure of the shared memory will be displayed when
|
---|
104 | * this method is called with true as argument. \n
|
---|
105 | * By default it is not enabled.
|
---|
106 | *
|
---|
107 | *
|
---|
108 | * \param enabled true to enable the output, false otherwise
|
---|
109 | */
|
---|
110 | void OutputToShMem(bool enabled);
|
---|
111 |
|
---|
112 | // TODO: these 2 method should be pure virtual
|
---|
113 | virtual DataType const &GetInputDataType() const;
|
---|
114 | virtual DataType const &GetOutputDataType() const;
|
---|
115 |
|
---|
116 | protected:
|
---|
117 | /*!
|
---|
118 | * \brief Process the childs of type IODevice, and log if needed
|
---|
119 | *
|
---|
120 | * This method must be called after computing datas;
|
---|
121 | * generally at the end of the reimplemented UpdateFrom or after acquiring
|
---|
122 | *datas in case of a sensor. \n
|
---|
123 | * It will call UpdateFrom methods of each child of type IODevice,
|
---|
124 | * and log all datas (this IODevice and its childs)
|
---|
125 | * if logging is enabled (see SetDataToLog(), AddDeviceToLog(),
|
---|
126 | * FrameworkManager::StartLog and FrameworkManager::AddDeviceToLog). \n
|
---|
127 | * If a thread is waiting on this IODevice (see Thread::WaitUpdate), it will be
|
---|
128 | *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
|
---|