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