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 _STREAM_READER_HPP_ 00023 #define _STREAM_READER_HPP_ 00024 00025 #include "Device.hpp" 00026 #include <ace/Asynch_IO.h> 00027 00028 00029 namespace mermaid 00030 { 00031 namespace support 00032 { 00033 namespace io 00034 { 00035 00036 using boost::shared_ptr; 00037 00038 /** 00039 * @Class StreamReader StreamReader.hpp "StreamReader.hpp" 00040 * @Description StreamReader class 00041 * 00042 * The class which ultimately executes the read operations 00043 * @Author Joao Carreira 00044 */ 00045 class StreamReader 00046 { 00047 public: 00048 00049 /** 00050 * @Description Constructor 00051 * 00052 * @Argument device The device on which the read operations will be executed 00053 * @Author Joao Carreira 00054 */ 00055 StreamReader (Device* device); 00056 00057 /** 00058 * @Description This method will be called by StreamHandler each time a read event occurs 00059 * 00060 * @Argument bytesRead The number of bytes read 00061 * @Argument requestedBytesRead The number of bytes requested to be read 00062 * @Argument data The data read from the device 00063 * @Argument success TRUE if the read operation was successful, FALSE otherwise 00064 * @Author Joao Carreira 00065 */ 00066 virtual void onRead (size_t bytesRead, size_t requestedBytesRead, const char* data, bool success); 00067 00068 /** 00069 * @Description Executes a read operation 00070 * 00071 * @Author Joao Carreira 00072 */ 00073 virtual void doRead(); 00074 00075 /** 00076 * @Description Opens the device for reading 00077 * 00078 * @Argument streamHandler The StreamHandler which handles io results 00079 * @Argument proactor The proactor instance which will be "in charge" of this StreamReader 00080 * @Author Joao Carreira 00081 */ 00082 virtual void open (ACE_Handler* streamHandler, ACE_Proactor* proactor); 00083 00084 /** 00085 * @Description File descriptor getter 00086 * 00087 * @Returns The file descriptor 00088 * @Author Joao Carreira 00089 */ 00090 virtual int getFileDescriptor() const { 00091 return device_->getFileDescriptor(); 00092 } 00093 00094 /** 00095 * @Description Destructor 00096 * @Author Joao Carreira 00097 */ 00098 virtual ~StreamReader(); 00099 00100 private: 00101 ACE_Asynch_Read_Stream readStream_; 00102 Device* device_; 00103 00104 }; // class StreamReader 00105 00106 } // namespace io 00107 } // namespace support 00108 } // namespace mermaid 00109 00110 #endif // _STREAM_READER_HPP_