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_WRITER_HPP_ 00023 #define _STREAM_WRITER_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 StreamWriter StreamWriter.hpp "StreamWriter.hpp" 00040 * @Description StreamWriter class 00041 * 00042 * The class which ultimately executes the write operations 00043 * @Author Joao Carreira 00044 */ 00045 class StreamWriter 00046 { 00047 public: 00048 /** 00049 * @Description Constructor. 00050 * 00051 * @Argument device The device on which the write operations will be executed 00052 * @Author Joao Carreira 00053 */ 00054 StreamWriter (Device* device); 00055 00056 /** 00057 * @Description This method will be called by StreamHandler each time a write event occurs 00058 * 00059 * @Argument bytesWritten The number of bytes written 00060 * @Argument requestedBytes The number of bytes requested to be written 00061 * @Argument data The data written to the device 00062 * @Argument success TRUE if the write operation was successful, FALSE otherwise 00063 * @Author Joao Carreira 00064 */ 00065 virtual void onWrite (size_t bytesWritten, size_t requestedBytes, const char* data, bool success, shared_ptr<StreamOperationHandlerMethodBase> streamOperationHandlerWrite); 00066 00067 /** 00068 * @Description Executes a write operation 00069 * 00070 * @Argument bytesToWrite The number of bytes to write to the device 00071 * @Argument data The data to be written to the device 00072 * @Argument streamOperationHandlerWrite The handler which will receive the write reply 00073 * @Author Joao Carreira 00074 */ 00075 virtual void doWrite (size_t bytesToWrite, const char* data, shared_ptr<StreamOperationHandlerMethodBase> streamOperationHandlerWrite); 00076 00077 /** 00078 * @Description Opens the device for writing 00079 * 00080 * @Argument streamHandler The StreamHandler which handles io results 00081 * @Argument proactor The proactor instance which will be "in charge" of this StreamWriter 00082 * @Author Joao Carreira 00083 */ 00084 virtual void open (ACE_Handler* streamHandler, ACE_Proactor* proactor); 00085 00086 /** 00087 * @Description File descriptor getter 00088 * 00089 * @Returns The file descriptor 00090 * @Author Joao Carreira 00091 */ 00092 virtual int getFileDescriptor() const; 00093 00094 /** 00095 * @Description Destructor 00096 * 00097 * @Author Joao Carreira 00098 */ 00099 virtual ~StreamWriter(); 00100 00101 private: 00102 ACE_Asynch_Write_Stream writeStream_; 00103 Device* device_; 00104 00105 }; // class StreamWriter 00106 00107 } // namespace io 00108 } // namespace support 00109 } // namespace mermaid 00110 00111 #endif // _STREAM_WRITER_HPP_