[2] | 1 | // %flair:license{
|
---|
[13] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[2] | 4 | // %flair:license}
|
---|
[36] | 5 | // ---
|
---|
[2] | 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 |
|
---|
[13] | 23 | namespace flair {
|
---|
| 24 | namespace core {
|
---|
[2] | 25 |
|
---|
[13] | 26 | class io_data;
|
---|
| 27 | class DataType;
|
---|
[2] | 28 |
|
---|
[13] | 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;
|
---|
[2] | 49 |
|
---|
[13] | 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);
|
---|
[2] | 64 |
|
---|
[13] | 65 | /*!
|
---|
| 66 | * \brief Destructor
|
---|
| 67 | *
|
---|
| 68 | */
|
---|
| 69 | virtual ~IODevice();
|
---|
[2] | 70 |
|
---|
[13] | 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);
|
---|
[2] | 85 |
|
---|
[13] | 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);
|
---|
[2] | 97 |
|
---|
[13] | 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);
|
---|
[50] | 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;
|
---|
[2] | 122 |
|
---|
[13] | 123 | // TODO: these 2 method should be pure virtual
|
---|
| 124 | virtual DataType const &GetInputDataType() const;
|
---|
| 125 | virtual DataType const &GetOutputDataType() const;
|
---|
[2] | 126 |
|
---|
[50] | 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);
|
---|
[2] | 152 |
|
---|
[13] | 153 | private:
|
---|
| 154 | /*!
|
---|
| 155 | * \brief Update using provided datas
|
---|
| 156 | *
|
---|
| 157 | * This method is automatically called by ProcessUpdate()
|
---|
| 158 | * of the Object::Parent's if its Object::ObjectType is "IODevice". \n
|
---|
| 159 | * This method must be reimplemented, in order to process the data from the
|
---|
| 160 | *parent.
|
---|
| 161 | *
|
---|
| 162 | * \param data data from the parent to process
|
---|
| 163 | */
|
---|
| 164 | virtual void UpdateFrom(const io_data *data) = 0;
|
---|
[2] | 165 |
|
---|
[13] | 166 | class IODevice_impl *pimpl_;
|
---|
| 167 | };
|
---|
[2] | 168 |
|
---|
| 169 | } // end namespace core
|
---|
| 170 | } // end namespace flair
|
---|
| 171 |
|
---|
| 172 | #endif // IO_DEVICE_H
|
---|