Deskflow 1.22.0.197
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
Arch.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
4 * SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
5 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
6 */
7
8// Consider whether or not to use either encapsulation (as below)
9// or inheritance (as it is now) for the ARCH stuff.
10//
11// case for encapsulation:
12// pros:
13// - compiler errors for missing pv implementations are not absolutely bonkers.
14// - function names don't have to be so verbose.
15// - easier to understand and debug.
16// - ctors in IArch implementations can call other implementations.
17// cons:
18// - slightly more code for calls to ARCH.
19// - you'll have to modify each ARCH call.
20//
21// also, we may want to consider making each encapsulated
22// class lazy-loaded so that apps like the daemon don't load
23// stuff when they don't need it.
24
25#pragma once
26
27#include "arch/ArchString.h"
28#include "common/Common.h"
29
30#if SYSAPI_WIN32
31
36
37#elif SYSAPI_UNIX
38
43
44#endif
45
50#define ARCH (Arch::getInstance())
51
53
62class Arch : public ARCH_DAEMON, public ARCH_LOG, public ARCH_MULTITHREAD, public ARCH_NETWORK, public ArchString
63{
64public:
65 Arch();
66 explicit Arch(Arch *arch);
67 ~Arch() override = default;
68
70
74 void init() override;
75
76 //
77 // accessors
78 //
79
81
85 static Arch *getInstance();
86
87 static void setInstance(Arch *s)
88 {
89 s_instance = s;
90 }
91
96 static void sleep(double timeout);
97
103 static double time();
104
105private:
106 static Arch *s_instance;
107};
108
111{
112public:
113 explicit ArchMutexLock(ArchMutex mutex) : m_mutex(mutex)
114 {
115 ARCH->lockMutex(m_mutex);
116 }
117 ArchMutexLock(ArchMutexLock const &) = delete;
120 {
121 ARCH->unlockMutex(m_mutex);
122 }
123
126
127private:
128 ArchMutex m_mutex;
129};
#define ARCH_DAEMON
Definition ArchDaemonNone.h:12
#define ARCH_LOG
Definition ArchLogUnix.h:12
#define ARCH_MULTITHREAD
Definition ArchMultithreadPosix.h:16
#define ARCH_NETWORK
Definition ArchNetworkBSD.h:18
static fd_set FAR fd_set FAR fd_set FAR const struct timeval FAR * timeout
Definition ArchNetworkWinsock.cpp:39
#define ARCH
Definition Arch.h:50
ArchMutexImpl * ArchMutex
Opaque mutex type. An opaque type representing a mutex.
Definition IArchMultithread.h:39
ArchMutexLock & operator=(ArchMutexLock const &)=delete
ArchMutexLock & operator=(ArchMutexLock &&)=delete
ArchMutexLock(ArchMutexLock &&)=delete
~ArchMutexLock()
Definition Arch.h:119
ArchMutexLock(ArchMutexLock const &)=delete
ArchMutexLock(ArchMutex mutex)
Definition Arch.h:113
ArchString()=default
Delegating implementation of architecture dependent interfaces.
Definition Arch.h:63
static void setInstance(Arch *s)
Definition Arch.h:87
static double time()
time
Definition Arch.cpp:56
static Arch * getInstance()
Return the singleton instance.
Definition Arch.cpp:41
~Arch() override=default
void init() override
Call init on other arch classes.
Definition Arch.cpp:33
Arch()
Definition Arch.cpp:22
static void sleep(double timeout)
blocks calling thread for timout seconds
Definition Arch.cpp:47