2012-06-10 16:50:54 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-08-07 00:38:51 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
2026-02-28 03:47:09 +00:00
|
|
|
#include <QtSystemDetection>
|
2025-06-19 22:53:21 +00:00
|
|
|
// Consider whether or not to use either encapsulation (as below)
|
2012-06-10 16:50:54 +00:00
|
|
|
// or inheritance (as it is now) for the ARCH stuff.
|
|
|
|
|
//
|
|
|
|
|
// case for encapsulation:
|
|
|
|
|
// pros:
|
|
|
|
|
// - compiler errors for missing pv implementations are not absolutely bonkers.
|
|
|
|
|
// - function names don't have to be so verbose.
|
|
|
|
|
// - easier to understand and debug.
|
|
|
|
|
// - ctors in IArch implementations can call other implementations.
|
|
|
|
|
// cons:
|
|
|
|
|
// - slightly more code for calls to ARCH.
|
|
|
|
|
// - you'll have to modify each ARCH call.
|
|
|
|
|
//
|
|
|
|
|
// also, we may want to consider making each encapsulated
|
|
|
|
|
// class lazy-loaded so that apps like the daemon don't load
|
|
|
|
|
// stuff when they don't need it.
|
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#pragma once
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2026-02-28 03:47:09 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "arch/win32/ArchDaemonWindows.h"
|
|
|
|
|
#include "arch/win32/ArchLogWindows.h"
|
|
|
|
|
#include "arch/win32/ArchMultithreadWindows.h"
|
|
|
|
|
#include "arch/win32/ArchNetworkWinsock.h"
|
2026-02-28 03:40:15 +00:00
|
|
|
#else
|
2025-10-15 21:29:44 +00:00
|
|
|
#include "arch/ArchDaemonNone.h"
|
2024-07-02 19:07:06 +00:00
|
|
|
#include "arch/unix/ArchLogUnix.h"
|
|
|
|
|
#include "arch/unix/ArchMultithreadPosix.h"
|
2025-06-14 02:23:54 +00:00
|
|
|
#include "arch/unix/ArchNetworkBSD.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\def ARCH
|
2014-11-11 13:51:47 +00:00
|
|
|
This macro evaluates to the singleton Arch object.
|
2012-06-10 16:50:54 +00:00
|
|
|
*/
|
2024-07-02 19:07:06 +00:00
|
|
|
#define ARCH (Arch::getInstance())
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
|
//! Delegating implementation of architecture dependent interfaces
|
|
|
|
|
/*!
|
|
|
|
|
This class is a centralized interface to all architecture dependent
|
|
|
|
|
interface implementations (except miscellaneous functions). It
|
|
|
|
|
instantiates an implementation of each interface and delegates calls
|
|
|
|
|
to each method to those implementations. Clients should use the
|
|
|
|
|
\c ARCH macro to access this object. Clients must also instantiate
|
|
|
|
|
exactly one of these objects before attempting to call any method,
|
|
|
|
|
typically at the beginning of \c main().
|
|
|
|
|
*/
|
2025-05-30 22:26:02 +00:00
|
|
|
class Arch : public ARCH_DAEMON, public ARCH_LOG, public ARCH_MULTITHREAD, public ARCH_NETWORK
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2024-07-02 19:07:06 +00:00
|
|
|
Arch();
|
2025-04-30 22:17:25 +00:00
|
|
|
~Arch() override = default;
|
2024-07-02 19:07:06 +00:00
|
|
|
|
2026-02-28 03:47:09 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
2024-07-02 19:07:06 +00:00
|
|
|
//! Call init on other arch classes.
|
|
|
|
|
/*!
|
|
|
|
|
Some arch classes depend on others to exist first. When init is called
|
|
|
|
|
these classes will have ARCH available for use.
|
|
|
|
|
*/
|
2025-04-28 01:27:48 +00:00
|
|
|
void init() override;
|
2025-08-07 00:38:51 +00:00
|
|
|
#endif
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// accessors
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//! Return the singleton instance
|
|
|
|
|
/*!
|
|
|
|
|
The client must have instantiated exactly once Arch object before
|
|
|
|
|
calling this function.
|
|
|
|
|
*/
|
|
|
|
|
static Arch *getInstance();
|
|
|
|
|
|
2025-06-12 02:59:50 +00:00
|
|
|
/**
|
|
|
|
|
* @brief blocks calling thread for timout seconds
|
|
|
|
|
* @param timeout - blocking time in seconds. if < 0 not blocked if == 0 then caller yields the CPU
|
|
|
|
|
*/
|
|
|
|
|
static void sleep(double timeout);
|
|
|
|
|
|
2025-06-12 03:18:35 +00:00
|
|
|
/**
|
|
|
|
|
* @brief time
|
|
|
|
|
* @return Returns the number of seconds since some arbitrary starting time.
|
|
|
|
|
* This should return as high a precision as reasonable.
|
|
|
|
|
*/
|
|
|
|
|
static double time();
|
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
static Arch *s_instance;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//! Convenience object to lock/unlock an arch mutex
|
2024-10-17 18:04:35 +00:00
|
|
|
class ArchMutexLock
|
|
|
|
|
{
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2025-04-30 22:17:25 +00:00
|
|
|
explicit ArchMutexLock(ArchMutex mutex) : m_mutex(mutex)
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
|
|
|
|
ARCH->lockMutex(m_mutex);
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
ArchMutexLock(ArchMutexLock const &) = delete;
|
|
|
|
|
ArchMutexLock(ArchMutexLock &&) = delete;
|
2024-10-17 18:04:35 +00:00
|
|
|
~ArchMutexLock()
|
|
|
|
|
{
|
|
|
|
|
ARCH->unlockMutex(m_mutex);
|
|
|
|
|
}
|
2024-07-02 19:07:06 +00:00
|
|
|
|
|
|
|
|
ArchMutexLock &operator=(ArchMutexLock const &) = delete;
|
|
|
|
|
ArchMutexLock &operator=(ArchMutexLock &&) = delete;
|
2020-11-03 10:52:56 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
private:
|
2024-07-02 19:07:06 +00:00
|
|
|
ArchMutex m_mutex;
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|