TSocketMultiplexerMethodJob.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2004 Chris Schoeneman
00004  * 
00005  * This package is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * found in the file COPYING that should have accompanied this file.
00008  * 
00009  * This package is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
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     // IJob overrides
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     // do nothing
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

Generated on Fri Nov 6 00:18:46 2009 for synergy-plus by  doxygen 1.4.7