source: vendor/synergy/current/lib/net/TSocketMultiplexerMethodJob.h

Last change on this file was 2749, checked in by bird, 19 years ago

synergy v1.3.1 sources (zip).

File size: 2.5 KB
Line 
1/*
2 * synergy -- mouse and keyboard sharing utility
3 * Copyright (C) 2004 Chris Schoeneman
4 *
5 * This package is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * found in the file COPYING that should have accompanied this file.
8 *
9 * This package is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#ifndef TSOCKERMULTIPLEXERMETHODJOB_H
16#define TSOCKERMULTIPLEXERMETHODJOB_H
17
18#include "ISocketMultiplexerJob.h"
19#include "CArch.h"
20
21//! Use a method as a socket multiplexer job
22/*!
23A socket multiplexer job class that invokes a member function.
24*/
25template <class T>
26class TSocketMultiplexerMethodJob : public ISocketMultiplexerJob {
27public:
28 typedef ISocketMultiplexerJob*
29 (T::*Method)(ISocketMultiplexerJob*, bool, bool, bool);
30
31 //! run() invokes \c object->method(arg)
32 TSocketMultiplexerMethodJob(T* object, Method method,
33 CArchSocket socket, bool readable, bool writeable);
34 virtual ~TSocketMultiplexerMethodJob();
35
36 // IJob overrides
37 virtual ISocketMultiplexerJob*
38 run(bool readable, bool writable, bool error);
39 virtual CArchSocket getSocket() const;
40 virtual bool isReadable() const;
41 virtual bool isWritable() const;
42
43private:
44 T* m_object;
45 Method m_method;
46 CArchSocket m_socket;
47 bool m_readable;
48 bool m_writable;
49 void* m_arg;
50};
51
52template <class T>
53inline
54TSocketMultiplexerMethodJob<T>::TSocketMultiplexerMethodJob(T* object,
55 Method method, CArchSocket socket,
56 bool readable, bool writable) :
57 m_object(object),
58 m_method(method),
59 m_socket(ARCH->copySocket(socket)),
60 m_readable(readable),
61 m_writable(writable)
62{
63 // do nothing
64}
65
66template <class T>
67inline
68TSocketMultiplexerMethodJob<T>::~TSocketMultiplexerMethodJob()
69{
70 ARCH->closeSocket(m_socket);
71}
72
73template <class T>
74inline
75ISocketMultiplexerJob*
76TSocketMultiplexerMethodJob<T>::run(bool read, bool write, bool error)
77{
78 if (m_object != NULL) {
79 return (m_object->*m_method)(this, read, write, error);
80 }
81 return NULL;
82}
83
84template <class T>
85inline
86CArchSocket
87TSocketMultiplexerMethodJob<T>::getSocket() const
88{
89 return m_socket;
90}
91
92template <class T>
93inline
94bool
95TSocketMultiplexerMethodJob<T>::isReadable() const
96{
97 return m_readable;
98}
99
100template <class T>
101inline
102bool
103TSocketMultiplexerMethodJob<T>::isWritable() const
104{
105 return m_writable;
106}
107
108#endif
Note: See TracBrowser for help on using the repository browser.