IOManager.hpp

00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 #ifndef _IOMANAGER_HPP_
00023 #define _IOMANAGER_HPP_
00024 
00025 #include <string>
00026 #include <map>
00027 
00028 #include <ActiveObject.hpp>
00029 
00030 #include "DeviceConfigurator.hpp"
00031 #include "DeviceHandle.hpp"
00032 #include "Device.hpp"
00033 #include "IOThread.hpp"
00034 #include "StreamOperationHandlerMethod.hpp"
00035 
00036 namespace mermaid
00037 {
00038   namespace support
00039   {
00040     namespace io
00041     {
00042     
00043       using boost::shared_ptr;
00044       using mermaid::support::activeobject::ActiveObject;
00045       
00046       /**
00047       * @Class IOManager IOManager.hpp "IOManager.hpp"
00048       * @Description IOManager class
00049       *
00050       * This is the class (singleton) which manages IO devices.
00051       * @Author Joao Carreira
00052       */
00053       class IOManager
00054       {
00055         public:
00056         
00057           /**
00058           * @Description Method used to retrieve the IOManager instance.
00059           *
00060           * This method is used to retrieve the IOManager (singleton entity) instance.
00061           * @Returns IOManager instance
00062           * @Author Joao Carreira
00063           */
00064           static shared_ptr<IOManager> getInstance();
00065           
00066           /**
00067           * @Description Creates a device.
00068           *
00069           * This method creates a device used to perform IO asynchronous operations in devices.
00070           * @Argument filename Name of the physical device.
00071           * @Argument owner ActiveObject in which this device is being created.
00072           * @Argument deviceConfigurator DeviceConfigurator used to configure the device when it has been opened.
00073           * @Returns Device handle to the created device.
00074           * @Author Joao Carreira
00075           */
00076           shared_ptr<DeviceHandle> createDevice (std::string filename, shared_ptr<ActiveObject> owner, shared_ptr<DeviceConfigurator> deviceConfigurator, int expectedDataSize);
00077           
00078           /**
00079           * @Description Start reading from a device.
00080           *
00081           * Enable read operations in a device. When read is enabled and there is available data the callback will be called.
00082           * @Argument device The device on which we want to enable read operations
00083           * @Author Joao Carreira
00084           */
00085           void enableDeviceRead (shared_ptr<Device> device, shared_ptr<StreamOperationHandlerMethodBase> streamOperationHandlerRead);
00086           
00087           /**
00088            * @Description Enable write operations in a device.
00089            *
00090            * Enable write operations in a device. This method must be called before writing to the device
00091            * @Argument device The device on which we want to enable read operations
00092            * @Author Joao Carreira
00093            */
00094           void enableDeviceWrite (shared_ptr<Device> device);
00095           
00096           /**
00097            * @Description Closes the given device
00098            * @Author Joao Carreira
00099            */
00100           void closeDevice (shared_ptr<Device> device);
00101           
00102           /**
00103           * @Description IOThread getter
00104           * @Returns IOThread of the IOManager
00105           * @Author Joao Carreira
00106           */
00107           shared_ptr<IOThread> getIOThread() const;
00108           
00109           /**
00110           * @Description Destructor
00111           * @Author Joao Carreira
00112           */
00113           ~IOManager();
00114           
00115         private:
00116           IOManager();
00117           static shared_ptr<IOManager> instance_;
00118           
00119           // Association between a device object and its handle.
00120           std::map<shared_ptr<Device>, shared_ptr<DeviceHandle> > deviceHandleMap_;
00121           
00122           // The IOThread which handles all the device events (read/write operations completed)
00123           shared_ptr<IOThread> ioThread_;
00124           
00125       }; // class IOManager
00126       
00127     } // namespace io
00128   } // namespace support
00129 } // namespace mermaid
00130 
00131 #endif // _IOMANAGER_HPP_
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3