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