• Main Page
  • Classes
  • Files
  • File List

TSocketMultiplexerMethodJob.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2004 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
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     // IJob overrides
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     // do nothing
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

Generated on Sun May 19 2013 00:00:05 for Synergy by  doxygen 1.7.1