Deskflow
1.26.0.418
Keyboard and mouse sharing utility
Toggle main menu visibility
Loading...
Searching...
No Matches
SocketMultiplexer.h
Go to the documentation of this file.
1
/*
2
* Deskflow -- mouse and keyboard sharing utility
3
* SPDX-FileCopyrightText: (C) 2012 - 2016 Synergy App Ltd
4
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
5
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6
*/
7
8
#pragma once
9
10
#include <list>
11
#include <map>
12
13
template
<
class
T>
class
CondVar
;
14
class
Mutex
;
15
class
Thread
;
16
class
ISocket
;
17
class
ISocketMultiplexerJob
;
18
20
23
class
SocketMultiplexer
24
{
25
public
:
26
SocketMultiplexer
();
27
SocketMultiplexer
(
SocketMultiplexer
const
&) =
delete
;
28
SocketMultiplexer
(
SocketMultiplexer
&&) =
delete
;
29
~SocketMultiplexer
();
30
31
SocketMultiplexer
&
operator=
(
SocketMultiplexer
const
&) =
delete
;
32
SocketMultiplexer
&
operator=
(
SocketMultiplexer
&&) =
delete
;
33
35
36
37
void
addSocket
(
ISocket
*,
ISocketMultiplexerJob
*);
38
39
void
removeSocket
(
ISocket
*);
40
42
44
45
// maybe belongs on ISocketMultiplexer
46
static
SocketMultiplexer
*
getInstance
();
47
49
50
private
:
51
// list of jobs. we use a list so we can safely iterate over it
52
// while other threads modify it.
53
using
SocketJobs = std::list<ISocketMultiplexerJob *>;
54
using
JobCursor = SocketJobs::iterator;
55
using
SocketJobMap = std::map<ISocket *, JobCursor>;
56
57
// service sockets. the service thread will only access m_sockets
58
// and m_update while m_pollable and m_polling are true. all other
59
// threads must only modify these when m_pollable and m_polling are
60
// false. only the service thread sets m_polling.
61
[[noreturn]]
void
serviceThread(
const
void
*);
62
63
// create, iterate, and destroy a cursor. a cursor is used to
64
// safely iterate through the job list while other threads modify
65
// the list. it works by inserting a dummy item in the list and
66
// moving that item through the list. the dummy item will never
67
// be removed by other edits so an iterator pointing at the item
68
// remains valid until we remove the dummy item in deleteCursor().
69
// nextCursor() finds the next non-dummy item, moves our dummy
70
// item just past it, and returns an iterator for the non-dummy
71
// item. all cursor calls lock the mutex for their duration.
72
JobCursor newCursor();
73
JobCursor nextCursor(JobCursor);
74
void
deleteCursor(JobCursor);
75
76
// lock out locking the job list. this blocks if another thread
77
// has already locked out locking. once it returns, only the
78
// calling thread will be able to lock the job list after any
79
// current lock is released.
80
void
lockJobListLock();
81
82
// lock the job list. this blocks if the job list is already
83
// locked. the calling thread must have called requestJobLock.
84
void
lockJobList();
85
86
// unlock the job list and the lock out on locking.
87
void
unlockJobList();
88
89
private
:
90
Mutex
*m_mutex =
nullptr
;
91
Thread
*m_thread =
nullptr
;
92
bool
m_update =
false
;
93
CondVar<bool>
*m_jobsReady =
nullptr
;
94
CondVar<bool>
*m_jobListLock =
nullptr
;
95
CondVar<bool>
*m_jobListLockLocked =
nullptr
;
96
Thread
*m_jobListLocker =
nullptr
;
97
Thread
*m_jobListLockLocker =
nullptr
;
98
99
SocketJobs m_socketJobs = {};
100
SocketJobMap m_socketJobMap = {};
101
ISocketMultiplexerJob *m_cursorMark =
nullptr
;
102
};
CondVar
Condition variable.
Definition
CondVar.h:121
ISocketMultiplexerJob
Socket multiplexer job.
Definition
ISocketMultiplexerJob.h:18
ISocket
Generic socket interface.
Definition
ISocket.h:19
Mutex
Mutual exclusion.
Definition
Mutex.h:22
SocketMultiplexer::addSocket
void addSocket(ISocket *, ISocketMultiplexerJob *)
Definition
SocketMultiplexer.cpp:62
SocketMultiplexer::SocketMultiplexer
SocketMultiplexer(SocketMultiplexer &&)=delete
SocketMultiplexer::SocketMultiplexer
SocketMultiplexer()
Definition
SocketMultiplexer.cpp:26
SocketMultiplexer::SocketMultiplexer
SocketMultiplexer(SocketMultiplexer const &)=delete
SocketMultiplexer::getInstance
static SocketMultiplexer * getInstance()
SocketMultiplexer::operator=
SocketMultiplexer & operator=(SocketMultiplexer const &)=delete
SocketMultiplexer::operator=
SocketMultiplexer & operator=(SocketMultiplexer &&)=delete
SocketMultiplexer::removeSocket
void removeSocket(ISocket *)
Definition
SocketMultiplexer.cpp:96
Thread
Thread handle.
Definition
Thread.h:33
src
lib
net
SocketMultiplexer.h
Generated by
1.18.0