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 _STREAMHANDLER_HPP_ 00023 #define _STREAMHANDLER_HPP_ 00024 00025 #include "StreamReader.hpp" 00026 #include "StreamWriter.hpp" 00027 #include <ace/Asynch_IO.h> 00028 00029 #include <map> 00030 00031 namespace mermaid 00032 { 00033 namespace support 00034 { 00035 namespace io 00036 { 00037 00038 using boost::shared_ptr; 00039 using std::map; 00040 00041 /** 00042 * @Class StreamHandler StreamHandler.hpp "StreamHandler.hpp" 00043 * @Description StreamHandler class 00044 * 00045 * The class which handles the events from ACE_Proactor 00046 * @Author Joao Carreira 00047 */ 00048 class StreamHandler : public ACE_Handler 00049 { 00050 public: 00051 00052 /** 00053 * @Description Associate a file descriptor with a StreamReader 00054 * 00055 * @Argument fileDescriptor File descriptor to be associated 00056 * @Argument streamReader StreamReader to be associated 00057 * @Author Joao Carreira 00058 */ 00059 virtual void associateFileDescriptorWithStreamReader (int fileDescriptor, shared_ptr<StreamReader> streamReader); 00060 00061 /** 00062 * @Description Associate a file descriptor with a StreamWriter 00063 * 00064 * @Argument fileDescriptor File descriptor to be associated 00065 * @Argument streamWriter StreamWriter to be associated 00066 * @Author Joao Carreira 00067 */ 00068 virtual void associateFileDescriptorWithStreamWriter (int fileDescriptor, shared_ptr<StreamWriter> streamWriter); 00069 00070 /** 00071 * @Description Get the StreamWriter associated with a given file descriptor 00072 * 00073 * @Argument fileDescriptor The file descriptor which is associated with a StreamWriter 00074 * @Returns The StreamWriter associated with the given file descriptor 00075 * @Author Joao Carreira 00076 */ 00077 virtual shared_ptr<StreamWriter> getAssociatedStreamWriter (int fileDescriptor); 00078 00079 /** 00080 * @Description Close the StreamWriter associated with this file descriptor 00081 * 00082 * @Argument fileDescriptor The file descriptor which is associated with the StreamWriter to be closed 00083 * @Author Joao Carreira 00084 */ 00085 virtual void closeStreamWriter (int fileDescriptor); 00086 00087 /** 00088 * @Description Close the StreamReader associated with this file descriptor 00089 * 00090 * @Argument fileDescriptor The file descriptor which is associated with the StreamReader to be closed 00091 * @Author Joao Carreira 00092 */ 00093 virtual void closeStreamReader (int fileDescriptor); 00094 00095 /** 00096 * @Description Handles read operations events 00097 * 00098 * @Argument result The result of an io operation 00099 * @Author Joao Carreira 00100 */ 00101 virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result); 00102 00103 /** 00104 * @Description Handles write operations events 00105 * 00106 * @Argument result The result of an io operation 00107 * @Author Joao Carreira 00108 */ 00109 virtual void handle_write_stream (const ACE_Asynch_Write_Stream::Result &result); 00110 00111 /** 00112 * @Description Destructor 00113 * @Author Joao Carreira 00114 */ 00115 virtual ~StreamHandler(); 00116 00117 protected: 00118 map<int, shared_ptr<StreamReader> > streamReaderMap_; 00119 map<int, shared_ptr<StreamWriter> > streamWriterMap_; 00120 00121 }; // class StreamHandler 00122 00123 } // namespace io 00124 } // namespace support 00125 } // namespace mermaid 00126 00127 #endif //_STREAMHANDLER_HPP_