Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNSocketBase.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_OS_NET_SOCKETBASE_H 00025 #define MN_OS_NET_SOCKETBASE_H 00026 00027 #include <config.h> 00028 00029 #include "mnstream.h" 00030 #include "MNMsg.h" 00031 00032 /************************************************************* 00033 * Name: MNSocketBase 00034 * Short: most basic socket type 00035 */ 00036 00037 class MNSelector; 00038 00039 #undef USE_DEBUG_STRING_IN_SOCKETBASE 00040 00041 class MNSocketBase 00042 { 00043 public: 00044 MNSocketBase( const MNSocketBase& orig ); 00045 MNSocketBase(); 00046 virtual ~MNSocketBase(); 00047 00048 MNSocketBase& operator=( const MNSocketBase& orig ); 00049 00050 virtual int get_sockdesc ( ) const = 0; 00051 virtual void callback ( MNSelector* select, int fd ); 00052 virtual void write_enabled ( ); 00053 #if defined(USE_DEBUG_STRING_IN_SOCKETBASE) && !defined(NDEBUG) 00054 private: 00055 char* _debug_string; 00056 protected: 00057 void setDebugString( const char* str ); 00058 const char* getDebugString( ) const; 00059 #else /* defined(USE_DEBUG_STRING_IN_SOCKETBASE) && !defined(NDEBUG)*/ 00060 protected: 00061 inline void setDebugString( const char* ) { } 00062 inline const char* getDebugString( ) const { return ""; } 00063 #endif /* defined(USE_DEBUG_STRING_IN_SOCKETBASE) && !defined(NDEBUG)*/ 00064 }; 00065 00078 template <class T> 00079 struct MNSocketBaseT : public MNSocketBase 00080 { 00081 typedef void (T::*callback_function)( MNSelector* select, int fd ); 00082 typedef void (T::*write_function)( ); 00083 00084 T* _client; 00085 callback_function _fun; 00086 write_function _fun2; 00087 00088 MNSocketBaseT( T* client, callback_function fun ) 00089 : _client( client ) 00090 , _fun( fun ) 00091 { 00092 } 00093 00094 MNSocketBaseT( T* client, write_function fun2 ) 00095 : _client( client ) 00096 , _fun2( fun2 ) 00097 { 00098 } 00099 00100 void callback( MNSelector* select, int fd ) 00101 { 00102 (_client->*_fun)( select, fd ); 00103 } 00104 00105 void write_enabled( ) 00106 { 00107 (_client->*_fun2)(); 00108 } 00109 00110 virtual int get_sockdesc( ) const 00111 { 00112 return _client->get_sockdesc( ); 00113 } 00114 }; 00115 00116 #endif /* MN_OS_NET_SOCKETBASE_H */ 00117 00118

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8