00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef TSOCKERMULTIPLEXERMETHODJOB_H
00020 #define TSOCKERMULTIPLEXERMETHODJOB_H
00021
00022 #include "ISocketMultiplexerJob.h"
00023 #include "CArch.h"
00024
00026
00029 template <class T>
00030 class TSocketMultiplexerMethodJob : public ISocketMultiplexerJob {
00031 public:
00032 typedef ISocketMultiplexerJob*
00033 (T::*Method)(ISocketMultiplexerJob*, bool, bool, bool);
00034
00036 TSocketMultiplexerMethodJob(T* object, Method method,
00037 CArchSocket socket, bool readable, bool writeable);
00038 virtual ~TSocketMultiplexerMethodJob();
00039
00040
00041 virtual ISocketMultiplexerJob*
00042 run(bool readable, bool writable, bool error);
00043 virtual CArchSocket getSocket() const;
00044 virtual bool isReadable() const;
00045 virtual bool isWritable() const;
00046
00047 private:
00048 T* m_object;
00049 Method m_method;
00050 CArchSocket m_socket;
00051 bool m_readable;
00052 bool m_writable;
00053 void* m_arg;
00054 };
00055
00056 template <class T>
00057 inline
00058 TSocketMultiplexerMethodJob<T>::TSocketMultiplexerMethodJob(T* object,
00059 Method method, CArchSocket socket,
00060 bool readable, bool writable) :
00061 m_object(object),
00062 m_method(method),
00063 m_socket(ARCH->copySocket(socket)),
00064 m_readable(readable),
00065 m_writable(writable)
00066 {
00067
00068 }
00069
00070 template <class T>
00071 inline
00072 TSocketMultiplexerMethodJob<T>::~TSocketMultiplexerMethodJob()
00073 {
00074 ARCH->closeSocket(m_socket);
00075 }
00076
00077 template <class T>
00078 inline
00079 ISocketMultiplexerJob*
00080 TSocketMultiplexerMethodJob<T>::run(bool read, bool write, bool error)
00081 {
00082 if (m_object != NULL) {
00083 return (m_object->*m_method)(this, read, write, error);
00084 }
00085 return NULL;
00086 }
00087
00088 template <class T>
00089 inline
00090 CArchSocket
00091 TSocketMultiplexerMethodJob<T>::getSocket() const
00092 {
00093 return m_socket;
00094 }
00095
00096 template <class T>
00097 inline
00098 bool
00099 TSocketMultiplexerMethodJob<T>::isReadable() const
00100 {
00101 return m_readable;
00102 }
00103
00104 template <class T>
00105 inline
00106 bool
00107 TSocketMultiplexerMethodJob<T>::isWritable() const
00108 {
00109 return m_writable;
00110 }
00111
00112 #endif