DeviceHandle.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 _DEVICE_HANDLE_HPP_
00023 #define _DEVICE_HANDLE_HPP_
00024 
00025 
00026 #include <cstring>
00027 #include "StreamOperationHandlerMethod.hpp"
00028 #include "Device.hpp"
00029 #include "DeviceConfigurator.hpp"
00030 
00031 namespace mermaid
00032 {
00033   namespace support
00034   {
00035     namespace io
00036     {
00037     
00038       using boost::shared_ptr;
00039       
00040       /**
00041        * @Class DeviceHandle DeviceHandle.hpp "DeviceHandle.hpp"
00042        * @Description DeviceHandle class
00043        *
00044        * This is the class which abstracts the device.
00045        * @Author Joao Carreira
00046        */
00047       class DeviceHandle
00048       {
00049         public:
00050         
00051           /**
00052            * @Description Constructor.
00053            *
00054            * @Argument device The device which this handle refers to.
00055            * @Author Joao Carreira
00056            */
00057           DeviceHandle (shared_ptr<Device> device);
00058           
00059           /**
00060            * @Description Starts reading from the device.
00061            *
00062            * @Argument streamOperationHandlerRead The handler which will receive read replies.
00063            * @Author Joao Carreira
00064            */
00065           virtual void enableRead (shared_ptr<StreamOperationHandlerMethodBase> streamOperationHandlerRead);
00066           
00067           /**
00068            * @Description Writes data to the device.
00069            *
00070            * @Argument bytesToWrite Number of bytes to be written
00071            * @Argument data Data to be written
00072           * @Argument streamOperationHandlerWrite The handler which will receive the operation reply
00073            * @Author Joao Carreira
00074            */
00075           virtual void write (size_t bytesToWrite, const char* data, shared_ptr<StreamOperationHandlerMethodBase> streamOperationHandlerWrite);
00076           
00077           /**
00078            * @Description Closes the device
00079            *
00080            * @Author Joao Carreira
00081            */
00082           virtual void close();
00083           
00084           //TODO: check if this is really needed. Should DeviceConfigurator be called in the IOThread?
00085           /**
00086            * @Description configures this device
00087            *
00088            * @Author Joao Carreira
00089            */
00090           virtual void configureDevice (shared_ptr<DeviceConfigurator>);
00091           
00092           /**
00093            * @Description Destructor.
00094            * @Author Joao Carreira
00095            */
00096           virtual ~DeviceHandle();
00097           
00098         private:
00099         
00100           shared_ptr<Device> device_;
00101           bool closed_;
00102           
00103       }; // class DeviceHandle
00104       
00105     } // namespace  io
00106   } // namespace support
00107 } // namespace mermaid
00108 
00109 
00110 #endif //_DEVICE_HANDLE_HPP_
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3