Compare commits
208 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 56f7a0d7b5 | |||
| 3b27fa5771 | |||
| 72ddcdb7f5 | |||
| 4a7d031bc6 | |||
| 45fcdde636 | |||
| 9a799294f7 | |||
| 46db468ede | |||
| 28957a3fa8 | |||
| 2c55f4fe06 | |||
| a4c82869a6 | |||
| f33848f9b8 | |||
| f497b6886a | |||
| 21d38ff444 | |||
| e828563190 | |||
| c7873f2f81 | |||
| 9f72b44d2a | |||
| 8dcd9b0c01 | |||
| e436b41ab0 | |||
| c2eae36650 | |||
| 1079c22736 | |||
| d69febe2dc | |||
| c6a97c24a2 | |||
| d9ec93e7ee | |||
| 9db11a90eb | |||
| c327c80d63 | |||
| 0884a267d1 | |||
| d1b810baa5 | |||
| 6bf25c0089 | |||
| f4b561ac64 | |||
| 28c690074c | |||
| 97c5a17e9d | |||
| f51abad8cc | |||
| ae5ba4e51f | |||
| 9413393057 | |||
| 79b445373b | |||
| 9beea1abfe | |||
| a88a67d47f | |||
| 7fd9070a80 | |||
| e37cea2d6b | |||
| 181d862838 | |||
| 6ca980e3e5 | |||
| 94be5f7498 | |||
| 32e6a84a6f | |||
| b9964b5e90 | |||
| 422b4c3a23 | |||
| 05e32497d1 | |||
| 9905f32738 | |||
| 29e9b8ae3b | |||
| fe3c41f857 | |||
| 3ececbcfd9 | |||
| c12aa4c6e9 | |||
| fc58688bb0 | |||
| 77bdde5434 | |||
| 3472ff6ce5 | |||
| 082d27a88c | |||
| 2d3105206d | |||
| c6778dc9be | |||
| 36e985d8ab | |||
| 865365b2fa | |||
| 8a83f68ff0 | |||
| 245fa815d2 | |||
| f12f312dab | |||
| dded2e3711 | |||
| d71d4eaf07 | |||
| bc9f47c957 | |||
| 0ea2576032 | |||
| 0100cb796e | |||
| 8ec40dd74b | |||
| 4034d15fb3 | |||
| 1a9f8d5cdc | |||
| 66ddaca410 | |||
| 2c2a5c0269 | |||
| e42d3b45b6 | |||
| 5aa9b1bfd4 | |||
| cfbfa88cdc | |||
| 4a92a3295b | |||
| ede27975d7 | |||
| a175c293f6 | |||
| b39b133c9d | |||
| 5976da7e5b | |||
| 7fe50748f3 | |||
| 0474e10b03 | |||
| 2421a8b725 | |||
| ab4fbd1c85 | |||
| 8f6f014bcd | |||
| 47d44db497 | |||
| 879283f46f | |||
| cbbfd495e3 | |||
| 1692bec7e6 | |||
| f9f12a9500 | |||
| 2b38fe6f91 | |||
| 1479a50af5 | |||
| 4c2b9eb9e4 | |||
| 872db8910e | |||
| e06b6b0be4 | |||
| a04572a8c2 | |||
| 5d434d9857 | |||
| 958e14cb13 | |||
| 7116ddac86 | |||
| 5d594dd6be | |||
| f784705a7e | |||
| 22b1e8e543 | |||
| cf9e2ecf49 | |||
| cb508f5c3a | |||
| 26cc85e878 | |||
| 776b02aafc | |||
| 42cd01efd7 | |||
| a7a54ad8a7 | |||
| 20bc88eb1f | |||
| 969b642e0b | |||
| a89f3b6892 | |||
| a973d4277c | |||
| b8124107aa | |||
| 0691d586e7 | |||
| e8c85611a0 | |||
| 0321b2d36e | |||
| f4a49749c7 | |||
| 59ed15628e | |||
| dddb6aadf1 | |||
| 2110411c6d | |||
| b29c5b1bb2 | |||
| 07a217f54f | |||
| aacf922319 | |||
| a80e255bb0 | |||
| 6299f04b59 | |||
| 97006889bd | |||
| f0bb4e5cb3 | |||
| dcb047b6c5 | |||
| 551368a2d2 | |||
| 4d738b4784 | |||
| 06a616ef42 | |||
| 90a651b409 | |||
| dbc7aebfbc | |||
| 024436d82f | |||
| b6bc469744 | |||
| c4e47c0f2c | |||
| 3d712d5621 | |||
| 4e2ad25fc1 | |||
| 66e201c8ef | |||
| 3a35b183d3 | |||
| c15214aee7 | |||
| 5fd4d93f7f | |||
| 84e289bc30 | |||
| 04943fad79 | |||
| a7c1dc4520 | |||
| a73e8df01e | |||
| 0d6837a948 | |||
| ed99306417 | |||
| 782702fe74 | |||
| 5686d24626 | |||
| 818d588b65 | |||
| 86e109baf5 | |||
| fa1ee0690e | |||
| d535593d1d | |||
| f89168d00a | |||
| fb3c8eb965 | |||
| e247f3813a | |||
| f4618ee085 | |||
| 5430625a7e | |||
| eac59768ea | |||
| cb05ece6b6 | |||
| 044c9b24f3 | |||
| a3fe66f213 | |||
| 60a148ce68 | |||
| da5a2088c8 | |||
| 89abcfb238 | |||
| 87704fedb1 | |||
| 3eef21c8df | |||
| 6fbb60a3c2 | |||
| a5522729aa | |||
| 36b4bb09bc | |||
| 8170dd4e99 | |||
| c2a658256e | |||
| bc350852e7 | |||
| 898629f824 | |||
| 7b437b8d35 | |||
| 03b062c96e | |||
| 6c5d08ba7f | |||
| b77d722577 | |||
| bd8e2c5335 | |||
| 13c993c798 | |||
| 7e568121ee | |||
| 115ee2b8af | |||
| 3e4a085bc1 | |||
| 0ce5c2de9a | |||
| ffce22f5a9 | |||
| e40cc11fd5 | |||
| ebec6331cd | |||
| 197b9ed886 | |||
| 8f7fbc0a21 | |||
| 0f5a04825a | |||
| b8835a8a5a | |||
| 8bb6056469 | |||
| 3adcb64f57 | |||
| bc9b1d1178 | |||
| e038dd2b0b | |||
| 1286c18e1d | |||
| 5d94dd0dbf | |||
| b3e03f2856 | |||
| b62e82e792 | |||
| 7837bf416e | |||
| d4d6cbb7fb | |||
| d5910d77ec | |||
| d01a023a8b | |||
| d246d9527a | |||
| a31cff0225 | |||
| da06e97521 | |||
| 7e4d43f1cc |
13
.github/actions/install-dependencies/action.yml
vendored
13
.github/actions/install-dependencies/action.yml
vendored
@ -13,8 +13,8 @@ inputs:
|
||||
description: "The version of Qt to install (Windows & macOS)"
|
||||
required: false
|
||||
|
||||
qt-install-dir:
|
||||
description: "The path to install Qt into (Windows & macOS)"
|
||||
vcpkg-triplet:
|
||||
description: "vcpkg triplet to use (Windows)"
|
||||
required: false
|
||||
|
||||
outputs:
|
||||
@ -57,7 +57,7 @@ runs:
|
||||
elif [ ${{ inputs.like }} == "arch" ]; then
|
||||
pacman -Syu --noconfirm base-devel cmake ninja \
|
||||
gcc openssl glib2 libxtst libxkbfile gtest libei libportal \
|
||||
qt6-base qt6-tools qt6-svg gtk3 tomlplusplus cli11 help2man
|
||||
qt6-base qt6-tools qt6-svg gtk3 tomlplusplus cli11 help2man doxygen graphviz rsync
|
||||
else
|
||||
echo "Unknown like"
|
||||
fi
|
||||
@ -72,7 +72,6 @@ runs:
|
||||
env:
|
||||
AQT_CONFIG: ${{ github.workspace }}/.github/actions/install-dependencies/aqt.ini
|
||||
with:
|
||||
dir: ${{inputs.qt-install-dir}}
|
||||
version: ${{inputs.qt-version}}
|
||||
cache: true
|
||||
cache-key-prefix: ${{matrix.target.os}}-${{inputs.qt-version}}
|
||||
@ -80,11 +79,11 @@ runs:
|
||||
- name: Build and cache vcpkg
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
id: vcpkg
|
||||
uses: sithlord48/vcpkg-action@v7
|
||||
uses: johnwason/vcpkg-action@v7
|
||||
with:
|
||||
pkgs: gtest openssl
|
||||
extra-args: --classic
|
||||
triplet: x64-windows-release
|
||||
extra-args: --classic --host-triplet=${{inputs.vcpkg-triplet}}
|
||||
triplet: ${{inputs.vcpkg-triplet}}
|
||||
token: ${{ github.token }}
|
||||
|
||||
- name: Install Wix
|
||||
|
||||
4
.github/actions/run-tests/action.yml
vendored
4
.github/actions/run-tests/action.yml
vendored
@ -77,8 +77,8 @@ runs:
|
||||
path: ${{ steps.row.outputs.file }}
|
||||
|
||||
- name: Check test outcome
|
||||
if: steps.unittests.outcome == 'failure'
|
||||
if: (steps.unittests.outcome != 'success' || steps.legacytests.outcome != 'success')
|
||||
run: |
|
||||
echo "Unit tests failed"
|
||||
echo "Tests failed"
|
||||
exit 1
|
||||
shell: bash
|
||||
|
||||
5
.github/actions/winget-publish/action.yaml
vendored
5
.github/actions/winget-publish/action.yaml
vendored
@ -21,12 +21,13 @@ runs:
|
||||
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
|
||||
|
||||
$packageId = "Deskflow.Deskflow"
|
||||
$installerUrl = "https://github.com/deskflow/deskflow/releases/download/v${{ inputs.release-version }}/deskflow-${{ inputs.release-version }}-win-x64.msi"
|
||||
$x64Url = "https://github.com/deskflow/deskflow/releases/download/v${{ inputs.release-version }}/deskflow-${{ inputs.release-version }}-win-x64.msi"
|
||||
$arm64Url = "https://github.com/deskflow/deskflow/releases/download/v${{ inputs.release-version }}/deskflow-${{ inputs.release-version }}-win-arm64.msi"
|
||||
|
||||
# Submit package update
|
||||
.\wingetcreate.exe update "$packageId" `
|
||||
--version "${{ inputs.release-version }}" `
|
||||
--urls "$installerUrl" `
|
||||
--urls "$x64Url|x64" "$arm64Url|arm64"`
|
||||
--submit `
|
||||
--token "${{ inputs.token }}"
|
||||
shell: pwsh
|
||||
|
||||
46
.github/workflows/continuous-integration.yml
vendored
46
.github/workflows/continuous-integration.yml
vendored
@ -133,19 +133,29 @@ jobs:
|
||||
runs-on: "windows-2022"
|
||||
timeout: 30
|
||||
config-args: "-G Ninja"
|
||||
qt-install-dir: "C:"
|
||||
qt-version: 6.9.0
|
||||
vcpkg-triplet: x64-windows-release
|
||||
arch: "amd64"
|
||||
|
||||
- name: "windows-2022-arm64"
|
||||
runs-on: "windows-11-arm"
|
||||
timeout: 30
|
||||
config-args: "-G Ninja"
|
||||
qt-version: 6.9.1
|
||||
vcpkg-triplet: arm64-windows
|
||||
arch: "arm64"
|
||||
|
||||
- name: "macos-14-arm64"
|
||||
runs-on: "macos-14"
|
||||
timeout: 10
|
||||
config-args: "-DCMAKE_OSX_ARCHITECTURES=\"arm64\" -DCMAKE_OSX_SYSROOT=/Applications/Xcode_15.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
|
||||
qt-install-dir: "/Users/runner"
|
||||
qt-version: 6.9.1
|
||||
|
||||
- name: "macos-13-x64"
|
||||
runs-on: macos-13
|
||||
timeout: 20
|
||||
config-args: "-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" -DCMAKE_OSX_SYSROOT=/Applications/Xcode_15.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"
|
||||
qt-install-dir: "/Users/runner"
|
||||
qt-version: 6.9.1
|
||||
|
||||
- name: "debian-13-x86_64"
|
||||
runs-on: ubuntu-latest
|
||||
@ -189,20 +199,6 @@ jobs:
|
||||
timeout: 20
|
||||
config-args: "-G Ninja -DCMAKE_INSTALL_PREFIX=/usr"
|
||||
|
||||
- name: "fedora-40-x86_84"
|
||||
runs-on: ubuntu-latest
|
||||
container: fedora:40
|
||||
like: "fedora"
|
||||
timeout: 20
|
||||
config-args: "-G Ninja -DCMAKE_INSTALL_PREFIX=/usr"
|
||||
|
||||
- name: "fedora-40-arm64"
|
||||
runs-on: ubuntu-24.04-arm
|
||||
container: fedora:40
|
||||
like: "fedora"
|
||||
timeout: 20
|
||||
config-args: "-G Ninja -DCMAKE_INSTALL_PREFIX=/usr"
|
||||
|
||||
- name: "opensuse-x86_84"
|
||||
runs-on: ubuntu-latest
|
||||
container: opensuse/tumbleweed:latest
|
||||
@ -222,7 +218,7 @@ jobs:
|
||||
container: archlinux:latest
|
||||
like: "arch"
|
||||
timeout: 20
|
||||
config-args: "-G Ninja -DCMAKE_INSTALL_PREFIX=/usr"
|
||||
config-args: "-G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_DEV_DOCS=ON"
|
||||
|
||||
- name: "ubuntu-25.04-x86_64"
|
||||
runs-on: ubuntu-latest
|
||||
@ -266,13 +262,16 @@ jobs:
|
||||
- name: Setup VC++ environment
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
with:
|
||||
arch: ${{matrix.target.arch}}
|
||||
|
||||
|
||||
- name: Install dependencies
|
||||
id: get-deps
|
||||
uses: ./.github/actions/install-dependencies
|
||||
with:
|
||||
qt-version: 6.9.0
|
||||
qt-install-dir: ${{matrix.target.qt-install-dir}}
|
||||
qt-version: ${{ matrix.target.qt-version }}
|
||||
vcpkg-triplet: ${{matrix.target.vcpkg-triplet}}
|
||||
like: ${{ matrix.target.like }}
|
||||
|
||||
- name: Get version
|
||||
@ -304,6 +303,13 @@ jobs:
|
||||
with:
|
||||
job: ${{ matrix.target.name }}
|
||||
|
||||
- name: Update Development Documentation
|
||||
if: matrix.target.like == 'arch' && github.ref == 'refs/heads/master'
|
||||
uses: JamesIves/github-pages-deploy-action@v4.7.3
|
||||
with:
|
||||
branch: gh-pages
|
||||
folder: build/doc/dev/html
|
||||
|
||||
- name: Upload
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -25,6 +25,9 @@ deskflow-config.toml
|
||||
/*.user
|
||||
*.ui.autosave
|
||||
|
||||
# generated vcpkg file
|
||||
vcpkg.json
|
||||
|
||||
#Generic linux files
|
||||
**/*.directory
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2024 Deskflow Developers
|
||||
# SPDX-FileCopyrightText: 2024 - 2025 Deskflow Developers
|
||||
# SPDX-FileCopyrightText: 2012 - 2024 Symless Ltd
|
||||
# SPDX-FileCopyrightText: 2009 - 2012 Nick Bolton
|
||||
# SPDX-License-Identifier: MIT
|
||||
@ -18,7 +18,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Fallback for when git can not be found
|
||||
set(DESKFLOW_VERSION_MAJOR 1)
|
||||
set(DESKFLOW_VERSION_MINOR 22)
|
||||
set(DESKFLOW_VERSION_MINOR 23)
|
||||
set(DESKFLOW_VERSION_PATCH 0)
|
||||
set(DESKFLOW_VERSION_TWEAK 0)
|
||||
|
||||
@ -68,6 +68,15 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
#generate vcpkg file if needed
|
||||
if(WIN32)
|
||||
option (VCPKG_QT "Use Qt from VCPKG" OFF)
|
||||
if(VCPKG_QT)
|
||||
set(QT_LIBS ", \"qttranslations\", \"qtsvg\"")
|
||||
endif()
|
||||
configure_file(cmake/vcpkg.json.in ${CMAKE_SOURCE_DIR}/vcpkg.json @ONLY)
|
||||
endif()
|
||||
|
||||
#Define our project
|
||||
project(
|
||||
deskflow
|
||||
@ -144,6 +153,10 @@ endif()
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
|
||||
|
||||
# disables the use of signals,slots and emit
|
||||
# Instead use Q_SIGNAL, Q_SLOT and Q_EMIT
|
||||
# prevents issues when used with glib for libportal
|
||||
add_definitions(-DQT_NO_KEYWORDS)
|
||||
include(cmake/Libraries.cmake)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
|
||||
16
README.md
16
README.md
@ -1,4 +1,8 @@
|
||||

|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/deskflow/deskflow-artwork/blob/main/logo/deskflow-logo-dark-200px.png?raw=true">
|
||||
<source media="(prefers-color-scheme: light)" srcset="https://github.com/deskflow/deskflow-artwork/blob/main/logo/deskflow-logo-light-200px.png?raw=true">
|
||||
<img alt="Deskflow" src="https://github.com/user-attachments/assets/f005b958-24df-4f4a-9bfd-4f834dae59d6">
|
||||
</picture>
|
||||
|
||||
**Deskflow** is a free and open source keyboard and mouse sharing app.
|
||||
Use the keyboard, mouse, or trackpad of one computer to control nearby computers,
|
||||
@ -6,6 +10,14 @@ and work seamlessly between them.
|
||||
It's like a software KVM (but without the video).
|
||||
TLS encryption is enabled by default. Wayland is supported. Clipboard sharing is supported.
|
||||
|
||||
> [!TIP]
|
||||
>
|
||||
> **Chat with us**
|
||||
>
|
||||
> - Main discussion on Matrix: [`#deskflow:matrix.org`](https://matrix.to/#/#deskflow:matrix.org) ([Matrix clients](https://matrix.org/ecosystem/clients/))
|
||||
> - Discussion also happens on IRC: `#deskflow` or `#deskflow-dev` on [Libera Chat](https://libera.chat/)
|
||||
> - Start a [new discussion](https://github.com/deskflow/deskflow/discussions) on our GitHub project.
|
||||
|
||||
## Download
|
||||
|
||||
[](https://github.com/deskflow/deskflow/releases/latest) [](https://github.com/deskflow/deskflow/releases/continuous) [](https://flathub.org/apps/org.deskflow.deskflow)
|
||||
@ -50,7 +62,7 @@ We support all major operating systems, including Windows, macOS, Linux, and Uni
|
||||
> [!NOTE]
|
||||
> On Windows, you will need to install the
|
||||
> [Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version).
|
||||
> Download latest: [`vc_redist.x64.exe`](https://aka.ms/vs/17/release/vc_redist.x64.exe)
|
||||
> Download latest: [`vc_redist.x64.exe`](https://aka.ms/vs/17/release/vc_redist.x64.exe) [`vc_redist.arm64.exe`](https://aka.ms/vs/17/release/vc_redist.arm64.exe)
|
||||
|
||||
Windows 10 or higher is required.
|
||||
|
||||
|
||||
208
REUSE.toml
208
REUSE.toml
@ -7,186 +7,53 @@ SPDX-PackageSupplier = "Deskflow Devs"
|
||||
SPDX-PackageDownloadLocation = "https://github.com/deskflow/deskflow"
|
||||
|
||||
[[annotations]]
|
||||
path = ".github/**"
|
||||
path = [
|
||||
".github/**"
|
||||
, ".clang-format"
|
||||
, ".editorconfig"
|
||||
, ".gitattributes"
|
||||
, ".gitignore"
|
||||
, "cspell.json"
|
||||
, "sonar-project.properties"
|
||||
, "cmake/vcpkg.json.in"
|
||||
, "**/*.md"
|
||||
, "doc/**"
|
||||
, "deploy/linux/flatpak/**"
|
||||
, "deploy/linux/org.deskflow.deskflow.metainfo.xml"
|
||||
, "deploy/windows/wix-patch.xml.in"
|
||||
, "src/apps/deskflow-client/deskflow-client.exe.manifest"
|
||||
, "src/apps/deskflow-core/deskflow-core.exe.manifest"
|
||||
, "src/apps/deskflow-server/deskflow-server.exe.manifest"
|
||||
, "src/apps/res/manpage.txt"
|
||||
, "src/apps/res/deskflow.plist.in"
|
||||
]
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = ".clang-format"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = ".editorconfig"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = ".gitattributes"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = ".gitignore"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "cspell.json"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "**/*.md"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "sonar-project.properties"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "vcpkg.json"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "vcpkg-configuration.json"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "doc/**"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/mac/dmg-background.tiff"
|
||||
path = [
|
||||
"deploy/mac/dmg-background.tiff"
|
||||
, "deploy/mac/dmg-volume.icns"
|
||||
, "deploy/linux/deskflow.png"
|
||||
, "deploy/windows/wix-banner.png"
|
||||
, "deploy/windows/wix-dialog.png"
|
||||
, "src/apps/res/icons/deskflow-**/apps/64/deskflow*.svg"
|
||||
, "src/apps/res/image/welcome.png"
|
||||
, "src/apps/res/Deskflow.icns"
|
||||
, "src/apps/res/deskflow.ico"
|
||||
, "src/apps/res/deskflow.qrc"
|
||||
]
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/mac/dmg-volume.icns"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/linux/deskflow.png"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/linux/flatpak/**"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/linux/org.deskflow.deskflow.metainfo.xml"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/windows/wix-banner.png"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/windows/wix-dialog.png"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "deploy/windows/wix-patch.xml.in"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/deskflow-client/deskflow-client.exe.manifest"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/deskflow-core/deskflow-core.exe.manifest"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/deskflow-server/deskflow-server.exe.manifest"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/manpage.txt"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/icons/deskflow-**/**/**/**.svg"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Kde Breeze Icons"
|
||||
SPDX-License-Identifier = "LGPL-2.1-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/icons/deskflow-**/apps/64/deskflow*.svg"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/image/welcome.png"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/Deskflow.icns"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/deskflow.ico"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/deskflow.plist.in"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "MIT"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/deskflow.qrc"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/apps/res/icons/deskflow-**/index.theme"
|
||||
precedence = "override"
|
||||
@ -194,13 +61,10 @@ SPDX-FileCopyrightText = "Chris Rizzitello <sithlord48@gmail.com>"
|
||||
SPDX-License-Identifier = "LGPL-2.1-only"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/lib/gui/MainWindow.ui"
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only WITH LicenseRef-OpenSSL-Exception"
|
||||
|
||||
[[annotations]]
|
||||
path = "src/lib/gui/dialogs/*.ui"
|
||||
path = [
|
||||
"src/lib/gui/MainWindow.ui"
|
||||
, "src/lib/gui/dialogs/*.ui"
|
||||
]
|
||||
precedence = "override"
|
||||
SPDX-FileCopyrightText = "Deskflow Developers"
|
||||
SPDX-License-Identifier = "GPL-2.0-only WITH LicenseRef-OpenSSL-Exception"
|
||||
|
||||
@ -26,13 +26,21 @@ macro(configure_libs)
|
||||
|
||||
# Define the location of Qt deployment tool
|
||||
if(WIN32)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND NOT VCPKG_INSTALL_DIR STREQUAL "")
|
||||
find_program(DEPLOYQT windeployqt.debug.bat)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND VCPKG_QT)
|
||||
set(DEPLOY_TOOL windeployqt.debug.bat)
|
||||
else()
|
||||
find_program(DEPLOYQT windeployqt)
|
||||
set(DEPLOY_TOOL windeployqt)
|
||||
endif()
|
||||
elseif(APPLE)
|
||||
find_program(DEPLOYQT macdeployqt)
|
||||
set(DEPLOY_TOOL macdeployqt)
|
||||
endif()
|
||||
|
||||
if (WIN32 OR APPLE)
|
||||
find_program(DEPLOYQT ${DEPLOY_TOOL})
|
||||
if(DEPLOYQT STREQUAL "DEPLOYQT-NOTFOUND")
|
||||
message(FATAL_ERROR "Unable to locate the Qt Deploy Tool: \"${DEPLOY_TOOL}\"")
|
||||
endif()
|
||||
unset(DEPLOY_TOOL)
|
||||
endif()
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
@ -82,12 +90,17 @@ macro(configure_unix_libs)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
check_include_files(sys/select.h HAVE_SYS_SELECT_H)
|
||||
check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
|
||||
check_include_files(sys/time.h HAVE_SYS_TIME_H)
|
||||
check_include_files(unistd.h HAVE_UNISTD_H)
|
||||
if (NOT HAVE_SYS_SOCKET_H)
|
||||
message(FATAL_ERROR "Missing header: sys/socket.h")
|
||||
endif()
|
||||
|
||||
|
||||
check_include_files(unistd.h HAVE_UNISTD_H)
|
||||
if (NOT HAVE_UNISTD_H)
|
||||
message(FATAL_ERROR "Missing unistd.h")
|
||||
endif()
|
||||
|
||||
check_function_exists(nanosleep HAVE_NANOSLEEP)
|
||||
check_function_exists(sigwait HAVE_POSIX_SIGWAIT)
|
||||
check_function_exists(inet_aton HAVE_INET_ATON)
|
||||
|
||||
@ -154,15 +167,6 @@ macro(configure_unix_libs)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# For config.h, set some static values; it may be a good idea to make these
|
||||
# values dynamic for non-standard UNIX compilers.
|
||||
set(HAVE_PTHREAD_SIGNAL 1)
|
||||
set(SELECT_TYPE_ARG1 int)
|
||||
set(SELECT_TYPE_ARG234 " (fd_set *)")
|
||||
set(SELECT_TYPE_ARG5 " (struct timeval *)")
|
||||
set(TIME_WITH_SYS_TIME 1)
|
||||
set(HAVE_SOCKLEN_T 1)
|
||||
|
||||
# Unix only: For config.h, save the results based on a template (config.h.in).
|
||||
# Note that this won't work on Windows because filenames are not case sensitive,
|
||||
# and we have header files named "Config.h" (upper case 'C').
|
||||
@ -196,11 +200,6 @@ macro(configure_xorg_libs)
|
||||
check_include_files("${XKBlib}" HAVE_X11_XKBLIB_H)
|
||||
check_include_files("X11/extensions/XInput2.h" HAVE_XI2)
|
||||
|
||||
if(HAVE_X11_EXTENSIONS_DPMS_H)
|
||||
# Assume that function prototypes declared, when include exists.
|
||||
set(HAVE_DPMS_PROTOTYPES 1)
|
||||
endif()
|
||||
|
||||
if(NOT HAVE_X11_XKBLIB_H)
|
||||
message(FATAL_ERROR "Missing header: " ${XKBlib})
|
||||
endif()
|
||||
|
||||
12
cmake/vcpkg.json.in
Normal file
12
cmake/vcpkg.json.in
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"$comment": "Generated file do not hand edit",
|
||||
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
|
||||
"name": "deskflow",
|
||||
"version": "@DESKFLOW_VERSION_MAJOR@.@DESKFLOW_VERSION_MINOR@.@DESKFLOW_VERSION_PATCH@.@DESKFLOW_VERSION_TWEAK@",
|
||||
"builtin-baseline": "d5ec528843d29e3a52d745a64b469f810b2cedbf",
|
||||
"dependencies": [
|
||||
"gtest",
|
||||
"openssl"
|
||||
@QT_LIBS@
|
||||
]
|
||||
}
|
||||
@ -2,7 +2,7 @@
|
||||
<component type="desktop-application">
|
||||
<id>org.deskflow.deskflow</id>
|
||||
<metadata_license>CC0-1.0</metadata_license>
|
||||
<project_license>GPL-2.0+</project_license>
|
||||
<project_license>GPL-2.0-only</project_license>
|
||||
<name>Deskflow</name>
|
||||
<developer id="org.deskflow">
|
||||
<name>Deskflow Developers</name>
|
||||
@ -16,6 +16,10 @@
|
||||
<launchable type="desktop-id">org.deskflow.deskflow.desktop</launchable>
|
||||
<url type="homepage">https://deskflow.org</url>
|
||||
<url type="bugtracker">https://github.com/deskflow/deskflow/issues</url>
|
||||
<url type="faq">https://github.com/deskflow/deskflow/wiki/Project-FAQ</url>
|
||||
<url type="help">https://github.com/deskflow/deskflow/wiki#user-guides</url>
|
||||
<url type="vcs-browser">https://github.com/deskflow/deskflow</url>
|
||||
<url type="contribute">https://github.com/deskflow/deskflow/wiki/Contributing</url>
|
||||
<screenshots>
|
||||
<screenshot type="default">
|
||||
<image>https://deskflow.org/screenshots/deskflow.png</image>
|
||||
@ -42,6 +46,26 @@
|
||||
</branding>
|
||||
<content_rating type="oars-1.0" />
|
||||
<releases>
|
||||
<release version="1.23.0" date="2025-07-23" urgency="high">
|
||||
<description>
|
||||
<p>This stable release fixes issues found in the previous version and adds a few new features. This release also uses more C++20 features. For the full changelog, see the release page.</p>
|
||||
<ul>
|
||||
<li>Fix: Core app not running when app starts minimized.</li>
|
||||
<li>Fix: Several items in the server configuration dialog being enabled at the wrong time.</li>
|
||||
<li>Fix: Use the correct license in our appstream data (GPL2.0 only).</li>
|
||||
<li>Fix: Apps saved size could grow over time on desktops using client side decorations.</li>
|
||||
<li>Fix: Use the system monospace font in the log area, instead of forcing one that may not be on the system.</li>
|
||||
<li>Fix: Issue with incorrect borders being set for libEI, causing issues on edges without neighbors.</li>
|
||||
<li>Feat: Add Restart action for the core process.</li>
|
||||
<li>Feat: Remove defunct --no-xinitthreads option.</li>
|
||||
<li>Feat: Make 2048 the minimum encryption key size.</li>
|
||||
<li>Feat: Provide additional connection information in the status area.</li>
|
||||
<li>Chore: Continue to update codebase to use C++20 features.</li>
|
||||
<li>Chore: Clean more sonar smells</li>
|
||||
</ul>
|
||||
</description>
|
||||
<url>https://github.com/deskflow/deskflow/releases/tag/v1.23.0</url>
|
||||
</release>
|
||||
<release version="1.22.0" date="2025-05-28" urgency="high">
|
||||
<description>
|
||||
<p>This stable release fixes a issues found in the previous version. For the full changelog see the release page.</p>
|
||||
@ -65,7 +89,7 @@
|
||||
</ul>
|
||||
</description>
|
||||
<url>https://github.com/deskflow/deskflow/releases/tag/v1.22.0</url>
|
||||
</release>/
|
||||
</release>
|
||||
<release version="1.21.2" date="2025-04-07" urgency="high">
|
||||
<description>
|
||||
<p>This stable release fixes a few critical bugs in 1.21.1. For the full changelog see the release page.</p>
|
||||
|
||||
@ -9,10 +9,6 @@ set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
|
||||
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
|
||||
include(InstallRequiredSystemLibraries)
|
||||
|
||||
install(CODE "execute_process(
|
||||
COMMAND ${DEPLOYQT} --no-compiler-runtime --no-system-d3d-compiler --no-quick-import -network \"\${CMAKE_INSTALL_PREFIX}/deskflow.exe\"
|
||||
)")
|
||||
|
||||
configure_file(${MY_DIR}/pre-cpack.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/pre-cpack.cmake @ONLY)
|
||||
set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/pre-cpack.cmake)
|
||||
|
||||
@ -27,6 +23,7 @@ list(APPEND CPACK_GENERATOR "7Z")
|
||||
find_program(WIX_APP wix)
|
||||
if (NOT "${WIX_APP}" STREQUAL "")
|
||||
set(CPACK_WIX_VERSION 4)
|
||||
set(CPACK_WIX_ARCHITECTURE ${BUILD_ARCHITECTURE})
|
||||
list(APPEND CPACK_GENERATOR "WIX")
|
||||
endif()
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 3.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 94 KiB After Width: | Height: | Size: 47 KiB |
@ -17,6 +17,7 @@
|
||||
/>
|
||||
</ServiceInstall>
|
||||
<ServiceControl Id="ServiceControl" Name="Deskflow" Remove="uninstall" Start="install" Stop="both"/>
|
||||
<RemoveFile Id="RmOldLog" On="install" Name="deskflow-daemon.log"/>
|
||||
</CPackWiXFragment>
|
||||
|
||||
<CPackWiXFragment Id="CM_CP_deskflow_server.exe">
|
||||
@ -44,7 +45,9 @@
|
||||
Control="Finish"
|
||||
Event="DoAction"
|
||||
Value="RunDeskflow"
|
||||
Condition= "NOT Installed" />
|
||||
Condition= "WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed" />
|
||||
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1" />
|
||||
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Run Deskflow when finished" />
|
||||
</UI>
|
||||
<CustomAction
|
||||
Id="CheckVCRedist"
|
||||
|
||||
@ -1,31 +1,24 @@
|
||||
# SPDX-FileCopyrightText: 2019 - 2024 Chris Rizzitello <sithlord48@gmail.com>
|
||||
# SPDX-FileCopyrightText: 2019 - 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
find_package(Doxygen QUIET)
|
||||
option(BUILD_DOCS "Build and install documents" ${DOXYGEN_FOUND})
|
||||
|
||||
if (BUILD_DOCS AND DOXYGEN_FOUND)
|
||||
option(BUILD_USER_DOCS "Build and install user documentation" ${DOXYGEN_FOUND})
|
||||
option(BUILD_DEV_DOCS "Build and install developer documentation" OFF)
|
||||
|
||||
if (DOXYGEN_FOUND)
|
||||
# Generic Doxygen options
|
||||
set(DOXYGEN_EXTRACT_ALL YES)
|
||||
set(DOXYGEN_EXTRACT_STATIC YES)
|
||||
set(DOXYGEN_STRIP_FROM_PATH ${CMAKE_SOURCE_DIR})
|
||||
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE mainpage.md)
|
||||
set(DOXYGEN_QUIET YES)
|
||||
set(DOXYGEN_PROJECT_NAME ${CMAKE_PROJECT_PROPER_NAME})
|
||||
|
||||
# Files used to make our documents
|
||||
# User facing documents will not include doxy comments in source code
|
||||
doxygen_add_docs(user-docs ${CMAKE_SOURCE_DIR}/doc COMMENT "Generating user documentation" ALL)
|
||||
|
||||
# HACK Only these will show in your IDE
|
||||
target_sources(user-docs PRIVATE
|
||||
mainpage.md
|
||||
configuration.md
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html"
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT deskflow_docs)
|
||||
|
||||
if (BUILD_USER_DOCS)
|
||||
add_subdirectory(user)
|
||||
endif()
|
||||
if (BUILD_DEV_DOCS)
|
||||
add_subdirectory(dev)
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Doxygen not found, skipping docs build")
|
||||
endif()
|
||||
|
||||
22
doc/dev/CMakeLists.txt
Normal file
22
doc/dev/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
# SPDX-FileCopyrightText: 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE mainpage.md)
|
||||
set(DOXYGEN_EXCLUDE_PATTERNS "*unittests/*")
|
||||
set(DOXYGEN_DOT_GRAPH_MAX_NODES 100)
|
||||
|
||||
# Files used to make our documents
|
||||
doxygen_add_docs(dev-docs
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/src
|
||||
COMMENT "Generating developer documentation" ALL)
|
||||
|
||||
# HACK Only these will show in your IDE
|
||||
target_sources(dev-docs PRIVATE
|
||||
mainpage.md
|
||||
contributing.md
|
||||
build.md
|
||||
protocol_reference.md
|
||||
)
|
||||
|
||||
# missing install target is intended generate a local copy
|
||||
84
doc/dev/build.md
Normal file
84
doc/dev/build.md
Normal file
@ -0,0 +1,84 @@
|
||||
# Building Deskflow
|
||||
|
||||
To build Deskflow you will a minimum of:
|
||||
- [cmake] 3.24+
|
||||
- [Qt] 6.7.0+
|
||||
- [openssl] 3.0+
|
||||
- [libportal] 0.8+ (linux, bsd)
|
||||
- [libei] 1.3+ (linux, bsd)
|
||||
- [google_test] ^
|
||||
- [tomlplusplus] ^
|
||||
- [cli11] ^
|
||||
|
||||
> ^ Will be fetched if not found on the host system.
|
||||
|
||||
By default a build of Deskflow will:
|
||||
- The GUI application deskflow
|
||||
- The Client application deskflow-client
|
||||
- The Server application deskflow-server
|
||||
- Documentation if [doxygen] was found on your system
|
||||
- Tests that will be run as part of the build process.
|
||||
|
||||
## Configuration
|
||||
Deskflow supports the following build options
|
||||
|
||||
CMake options:
|
||||
| Option | Description | Default Value | Additional requirements |
|
||||
:-------------------------:|:---------------------------------------:|:------------------:|:-----------------------:|
|
||||
| BUILD_GUI | Build GUI | ON | |
|
||||
| BUILD_USER_DOCS | Build user documentation | DOXYGEN_FOUND | `Doxygen` |
|
||||
| BUILD_DEV_DOCS | Build development documentation | OFF | `Doxygen` |
|
||||
| BUILD_INSTALLER | Build installers/packages | ON | |
|
||||
| BUILD_TESTS | Build unit tests and legacy tests | ON | `gtest`|
|
||||
| BUILD_UNIFIED | Build unified binary (client+server) | OFF | |
|
||||
| ENABLE_COVERAGE | Enable test coverage | OFF | `gcov` |
|
||||
| SKIP_BUILD_TESTS | Skip running of tests at build time | OFF | |
|
||||
| VCPKG_QT | Build Qt w/ vcpkg (windows only) | OFF | |
|
||||
|
||||
Example cmake configuration.
|
||||
`cmake -S. -Bbuild -DCMAKE_INSTALL_PREFIX=<INSTALLPREFIX>`
|
||||
|
||||
### Windows Configuration
|
||||
It is recommended to use vcpkg to install the dependencies. The first time you configure Deskflow, all dependencies other than Qt will be built. If you don't want to use vcpkg, you must manually setup the dependencies. However, that will not be covered by this document.
|
||||
|
||||
#### Windows and Qt
|
||||
There are two ways you can install [Qt] on Windows (vcpkg or Qt online installer). The default configuration expects you to use the Qt online installer. You should not install Qt in both ways, as having both can cause some weird things to happen, like Qt getting libs from one install and plugins from the other. When switching between them, remove the previous install first.
|
||||
|
||||
##### System Qt
|
||||
|
||||
1. Download and install the [Qt] online installer from their website.
|
||||
2. Add the path of Qt's cmake files to your system path. (Skipping this may require you provide this path to cmake via `Qt6_DIR` at configure time)
|
||||
- Often `C:\Qt\<version>\<msvcinfo>\lib\cmake`
|
||||
3. Add the path of Qt's binary tools to your system path.
|
||||
- Often `C:\Qt\<version>\<msvcinfo>\bin`
|
||||
|
||||
##### Vcpkg managed Qt
|
||||
1. Add the option `-DVCPKG_QT=ON` to your cmake configuration command (i.e `cmake -S. -Bbuild -DVCPKG_QT=ON ...`) or if using an IDE, look for the option where you configure the project, have the IDE run cmake again.
|
||||
2. Once the configuration starts, you should see a lot more packages vcpkg will build. Building Qt takes a long time (potentially hours), so go find something else to do for a while.
|
||||
3. If you want to use the system Qt again, you must delete the `vcpkg.json` generated in the project root and the `build` folder and reconfigure the project from scratch.
|
||||
|
||||
## Build
|
||||
After configuring you should be able to run make to build all targets.
|
||||
|
||||
`cmake --build build`
|
||||
|
||||
## Install
|
||||
To test installation run `DESTDIR=<installDIR> cmake --install build` to install into `<installDir>/<CMAKE_INSTALL_PREFIX>` <br>
|
||||
Running `cmake --install build` will install to the `CMAKE_INSTALL_PREFIX`
|
||||
|
||||
## Making Deskflow packages
|
||||
Deskflow can generate several packages using cpack.
|
||||
To generate packages build the `package` or `package_source` target.
|
||||
Example: ` cmake --build build --target package package_source` would generate both package and package source packages.
|
||||
Deskflow can generate several package types depending on the system. Archive-based packages should work on all platforms. On Linux deb and rpm info is set up, flatpaks can be generated from the included file in deploy/linux and a PKGBUILD for Arch linux is generated in the build folder. On macos a dmg file will be created and signed. For windows wix can be used to create an installer.
|
||||
|
||||
|
||||
[Qt]:https://www.qt.io
|
||||
[doxygen]:http://www.stack.nl/~dimitri/doxygen/
|
||||
[cmake]:https://cmake.org/
|
||||
[openssl]:https://www.openssl.org/
|
||||
[google_test]:https://github.com/google/googletest
|
||||
[tomlplusplus]:https://github.com/marzer/tomlplusplus
|
||||
[cli11]:https://github.com/CLIUtils/CLI11
|
||||
[libei]:https://gitlab.freedesktop.org/libinput/libei
|
||||
[libportal]:https://github.com/flatpak/libportal
|
||||
13
doc/dev/contributing.md
Normal file
13
doc/dev/contributing.md
Normal file
@ -0,0 +1,13 @@
|
||||
# Contributing to Deskflow {#contributing_guide}
|
||||
|
||||
Thanks for your interest in contributing to Deskflow! We welcome all kinds of contributions — bug reports, feature suggestions, documentation improvements, and code.
|
||||
|
||||
## Read the Full Guidelines
|
||||
|
||||
To keep this repository clean and contribution-friendly, we've outlined our full contributing guidelines on the Deskflow Wiki:
|
||||
|
||||
👉 [How to Contribute to Deskflow](https://github.com/deskflow/deskflow/wiki/Contributing)
|
||||
|
||||
Please take a moment to read through the page before opening an issue or submitting a pull request.
|
||||
|
||||
Thanks again for helping make Deskflow better!
|
||||
55
doc/dev/mainpage.md
Normal file
55
doc/dev/mainpage.md
Normal file
@ -0,0 +1,55 @@
|
||||
**Deskflow** is a free and open source keyboard and mouse sharing app.
|
||||
Use the keyboard, mouse, or trackpad of one computer to control nearby computers,
|
||||
and work seamlessly between them.
|
||||
|
||||
Deskflow acts as a software KVM (without video) that allows you to:
|
||||
- Share keyboard and mouse input across multiple computers
|
||||
- Synchronize clipboard content between machines
|
||||
- Work seamlessly across different operating systems (Windows, macOS, Linux, BSD)
|
||||
|
||||
Deskflow software consists of a **server** (primary computer) that shares its input devices and **clients** (secondary computers) that receive and execute the input commands over a TCP network connection.
|
||||
|
||||
### Architecture Overview
|
||||
|
||||
Deskflow is built with a modular, cross-platform architecture:
|
||||
|
||||
```
|
||||
┌─────────────────┐ Network Protocol ┌─────────────────┐
|
||||
│ Server App │◄──────────────────────►│ Client App │
|
||||
│ │ (Port 24800) │ (Windows) │
|
||||
│ ┌─────────────┐ │ │ ┌─────────────┐ │
|
||||
│ │ Screen │ │ │ │ Screen │ │
|
||||
│ │ Platform │ │ │ │ Platform │ │
|
||||
│ │ Layer │ │ │ │ Layer │ │
|
||||
│ └─────────────┘ │ │ └─────────────┘ │
|
||||
└─────────────────┘ └─────────────────┘
|
||||
┌───────┐ ┌───────┐
|
||||
│ Keyb. │ │ Mouse │
|
||||
└───────┘ └───────┘
|
||||
|
||||
┌─────────────────┐
|
||||
│ Client App │
|
||||
│ (macOS) │
|
||||
│ ┌─────────────┐ │
|
||||
│ │ Screen │ │
|
||||
│ │ Platform │ │
|
||||
│ │ Layer │ │
|
||||
│ └─────────────┘ │
|
||||
└─────────────────┘
|
||||
|
||||
┌─────────────────┐
|
||||
│ Client App │
|
||||
│ (Custom) │
|
||||
│ ┌─────────────┐ │
|
||||
│ │ Screen │ │
|
||||
│ │ Platform │ │
|
||||
│ │ Layer │ │
|
||||
│ └─────────────┘ │
|
||||
└─────────────────┘
|
||||
```
|
||||
|
||||
### More info
|
||||
|
||||
For more info, see our [Wiki](https://github.com/deskflow/deskflow/wiki).
|
||||
|
||||
Check out our [Building guide](build.md) or our general @ref contributing_guide "Contributing section". We also have a detailed [Protocol Reference](protocol_reference.md).
|
||||
532
doc/dev/protocol_reference.md
Normal file
532
doc/dev/protocol_reference.md
Normal file
@ -0,0 +1,532 @@
|
||||
# Protocol Reference {#protocol_reference}
|
||||
|
||||
This document provides a comprehensive reference for the Deskflow network protocol. It is the primary source of information for developers implementing Deskflow clients or extending the protocol.
|
||||
|
||||
## Protocol Overview
|
||||
|
||||
The Deskflow protocol enables keyboard and mouse sharing between multiple computers over a TCP network connection. The protocol uses two distinct sets of terminology to describe the roles of the computers involved:
|
||||
|
||||
- **Network Role (Client/Server)**: This describes the connection architecture.
|
||||
- **Server**: The machine that listens for incoming TCP connections.
|
||||
- **Client**: The machine that initiates the TCP connection to the server.
|
||||
|
||||
- **Input Control Role (Primary/Secondary)**: This describes the flow of keyboard and mouse events.
|
||||
- **Primary**: The computer whose keyboard and mouse are currently being used to control other computers.
|
||||
- **Secondary**: A computer that is being controlled by the Primary's keyboard and mouse.
|
||||
|
||||
In a typical setup, the Primary computer (the one whose keyboard and mouse are shared) also acts as the Server. However, the protocol is flexible and allows these roles to be separate. For example, a Primary machine can act as a Client to connect to a Secondary machine that is configured as a Server. This can be useful for navigating restrictive network environments like firewalls.
|
||||
|
||||
Throughout the documentation, message direction is often described using the Primary/Secondary roles to clarify the input control flow, while Client/Server roles are used when discussing the underlying network connection.
|
||||
|
||||
### Key Implementation Files
|
||||
|
||||
- **[ProtocolTypes.h](@ref ProtocolTypes.h)** – Complete protocol specification
|
||||
- **[ProtocolUtil.h](@ref ProtocolUtil.h)** – Message formatting utilities
|
||||
- **[ClientInfo](@ref ClientInfo)** – Screen information structure
|
||||
|
||||
The protocol is designed to be:
|
||||
- Lightweight and efficient
|
||||
- Cross-platform compatible
|
||||
- Extensible for new features
|
||||
- Backward compatible with older versions
|
||||
|
||||
## Protocol Architecture
|
||||
|
||||
|
||||
```
|
||||
┌─────────────────┐ TCP/IP Network ┌─────────────────┐
|
||||
│ Primary │◄────────────────────►│ Secondary │
|
||||
│ (Server) │ Port 24800 │ (Client) │
|
||||
│ │ │ │
|
||||
│ • Shares input │ │ • Receives input│
|
||||
│ • Manages layout│ │ • Reports info │
|
||||
│ • Coordinates │ │ • Executes cmds │
|
||||
└─────────────────┘ └─────────────────┘
|
||||
```
|
||||
|
||||
The protocol operates over a standard TCP connection on port 24800. In protocol versions 1.4 and later, TLS encryption is supported for secure communications.
|
||||
|
||||
## Protocol State Machine
|
||||
|
||||
The client's connection lifecycle is defined by five primary states:
|
||||
|
||||
|
||||
```
|
||||
┌──────────────────┐
|
||||
│ START │
|
||||
└────────┬─────────┘
|
||||
│
|
||||
▼
|
||||
┌────────┴─────────┐
|
||||
│ DISCONNECTED │
|
||||
│ (Initial & │◄───────────────────┐
|
||||
│ Final State) │ │
|
||||
└────────┬─────────┘ │
|
||||
│ │
|
||||
▼ │
|
||||
┌──────────────────┐ │
|
||||
│ CONNECTING │ TCP Failure │
|
||||
│ (TCP handshake) ├───────────────────►┤
|
||||
└────────┬─────────┘ │
|
||||
│ │
|
||||
TCP Success │ │
|
||||
│ │
|
||||
▼ │
|
||||
┌──────────────────┐ │
|
||||
│ HANDSHAKE │ Version Mismatch │
|
||||
│ (Hello/HelloBk) ├───────────────────►┤
|
||||
└────────┬─────────┘ │
|
||||
│ │
|
||||
OK │ │
|
||||
│ │
|
||||
▼ │
|
||||
┌──────────────────┐ │
|
||||
│ CONNECTED │ CCLOSE (close) │
|
||||
┌───►│ (Authenticated ├───────────────────►┤
|
||||
│ │ but inactive) │ │
|
||||
│ └────────┬─────────┘ │
|
||||
│ │ │
|
||||
COUT │ CINN │ │
|
||||
(Leave) │ (Enter)│ │
|
||||
│ ▼ │
|
||||
│ ┌──────────────────┐ │
|
||||
└────┤ ACTIVE │ CCLOSE (close) │
|
||||
│ (Receiving all ├───────────────────►┘
|
||||
┌───►│ input events) │
|
||||
│ └────────┬─────────┘
|
||||
│ │
|
||||
│ ▼
|
||||
│ ┌──────────────────┐
|
||||
└────┤ PROCESS EVENT │
|
||||
└──────────────────┘
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
### State Descriptions
|
||||
|
||||
1. **Disconnected**: Initial and final state. No connection to @ref Server.
|
||||
2. **Connecting**: @ref TCPSocket connection attempt in progress.
|
||||
- Initiating @ref TCPSocket connection.
|
||||
- On successful TCP connection, moves to the `Handshake` state.
|
||||
- If TCP connection fails (timeout, RST packet), returns to `Disconnected`.
|
||||
3. **Handshake**: Protocol version negotiation and authentication.
|
||||
- @ref Server sends @ref kMsgHello with protocol version information.
|
||||
- @ref Client responds with @ref kMsgHelloBack including version and screen name.
|
||||
- @ref Server validates the client's message.
|
||||
- Success transitions to `Connected`, failure sends @ref kMsgEIncompatible error.
|
||||
4. **Connected**: Authenticated but not receiving input events.
|
||||
- @ref Client must respond to @ref kMsgCKeepAlive messages from the @ref Server.
|
||||
- Receiving @ref kMsgCEnter message transitions to `Active`.
|
||||
5. **Active**: Receiving and processing input events from @ref Server.
|
||||
- Receiving @ref kMsgCLeave message transitions back to `Connected`.
|
||||
- Receiving @ref kMsgCClose message transitions to `Disconnected`.
|
||||
|
||||
|
||||
## Message Categories
|
||||
|
||||
The protocol organizes messages into logical categories:
|
||||
|
||||
| Category | Prefix | Purpose | Examples |
|
||||
|----------|---------|----------|-----------|
|
||||
| **[Handshake](@ref protocol_handshake)** | None | Connection setup | @ref kMsgHello, @ref kMsgHelloBack |
|
||||
| **[Commands](@ref protocol_commands)** | `C` | Screen control | @ref kMsgCEnter, @ref kMsgCLeave, @ref kMsgCKeepAlive |
|
||||
| **[Data](@ref protocol_data)** | `D` | Input events | @ref kMsgDKeyDown, @ref kMsgDMouseMove, @ref kMsgCClipboard, @ref kMsgDClipboard |
|
||||
| **[Queries](@ref protocol_queries)** | `Q` | Information requests | @ref kMsgQInfo |
|
||||
| **[Errors](@ref protocol_errors)** | `E` | Error notifications | @ref kMsgEIncompatible, @ref kMsgEBusy |
|
||||
|
||||
## Message Reference Table
|
||||
|
||||
This table lists all protocol messages in alphabetical order. For a typical sequence of messages, see the [Typical Control Flow](#typical-control-flow) section.
|
||||
|
||||
| Message | Constant | Category | Direction | Purpose | Constraints | Protocol Version |
|
||||
|---|---|---|---|---|---|---|
|
||||
| [**CALV**](@ref kMsgCKeepAlive) | @ref kMsgCKeepAlive | Command | Both | Keep-alive | [MsgSize](#constraint-protocol-max-message-length), [KeepAlive](#constraint-keep-alive) | 1.3+ |
|
||||
| [**CBYE**](@ref kMsgCClose) | @ref kMsgCClose | Command | Server→Client | Close connection | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**CCLP**](@ref kMsgCClipboard) | @ref kMsgCClipboard | Command | Both | Clipboard ownership notification | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**CIAK**](@ref kMsgCInfoAck) | @ref kMsgCInfoAck | Command | Server→Client | Acknowledge info message | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**CINN**](@ref kMsgCEnter) | @ref kMsgCEnter | Command | Server→Client | Enter screen | [MsgSize](#constraint-protocol-max-message-length), [ScreenEntrySync](#constraint-screen-entry-sync) | 1.0+ |
|
||||
| [**CNOP**](@ref kMsgCNoop) | @ref kMsgCNoop | Command | Both | No operation | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**COUT**](@ref kMsgCLeave) | @ref kMsgCLeave | Command | Server→Client | Leave screen | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**CROP**](@ref kMsgCResetOptions) | @ref kMsgCResetOptions | Command | Server→Client | Reset options to defaults | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**CSEC**](@ref kMsgCScreenSaver) | @ref kMsgCScreenSaver | Command | Server→Client | Screen saver control | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DCLP**](@ref kMsgDClipboard) | @ref kMsgDClipboard | Data | Both | Clipboard data | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DDRG**](@ref kMsgDDragInfo) | @ref kMsgDDragInfo | Data | Server→Client | Drag file info | [MsgSize](#constraint-protocol-max-message-length), [ListSize](#constraint-max-list) | 1.5+ |
|
||||
| [**DFTR**](@ref kMsgDFileTransfer) | @ref kMsgDFileTransfer | Data | Both | File transfer data | [MsgSize](#constraint-protocol-max-message-length) | 1.5+ |
|
||||
| [**DINF**](@ref kMsgDInfo) | @ref kMsgDInfo | Data | Client→Server | Screen information | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DKDL**](@ref kMsgDKeyDownLang) | @ref kMsgDKeyDownLang | Data | Server→Client | Key down with language | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.8+ |
|
||||
| [**DKDN**](@ref kMsgDKeyDown) | @ref kMsgDKeyDown | Data | Server→Client | Key down | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.1+ |
|
||||
| [**DKDN**](@ref kMsgDKeyDown1_0) | @ref kMsgDKeyDown1_0 | Data | Server→Client | Key down (legacy) | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.0 |
|
||||
| [**DKRP**](@ref kMsgDKeyRepeat) | @ref kMsgDKeyRepeat | Data | Server→Client | Key repeat | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.1+ |
|
||||
| [**DKRP**](@ref kMsgDKeyRepeat1_0) | @ref kMsgDKeyRepeat1_0 | Data | Server→Client | Key repeat (legacy) | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.0 |
|
||||
| [**DKUP**](@ref kMsgDKeyUp) | @ref kMsgDKeyUp | Data | Server→Client | Key up | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.1+ |
|
||||
| [**DKUP**](@ref kMsgDKeyUp1_0) | @ref kMsgDKeyUp1_0 | Data | Server→Client | Key up (legacy) | [MsgSize](#constraint-protocol-max-message-length), [KeyMap](#constraint-keymap) | 1.0 |
|
||||
| [**DMDN**](@ref kMsgDMouseDown) | @ref kMsgDMouseDown | Data | Server→Client | Mouse down | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DMMV**](@ref kMsgDMouseMove) | @ref kMsgDMouseMove | Data | Server→Client | Mouse move (absolute) | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DMRM**](@ref kMsgDMouseRelMove) | @ref kMsgDMouseRelMove | Data | Server→Client | Mouse move (relative) | [MsgSize](#constraint-protocol-max-message-length) | 1.2+ |
|
||||
| [**DMUP**](@ref kMsgDMouseUp) | @ref kMsgDMouseUp | Data | Server→Client | Mouse up | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**DMWM**](@ref kMsgDMouseWheel) | @ref kMsgDMouseWheel | Data | Server→Client | Mouse wheel | [MsgSize](#constraint-protocol-max-message-length) | 1.3+ |
|
||||
| [**DMWM**](@ref kMsgDMouseWheel1_0) | @ref kMsgDMouseWheel1_0 | Data | Server→Client | Mouse wheel (legacy) | [MsgSize](#constraint-protocol-max-message-length) | 1.0-1.2 |
|
||||
| [**DSOP**](@ref kMsgDSetOptions) | @ref kMsgDSetOptions | Data | Server→Client | Set options | [MsgSize](#constraint-protocol-max-message-length), [ListSize](#constraint-max-list) | 1.0+ |
|
||||
| [**EBAD**](@ref kMsgEBad) | @ref kMsgEBad | Error | Server→Client | Protocol violation | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**EBSY**](@ref kMsgEBusy) | @ref kMsgEBusy | Error | Server→Client | Server busy | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**EICV**](@ref kMsgEIncompatible) | @ref kMsgEIncompatible | Error | Server→Client | Incompatible version | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**EUNK**](@ref kMsgEUnknown) | @ref kMsgEUnknown | Error | Server→Client | Unknown client | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**Hello**](@ref kMsgHello) | @ref kMsgHello | Handshake | Server→Client | Protocol identification | [HelloSize](#constraint-max-hello), [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**HelloArgs**](@ref kMsgHelloArgs) | @ref kMsgHelloArgs | Handshake | Internal | Hello message construction | [HelloSize](#constraint-max-hello), [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**HelloBack**](@ref kMsgHelloBack) | @ref kMsgHelloBack | Handshake | Client→Server | Client identification | [HelloSize](#constraint-max-hello), [MsgSize](#constraint-protocol-max-message-length), [HandshakeTimeout](#constraint-handshake-timeout) | 1.0+ |
|
||||
| [**HelloBackArgs**](@ref kMsgHelloBackArgs) | @ref kMsgHelloBackArgs | Handshake | Internal | HelloBack message construction | [HelloSize](#constraint-max-hello), [MsgSize](#constraint-protocol-max-message-length), [HandshakeTimeout](#constraint-handshake-timeout) | 1.0+ |
|
||||
| [**LSYN**](@ref kMsgDLanguageSynchronisation) | @ref kMsgDLanguageSynchronisation | Data | Server→Client | Language synchronization | [MsgSize](#constraint-protocol-max-message-length) | 1.8+ |
|
||||
| [**QINF**](@ref kMsgQInfo) | @ref kMsgQInfo | Query | Server→Client | Request screen info | [MsgSize](#constraint-protocol-max-message-length) | 1.0+ |
|
||||
| [**SECN**](@ref kMsgDSecureInputNotification) | @ref kMsgDSecureInputNotification | Data | Server→Client | Secure input notification | [MsgSize](#constraint-protocol-max-message-length) | 1.7+ |
|
||||
|
||||
## Typical Control Flow
|
||||
<a id="typical-control-flow"></a>
|
||||
|
||||
A typical control flow is as follows:
|
||||
1. **Handshake**: The server and client exchange `Hello` and `HelloBack` messages to agree on a protocol version.
|
||||
2. **Information Exchange**: The server requests client information with `QINF`, and the client responds with `DINF`.
|
||||
3. **Options**: The server sends `DSOP` to configure client options.
|
||||
4. **Keep-Alive**: The server and client periodically exchange `CALV` messages to maintain the connection.
|
||||
5. **Screen Entry**: The server sends `CINN` to grant control to the client.
|
||||
6. **Input Events**: The server sends a stream of input event messages (e.g., `DMMV`, `DMDN`, `DKDN`).
|
||||
7. **Screen Leave**: The server sends `COUT` to revoke control from the client.
|
||||
8. **Connection Close**: The server sends `CCLOSE` to terminate the connection.
|
||||
|
||||
## Protocol Constraints
|
||||
|
||||
To ensure security, stability, and compatibility, the protocol enforces strict constraints:
|
||||
|
||||
<a id="constraint-max-msg"></a>
|
||||
|
||||
### Message and Data Size Limits
|
||||
|
||||
**Maximum Message Size:**
|
||||
<a id="constraint-protocol-max-message-length"></a>**4,194,304 bytes (4 MB)** — @ref PROTOCOL_MAX_MESSAGE_LENGTH
|
||||
Maximum total size of any single, length-prefixed data packet
|
||||
Defined in Protocol Limits
|
||||
|
||||
**Maximum List Size:**
|
||||
<a id="constraint-max-list"></a>**1,048,576 elements** — @ref PROTOCOL_MAX_LIST_LENGTH
|
||||
Maximum number of items in a list/vector within a message
|
||||
Defined in Protocol Limits
|
||||
|
||||
**Maximum Hello Size:**
|
||||
<a id="constraint-max-hello"></a>**1,024 bytes** — @ref kMaxHelloLength
|
||||
Maximum size of the initial Connection Handshake message
|
||||
Defined in Protocol Limits
|
||||
|
||||
<a id="constraint-tls"></a>
|
||||
|
||||
### TLS Handshake and Security (Protocol v1.4+)
|
||||
|
||||
When encryption is enabled, the protocol follows this sequence:
|
||||
|
||||
1. Standard TCP connection established
|
||||
2. TLS handshake performed over TCP socket
|
||||
3. Protocol handshake begins only after TLS session is established
|
||||
|
||||
- **Implementation Details**:
|
||||
- The client initiates a standard TCP connection, then the (private) SecureSocket::handleTCPConnected method is called, which begins the TLS handshake
|
||||
|
||||
- **Certificate Validation**:
|
||||
- Client implementations **must** validate the server's certificate
|
||||
- The reference implementation checks that the public key is RSA or DSA and that the key length is at least 2048 bits
|
||||
|
||||
### Key Code and Modifier Mapping
|
||||
|
||||
A modifier (modifier mask) represents the state of modifier keys (like Shift, Control, Alt, and Command) on a keyboard. It is a binary code (like 0000 0110) where each bit corresponds to a specific modifier key.
|
||||
|
||||
**Key-Up/Key-Down Strategy:**
|
||||
- <a id="constraint-keymap"></a>Client must use the @ref KeyButton (physical key) to track pressed keys, as the @ref KeyID (virtual key) can change based on modifier state
|
||||
- This strategy is described in the documentation for @ref kMsgDKeyDown
|
||||
|
||||
**Modifier Remapping:**
|
||||
- The server can command clients to remap modifier keys via the @ref kMsgDSetOptions message
|
||||
- The client processes the @ref kMsgDSetOptions message and updates the modifier translation table accordingly
|
||||
|
||||
## Timing and Synchronization
|
||||
|
||||
<a id="constraint-keep-alive"></a>
|
||||
|
||||
### Keep-Alive Mechanism (Protocol v1.3+)
|
||||
|
||||
**Server-Side Behavior:**
|
||||
- The server sends kMsgCKeepAlive messages every 3.0 seconds (defined by @ref kKeepAliveRate)
|
||||
- This timer is implemented in @ref ClientProxy1_3::addHeartbeatTimer in the @ref ClientProxy1_3 class
|
||||
|
||||
**Client-Side Behavior:**
|
||||
- Upon receiving a kMsgCKeepAlive message, the client must immediately send a kMsgCKeepAlive message back
|
||||
- The client maintains a timeout that is reset each time any message is received
|
||||
- If no message is received for 9.0 seconds (3 × @ref kKeepAliveRate), client must disconnect
|
||||
- This is handled by the (private) ServerProxy::handleKeepAliveAlarm method
|
||||
|
||||
<a id="constraint-screen-entry-sync"></a>
|
||||
### Synchronization on Screen Entry
|
||||
|
||||
- The @ref kMsgCEnter (Enter Screen) message includes the current modifier state
|
||||
- Client must synchronize their local modifier state with this mask
|
||||
|
||||
<a id="constraint-handshake-timeout"></a>
|
||||
### Handshake Timeout
|
||||
|
||||
- Server allows **30 seconds** for handshake completion
|
||||
- If client fails to send valid @ref kMsgHelloBack within this time, connection is closed
|
||||
- When a new client connects, the server creates a temporary @ref ClientProxyUnknown to handle the version handshake
|
||||
- A one-shot timer is started for 30 seconds
|
||||
- If the client fails to respond in time, the @ref protocol_errors function is triggered, the connection is logged as unresponsive, and the socket is closed
|
||||
|
||||
## Version Compatibility
|
||||
|
||||
| Version | Release Date | Project | Features | Compatibility |
|
||||
|---------|----------|---------------|----------|---------------|
|
||||
| **1.0** | May 2001 | Synergy | Basic keyboard/mouse sharing (@ref kMsgDKeyDown, @ref kMsgDMouseMove) | All versions |
|
||||
| **1.1** | Apr 2002 | Synergy | Physical key codes (@ref KeyButton) | 1.1+ |
|
||||
| **1.2** | Jan 2006 | Synergy | Relative mouse movement | 1.2+ |
|
||||
| **1.3** | May 2006 | Synergy | Keep-alive (@ref kMsgCKeepAlive), horizontal scroll (@ref kMsgDMouseWheel) | 1.3+ |
|
||||
| **1.4** | Nov 2012 | Synergy | Encryption support (@ref SecureSocket) | 1.4+ |
|
||||
| **1.5** | Sep 2013 | Synergy | File transfer | 1.5+ |
|
||||
| **1.6** | Jan 2014 | Synergy | Clipboard streaming | 1.6+ |
|
||||
| **1.7** | Nov 2021 | Synergy | Secure input notifications | 1.7+ |
|
||||
| **1.8** | Jun 2025 | Synergy | Language synchronization | 1.8+ |
|
||||
|
||||
### Version Migration Guide
|
||||
|
||||
When implementing a client that supports multiple protocol versions:
|
||||
|
||||
1. **Version Negotiation**: During handshake, client should advertise highest supported version
|
||||
2. **Feature Detection**: Check server's version in `Hello` message before using version-specific features
|
||||
3. **Fallback Mechanism**: Be prepared to operate with only features available in the negotiated version
|
||||
4. **Graceful Degradation**: If server supports a lower version than client's minimum, handle `EIncompatible` error gracefully
|
||||
|
||||
## Implementation Examples
|
||||
|
||||
### Connection Lifecycle
|
||||
|
||||
```cpp
|
||||
// 1. Connect to server
|
||||
std::string server_ip = "192.168.1.100";
|
||||
connect(server_ip, 24800);
|
||||
|
||||
// 2. Receive Hello from server
|
||||
auto hello = receive_message();
|
||||
std::string server_version, server_name;
|
||||
parse_hello(hello, &server_version, &server_name);
|
||||
|
||||
// 3. Send HelloBack to server
|
||||
std::string client_version = "1.8";
|
||||
std::string client_name = "MyClient";
|
||||
send_hello_back(client_version, client_name);
|
||||
|
||||
// 4. Enter main message loop
|
||||
bool connected = true;
|
||||
while (connected) {
|
||||
auto message = receive_message();
|
||||
handle_message(message);
|
||||
}
|
||||
```
|
||||
|
||||
### Message Handling
|
||||
|
||||
```cpp
|
||||
void handle_message(const Message& msg) {
|
||||
switch (msg.type) {
|
||||
case "CINN": // Enter screen
|
||||
handle_enter(msg.x, msg.y, msg.sequence, msg.modifiers);
|
||||
break;
|
||||
case "DKDN": // Key down
|
||||
handle_key_down(msg.key_id, msg.modifiers, msg.key_button);
|
||||
break;
|
||||
case "DMMV": // Mouse move
|
||||
handle_mouse_move(msg.x, msg.y);
|
||||
break;
|
||||
// ... handle other message types
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Complete Message Exchange Sequence
|
||||
|
||||
Below is a typical message exchange sequence for a client connecting to a server:
|
||||
|
||||
|
||||
|
||||
```
|
||||
Client Server
|
||||
| |
|
||||
| | Server starts listening on port 24800
|
||||
| |
|
||||
| TCP SYN |
|
||||
| ───────────────────────────────────► |
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| TCP SYN+ACK |
|
||||
| |
|
||||
| TCP ACK |
|
||||
| ───────────────────────────────────► |
|
||||
| | TCP connection established
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "Deskflow" + version (1.8) | Hello message
|
||||
| |
|
||||
| "Deskflow" + version + name |
|
||||
| ───────────────────────────────────► | HelloBack message
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "QINF" | Query screen info
|
||||
| |
|
||||
| "DINF" + screen dimensions |
|
||||
| ───────────────────────────────────► | Report screen info
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DSOP" + options | Set options
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "CALV" | Keep-alive
|
||||
| |
|
||||
| "CALV" |
|
||||
| ───────────────────────────────────► | Keep-alive response
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "CINN" + x + y + seq + mask | Enter screen
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DMMV" + x + y | Mouse move
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DMDN" + button | Mouse down
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DMUP" + button | Mouse up
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DKDN" + key + mask + button | Key down
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "DKUP" + key + mask + button | Key up
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "COUT" | Leave screen
|
||||
| |
|
||||
| ◄─────────────────────────────────── |
|
||||
| "CCLOSE" | Close connection
|
||||
| |
|
||||
| TCP FIN |
|
||||
| ◄─────────────────────────────────── |
|
||||
| |
|
||||
| TCP FIN+ACK |
|
||||
| ───────────────────────────────────► |
|
||||
| | Connection closed
|
||||
```
|
||||
|
||||
**Legend:**
|
||||
|
||||
- Hello message: @ref kMsgHello
|
||||
- HelloBack message: @ref kMsgHelloBack
|
||||
- Query screen info: @ref kMsgQInfo
|
||||
- Report screen info: @ref kMsgDInfo
|
||||
- Set options: @ref kMsgDSetOptions
|
||||
- Keep-alive: @ref kMsgCKeepAlive
|
||||
- Enter screen: @ref kMsgCEnter
|
||||
- Mouse move: @ref kMsgDMouseMove
|
||||
- Mouse down: @ref kMsgDMouseDown
|
||||
- Mouse up: @ref kMsgDMouseUp
|
||||
- Key down: @ref kMsgDKeyDown
|
||||
- Key up: @ref kMsgDKeyUp
|
||||
- Leave screen: @ref kMsgCLeave
|
||||
- Close connection: @ref kMsgCClose
|
||||
|
||||
## Debugging and Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Version Mismatch**: Check protocol version negotiation
|
||||
2. **Message Format**: Validate message structure and parameters
|
||||
3. **Byte Order**: Ensure network byte order for multi-byte integers
|
||||
4. **Keep-Alive**: Implement proper keep-alive response
|
||||
5. **Screen Info**: Send accurate screen dimensions and mouse position
|
||||
|
||||
### Debug Tools
|
||||
|
||||
- **Wireshark**: Capture and analyze network traffic
|
||||
- **Protocol Logs**: Enable verbose logging in Deskflow
|
||||
- **Message Validation**: Check message format against specification
|
||||
|
||||
## Platform-Specific Implementations
|
||||
|
||||
For platform-specific implementation details, refer to:
|
||||
- @ref ProtocolTypes.h – Complete protocol specification
|
||||
- @ref ProtocolUtil.h – Message formatting utilities
|
||||
|
||||
## Implementation Checklist
|
||||
|
||||
### Basic Client Implementation
|
||||
|
||||
- **Connection Management**
|
||||
- TCP connection to server port 24800
|
||||
- Protocol handshake (Hello/HelloBack)
|
||||
- Version negotiation
|
||||
- Keep-alive handling
|
||||
|
||||
- **Message Processing**
|
||||
- Message parsing and validation
|
||||
- Command message handling (Enter/Leave)
|
||||
- Input event processing (keyboard/mouse)
|
||||
- Error handling and recovery
|
||||
|
||||
- **Screen Management**
|
||||
- Screen information reporting (DINF)
|
||||
- Resolution change detection
|
||||
- Mouse cursor positioning
|
||||
|
||||
- **Input Synthesis**
|
||||
- Keyboard event injection
|
||||
- Mouse event injection
|
||||
- Modifier key synchronization
|
||||
|
||||
### Advanced Features
|
||||
|
||||
- **Clipboard Synchronization**
|
||||
- Clipboard grab notifications
|
||||
- Data transfer (@ref kMsgDClipboard - text, images, HTML)
|
||||
- Streaming for large data (v1.6+)
|
||||
|
||||
- **File Transfer** (v1.5+)
|
||||
- Drag-and-drop initiation
|
||||
- Chunked file transfer
|
||||
- Progress tracking
|
||||
|
||||
- **Security Features**
|
||||
- TLS/SSL encryption (v1.4+)
|
||||
- Secure input notifications (v1.7+)
|
||||
- Input validation and limits
|
||||
|
||||
## Reference Implementation
|
||||
|
||||
The @ref ServerProxy class provides a reference implementation demonstrating:
|
||||
|
||||
- Basic protocol handling
|
||||
- Message parsing and generation
|
||||
- Connection management
|
||||
- Input event processing
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
When extending the protocol:
|
||||
|
||||
1. **Maintain Compatibility**: New features should be backward compatible
|
||||
2. **Update Documentation**: Document new messages and parameters
|
||||
3. **Version Increment**: Bump minor version for new features
|
||||
4. **Test Thoroughly**: Verify with existing clients and servers
|
||||
|
||||
## Support and Resources
|
||||
|
||||
|
||||
- @ref ProtocolTypes.h – Complete protocol specification
|
||||
- @ref ProtocolUtil.h – Message formatting utilities
|
||||
|
||||
---
|
||||
|
||||
*This documentation is generated from the source code and is always up-to-date with the latest protocol implementation.*
|
||||
20
doc/user/CMakeLists.txt
Normal file
20
doc/user/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
# SPDX-FileCopyrightText: 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE mainpage.md)
|
||||
|
||||
# Files used to make our documents
|
||||
# User facing documents will not include doxy comments in source code
|
||||
doxygen_add_docs(user-docs ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Generating user documentation" ALL)
|
||||
|
||||
# HACK Only these will show in your IDE
|
||||
target_sources(user-docs PRIVATE
|
||||
mainpage.md
|
||||
configuration.md
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html"
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT deskflow_user_docs
|
||||
)
|
||||
@ -1,6 +1,6 @@
|
||||
# GUI Config
|
||||
|
||||
Deskflow will automaticlly figure out where to save settings and other files.
|
||||
Deskflow will automatically figure out where to save settings and other files.
|
||||
|
||||
|
||||
## Unix Systems
|
||||
@ -195,7 +195,4 @@ _last = "moe:24800"
|
||||
|
||||
# Enable verbose logging in the GUI (always off by default)
|
||||
# DESKFLOW_GUI_VERBOSE=true
|
||||
|
||||
# Reset all settings and delete all data on startup
|
||||
# DESKFLOW_RESET_ALL=true
|
||||
```
|
||||
@ -10,11 +10,12 @@ if(UNIX AND NOT APPLE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(generate_app_man TARGET)
|
||||
function(generate_app_man TARGET NAME)
|
||||
if(HELP2MAN)
|
||||
add_custom_command(
|
||||
TARGET ${target} POST_BUILD
|
||||
COMMAND QT_QPA_PLATFORM=minimal PATH=$<TARGET_FILE_DIR:${target}>:${PATH} ${HELP2MAN}
|
||||
--name ${NAME}
|
||||
--include ${CMAKE_SOURCE_DIR}/src/apps/res/manpage.txt
|
||||
--no-info
|
||||
${target}
|
||||
|
||||
@ -45,7 +45,7 @@ if(APPLE)
|
||||
)
|
||||
elseif(UNIX)
|
||||
install(TARGETS ${target} DESTINATION bin)
|
||||
generate_app_man(${target})
|
||||
generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION} \\(Client\\)")
|
||||
elseif(WIN32)
|
||||
install(
|
||||
TARGETS ${target}
|
||||
|
||||
@ -40,7 +40,7 @@ if(APPLE)
|
||||
)
|
||||
elseif(UNIX)
|
||||
install(TARGETS ${target} DESTINATION bin)
|
||||
generate_app_man(${target})
|
||||
generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION}")
|
||||
elseif(WIN32)
|
||||
install(
|
||||
TARGETS ${target}
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "VersionInfo.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "base/EventQueue.h"
|
||||
#include "base/Log.h"
|
||||
@ -97,10 +98,10 @@ int main(int argc, char **argv)
|
||||
|
||||
if (parser.isSet(installOption)) {
|
||||
daemon.install();
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
} else if (parser.isSet(uninstallOption)) {
|
||||
daemon.uninstall();
|
||||
return kExitSuccess;
|
||||
return s_exitSuccess;
|
||||
}
|
||||
|
||||
const auto ipcServer =
|
||||
@ -120,10 +121,10 @@ int main(int argc, char **argv)
|
||||
|
||||
} catch (std::exception &e) {
|
||||
handleError(e.what());
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
} catch (...) {
|
||||
handleError();
|
||||
return kExitFailed;
|
||||
return s_exitFailed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -72,10 +72,29 @@ if(WIN32)
|
||||
RUNTIME DESTINATION .
|
||||
)
|
||||
|
||||
set(QT_DEPENDS_DIR ${CMAKE_BINARY_DIR}/qt-depends)
|
||||
|
||||
add_custom_command(
|
||||
TARGET ${target} POST_BUILD
|
||||
COMMAND ${DEPLOYQT} --no-compiler-runtime --no-system-d3d-compiler --no-quick-import -network $<TARGET_FILE:${target}>
|
||||
COMMAND ${DEPLOYQT}
|
||||
--no-compiler-runtime
|
||||
--no-system-d3d-compiler
|
||||
--no-opengl-sw
|
||||
--no-quick-import
|
||||
--dir "${QT_DEPENDS_DIR}"
|
||||
--plugindir "${QT_DEPENDS_DIR}/plugins"
|
||||
$<TARGET_FILE:${target}>
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different
|
||||
${QT_DEPENDS_DIR}
|
||||
$<TARGET_FILE_DIR:${target}>
|
||||
)
|
||||
|
||||
install(
|
||||
DIRECTORY ${QT_DEPENDS_DIR}/
|
||||
DESTINATION .
|
||||
PATTERN "dx*.dll" EXCLUDE
|
||||
)
|
||||
|
||||
elseif(APPLE)
|
||||
set_target_properties(${target} PROPERTIES
|
||||
INSTALL_RPATH "@loader_path/../Libraries;@loader_path/../Frameworks"
|
||||
@ -84,5 +103,5 @@ elseif(APPLE)
|
||||
install(TARGETS ${target} BUNDLE DESTINATION .)
|
||||
else()
|
||||
install(TARGETS ${target} DESTINATION bin)
|
||||
generate_app_man(${target})
|
||||
generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION} \\(GUI\\)")
|
||||
endif()
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "VersionInfo.h"
|
||||
#include "common/Constants.h"
|
||||
#include "common/UrlConstants.h"
|
||||
#include "gui/Diagnostic.h"
|
||||
@ -17,7 +18,6 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QGuiApplication>
|
||||
#include <QLocalSocket>
|
||||
#include <QMessageBox>
|
||||
#include <QSharedMemory>
|
||||
@ -37,6 +37,8 @@ using namespace deskflow::gui;
|
||||
bool checkMacAssistiveDevices();
|
||||
#endif
|
||||
|
||||
const static auto kHeader = QStringLiteral("%1: %2\n").arg(kAppName, kDisplayVersion);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if defined(Q_OS_UNIX) && defined(QT_DEBUG)
|
||||
@ -53,8 +55,8 @@ int main(int argc, char *argv[])
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// Add Command Line Options
|
||||
auto helpOption = QCommandLineOption("help", "Display Help on the command line");
|
||||
auto versionOption = QCommandLineOption("version", "Display version information");
|
||||
auto helpOption = QCommandLineOption({"h", "help"}, "Display Help on the command line");
|
||||
auto versionOption = QCommandLineOption({"v", "version"}, "Display version information");
|
||||
auto resetOption = QCommandLineOption("reset", "Reset all settings");
|
||||
|
||||
QCommandLineParser parser;
|
||||
@ -64,15 +66,19 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(resetOption);
|
||||
parser.parse(QCoreApplication::arguments());
|
||||
|
||||
const auto header = QStringLiteral("%1: %2\n").arg(kAppName, kDisplayVersion);
|
||||
if (parser.isSet(helpOption) || !parser.unknownOptionNames().isEmpty() || !parser.errorText().isEmpty()) {
|
||||
QTextStream(stdout) << header << QStringLiteral(" %1\n\n").arg(kAppDescription)
|
||||
if (!parser.errorText().isEmpty()) {
|
||||
qCritical().noquote() << parser.errorText() << "\nUse --help for more information.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (parser.isSet(helpOption)) {
|
||||
QTextStream(stdout) << kHeader << QStringLiteral(" %1\n\n").arg(kAppDescription)
|
||||
<< parser.helpText().replace(QApplication::applicationFilePath(), kAppId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (parser.isSet(versionOption)) {
|
||||
QTextStream(stdout) << header << kCopyright << Qt::endl;
|
||||
QTextStream(stdout) << kHeader << kCopyright << Qt::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -106,8 +112,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
// Sets the fallback icon path
|
||||
setIconFallbackPaths();
|
||||
// Sets the fallback icon path and fallback theme
|
||||
const auto themeName = QStringLiteral("deskflow-%1").arg(iconMode());
|
||||
if (QIcon::themeName().isEmpty())
|
||||
QIcon::setThemeName(themeName);
|
||||
else
|
||||
QIcon::setFallbackThemeName(themeName);
|
||||
QIcon::setFallbackSearchPaths({QStringLiteral(":/icons/%1").arg(themeName)});
|
||||
|
||||
qInstallMessageHandler(deskflow::gui::messages::messageHandler);
|
||||
qInfo("%s v%s", kAppName, qPrintable(kVersion));
|
||||
|
||||
@ -45,7 +45,7 @@ if(APPLE)
|
||||
)
|
||||
elseif(UNIX)
|
||||
install(TARGETS ${target} DESTINATION bin)
|
||||
generate_app_man(${target})
|
||||
generate_app_man(${target} "${CMAKE_PROJECT_DESCRIPTION} \\(Server\\)")
|
||||
elseif(WIN32)
|
||||
install(
|
||||
TARGETS ${target}
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
# SPDX-FileCopyrightText: 2009 - 2012 Nick Bolton
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
configure_file(VersionInfo.h.in VersionInfo.h @ONLY)
|
||||
|
||||
add_subdirectory(arch)
|
||||
add_subdirectory(base)
|
||||
add_subdirectory(client)
|
||||
|
||||
@ -7,42 +7,12 @@
|
||||
|
||||
// clang-format off
|
||||
|
||||
/* Define if the <X11/extensions/dpms.h> header file declares function prototypes. */
|
||||
#cmakedefine HAVE_DPMS_PROTOTYPES @HAVE_DPMS_PROTOTYPES@
|
||||
|
||||
/* Define if you have the `inet_aton` function. */
|
||||
#cmakedefine HAVE_INET_ATON @HAVE_INET_ATON@
|
||||
|
||||
/* Define if you have the `nanosleep` function. */
|
||||
#cmakedefine HAVE_NANOSLEEP @HAVE_NANOSLEEP@
|
||||
|
||||
/* Define if you have a POSIX `sigwait` function. */
|
||||
#cmakedefine HAVE_POSIX_SIGWAIT @HAVE_POSIX_SIGWAIT@
|
||||
|
||||
/* Define if you have POSIX threads libraries and header files. */
|
||||
#cmakedefine HAVE_PTHREAD @HAVE_PTHREAD@
|
||||
|
||||
/* Define if you have `pthread_sigmask` and `pthread_kill` functions. */
|
||||
#cmakedefine HAVE_PTHREAD_SIGNAL @HAVE_PTHREAD_SIGNAL@
|
||||
|
||||
/* Define if your compiler defines socklen_t. */
|
||||
#cmakedefine HAVE_SOCKLEN_T @HAVE_SOCKLEN_T@
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SELECT_H @HAVE_SYS_SELECT_H@
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
#cmakedefine HAVE_SYS_SOCKET_H @HAVE_SYS_SOCKET_H@
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TIME_H @HAVE_SYS_TIME_H@
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
|
||||
|
||||
/* Define to 1 if you have the <X11/extensions/Xrandr.h> header file. */
|
||||
#cmakedefine HAVE_X11_EXTENSIONS_XRANDR_H @HAVE_X11_EXTENSIONS_XRANDR_H@
|
||||
|
||||
@ -61,19 +31,4 @@
|
||||
/* Define this if the XKB extension is available. */
|
||||
#cmakedefine HAVE_XKB_EXTENSION @HAVE_XKB_EXTENSION@
|
||||
|
||||
/* Define to the type of arg 1 for `select`. */
|
||||
#cmakedefine SELECT_TYPE_ARG1 @SELECT_TYPE_ARG1@
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select`. */
|
||||
#cmakedefine SELECT_TYPE_ARG234 @SELECT_TYPE_ARG234@
|
||||
|
||||
/* Define to the type of arg 5 for `select`. */
|
||||
#cmakedefine SELECT_TYPE_ARG5 @SELECT_TYPE_ARG5@
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#cmakedefine TIME_WITH_SYS_TIME @TIME_WITH_SYS_TIME@
|
||||
|
||||
/* Define to 1 if the X Window System is missing or not being used. */
|
||||
#cmakedefine X_DISPLAY_MISSING @X_DISPLAY_MISSING@
|
||||
|
||||
// clang-format on
|
||||
|
||||
14
src/lib/VersionInfo.h.in
Normal file
14
src/lib/VersionInfo.h.in
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2024 - 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-FileCopyrightText: (C) 2025 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
const auto kVersion = "@CMAKE_PROJECT_VERSION@";
|
||||
const auto kVersionGitSha = "@GIT_SHA_SHORT@";
|
||||
// clang-format off
|
||||
const auto kDisplayVersion = @CMAKE_PROJECT_VERSION_TWEAK@ ? "@CMAKE_PROJECT_VERSION@ (@GIT_SHA_SHORT@)" : "@CMAKE_PROJECT_VERSION_MAJOR@.@CMAKE_PROJECT_VERSION_MINOR@.@CMAKE_PROJECT_VERSION_PATCH@";
|
||||
// clang-format on
|
||||
@ -7,6 +7,8 @@
|
||||
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
#if SYSAPI_WIN32
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
#endif
|
||||
@ -41,3 +43,19 @@ Arch *Arch::getInstance()
|
||||
assert(s_instance != nullptr);
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void Arch::sleep(double timeout)
|
||||
{
|
||||
ARCH->testCancelThread();
|
||||
if (timeout < 0.0)
|
||||
return;
|
||||
const auto msec = static_cast<uint64_t>(timeout * 1000);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(msec));
|
||||
}
|
||||
|
||||
double Arch::time()
|
||||
{
|
||||
auto sinceEpoch = std::chrono::steady_clock::now().time_since_epoch();
|
||||
auto uSecSinceEpoch = std::chrono::duration_cast<std::chrono::microseconds>(sinceEpoch).count();
|
||||
return double(uSecSinceEpoch / 1000000);
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
// TODO: consider whether or not to use either encapsulation (as below)
|
||||
// Consider whether or not to use either encapsulation (as below)
|
||||
// or inheritance (as it is now) for the ARCH stuff.
|
||||
//
|
||||
// case for encapsulation:
|
||||
@ -33,20 +33,13 @@
|
||||
#include "arch/win32/ArchLogWindows.h"
|
||||
#include "arch/win32/ArchMultithreadWindows.h"
|
||||
#include "arch/win32/ArchNetworkWinsock.h"
|
||||
#include "arch/win32/ArchSleepWindows.h"
|
||||
#include "arch/win32/ArchTimeWindows.h"
|
||||
|
||||
#elif SYSAPI_UNIX
|
||||
|
||||
#include "arch/unix/ArchDaemonUnix.h"
|
||||
#include "arch/unix/ArchLogUnix.h"
|
||||
#include "arch/unix/ArchNetworkBSD.h"
|
||||
#include "arch/unix/ArchSleepUnix.h"
|
||||
#include "arch/unix/ArchTimeUnix.h"
|
||||
|
||||
#if HAVE_PTHREAD
|
||||
#include "arch/unix/ArchMultithreadPosix.h"
|
||||
#endif
|
||||
#include "arch/unix/ArchNetworkBSD.h"
|
||||
|
||||
#endif
|
||||
|
||||
@ -66,13 +59,7 @@ to each method to those implementations. Clients should use the
|
||||
exactly one of these objects before attempting to call any method,
|
||||
typically at the beginning of \c main().
|
||||
*/
|
||||
class Arch : public ARCH_DAEMON,
|
||||
public ARCH_LOG,
|
||||
public ARCH_MULTITHREAD,
|
||||
public ARCH_NETWORK,
|
||||
public ARCH_SLEEP,
|
||||
public ArchString,
|
||||
public ARCH_TIME
|
||||
class Arch : public ARCH_DAEMON, public ARCH_LOG, public ARCH_MULTITHREAD, public ARCH_NETWORK, public ArchString
|
||||
{
|
||||
public:
|
||||
Arch();
|
||||
@ -102,6 +89,19 @@ public:
|
||||
s_instance = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
private:
|
||||
static Arch *s_instance;
|
||||
};
|
||||
|
||||
@ -6,28 +6,21 @@
|
||||
*/
|
||||
|
||||
#include "arch/ArchString.h"
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
|
||||
static ArchMutex s_mutex = nullptr;
|
||||
std::mutex s_mutex;
|
||||
|
||||
//
|
||||
// use C library non-reentrant multibyte conversion with mutex
|
||||
//
|
||||
|
||||
ArchString::~ArchString()
|
||||
{
|
||||
if (s_mutex != nullptr) {
|
||||
ARCH->closeMutex(s_mutex);
|
||||
s_mutex = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::scoped_lock lock{s_mutex};
|
||||
ptrdiff_t len = 0;
|
||||
|
||||
bool dummyErrors;
|
||||
@ -36,12 +29,6 @@ int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool
|
||||
}
|
||||
*errors = false;
|
||||
|
||||
if (s_mutex == nullptr) {
|
||||
s_mutex = ARCH->newMutex();
|
||||
}
|
||||
|
||||
ARCH->lockMutex(s_mutex);
|
||||
|
||||
if (dst == nullptr) {
|
||||
char dummy[MB_LEN_MAX];
|
||||
const wchar_t *scan = src;
|
||||
@ -75,7 +62,6 @@ int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool
|
||||
}
|
||||
len = dst - dst0;
|
||||
}
|
||||
ARCH->unlockMutex(s_mutex);
|
||||
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
@ -91,6 +77,7 @@ ArchString::EWideCharEncoding ArchString::getWideCharEncoding() const
|
||||
|
||||
int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
std::scoped_lock lock{s_mutex};
|
||||
ptrdiff_t len = 0;
|
||||
wchar_t dummy;
|
||||
|
||||
@ -100,12 +87,6 @@ int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool
|
||||
}
|
||||
*errors = false;
|
||||
|
||||
if (s_mutex == nullptr) {
|
||||
s_mutex = ARCH->newMutex();
|
||||
}
|
||||
|
||||
ARCH->lockMutex(s_mutex);
|
||||
|
||||
if (dst == nullptr) {
|
||||
const char *scan = src;
|
||||
while (n > 0) {
|
||||
@ -177,7 +158,6 @@ int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool
|
||||
}
|
||||
len = dst - dst0;
|
||||
}
|
||||
ARCH->unlockMutex(s_mutex);
|
||||
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public:
|
||||
ArchString() = default;
|
||||
ArchString(const ArchString &) = delete;
|
||||
ArchString(ArchString &&) = delete;
|
||||
~ArchString() override;
|
||||
~ArchString() override = default;
|
||||
|
||||
ArchString &operator=(const ArchString &) = delete;
|
||||
ArchString &operator=(ArchString &&) = delete;
|
||||
|
||||
@ -16,10 +16,6 @@ if(WIN32)
|
||||
win32/ArchMultithreadWindows.h
|
||||
win32/ArchNetworkWinsock.cpp
|
||||
win32/ArchNetworkWinsock.h
|
||||
win32/ArchSleepWindows.cpp
|
||||
win32/ArchSleepWindows.h
|
||||
win32/ArchTimeWindows.cpp
|
||||
win32/ArchTimeWindows.h
|
||||
win32/XArchWindows.cpp
|
||||
win32/XArchWindows.h
|
||||
)
|
||||
@ -34,10 +30,6 @@ elseif(UNIX)
|
||||
unix/ArchMultithreadPosix.h
|
||||
unix/ArchNetworkBSD.cpp
|
||||
unix/ArchNetworkBSD.h
|
||||
unix/ArchSleepUnix.cpp
|
||||
unix/ArchSleepUnix.h
|
||||
unix/ArchTimeUnix.cpp
|
||||
unix/ArchTimeUnix.h
|
||||
unix/XArchUnix.cpp
|
||||
unix/XArchUnix.h
|
||||
)
|
||||
@ -52,10 +44,8 @@ add_library(arch STATIC ${PLATFORM_CODE}
|
||||
IArchLog.h
|
||||
IArchMultithread.h
|
||||
IArchNetwork.h
|
||||
IArchSleep.h
|
||||
ArchString.cpp
|
||||
ArchString.h
|
||||
IArchTime.h
|
||||
XArch.h
|
||||
)
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/ELevel.h"
|
||||
#include "base/LogLevel.h"
|
||||
#include "common/IInterface.h"
|
||||
|
||||
//! Interface for architecture dependent logging
|
||||
@ -47,7 +47,7 @@ public:
|
||||
/*!
|
||||
Writes the given string to the log with the given level.
|
||||
*/
|
||||
virtual void writeLog(ELevel, const char *) = 0;
|
||||
virtual void writeLog(LogLevel, const char *) = 0;
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
@ -69,16 +69,16 @@ public:
|
||||
Not all platforms support all signals. Unsupported signals are
|
||||
ignored.
|
||||
*/
|
||||
enum ESignal
|
||||
enum class ThreadSignal : uint8_t
|
||||
{
|
||||
kINTERRUPT, //!< Interrupt (e.g. Ctrl+C)
|
||||
kTERMINATE, //!< Terminate (e.g. Ctrl+Break)
|
||||
kHANGUP, //!< Hangup (SIGHUP)
|
||||
kUSER, //!< User (SIGUSR2)
|
||||
kNUM_SIGNALS
|
||||
Interrupt, //!< Interrupt (e.g. Ctrl+C)
|
||||
Terminate, //!< Terminate (e.g. Ctrl+Break)
|
||||
Hangup, //!< Hangup (SIGHUP)
|
||||
User, //!< User (SIGUSR2)
|
||||
MaxSignals //!< Number of differnt signals
|
||||
};
|
||||
//! Type of signal handler function
|
||||
using SignalFunc = void (*)(ESignal, void *userData);
|
||||
using SignalFunc = void (*)(ThreadSignal, void *userData);
|
||||
|
||||
//! @name manipulators
|
||||
//@{
|
||||
@ -249,15 +249,15 @@ public:
|
||||
Sets the function to call on receipt of an external interrupt.
|
||||
By default and when \p func is nullptr, the main thread is cancelled.
|
||||
*/
|
||||
virtual void setSignalHandler(ESignal, SignalFunc func, void *userData) = 0;
|
||||
virtual void setSignalHandler(ThreadSignal, SignalFunc func, void *userData) = 0;
|
||||
|
||||
//! Invoke the signal handler
|
||||
/*!
|
||||
Invokes the signal handler for \p signal, if any. If no handler
|
||||
cancels the main thread for \c kINTERRUPT and \c kTERMINATE and
|
||||
cancels the main thread for \c ThreadSignal::Interrupt and \c ThreadSignal::Terminate and
|
||||
ignores the call otherwise.
|
||||
*/
|
||||
virtual void raiseSignal(ESignal signal) = 0;
|
||||
virtual void raiseSignal(ThreadSignal signal) = 0;
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
@ -53,18 +53,18 @@ class IArchNetwork : public IInterface
|
||||
{
|
||||
public:
|
||||
//! Supported address families
|
||||
enum EAddressFamily
|
||||
enum class AddressFamily : uint8_t
|
||||
{
|
||||
kUNKNOWN,
|
||||
kINET,
|
||||
kINET6,
|
||||
Unknown,
|
||||
INet,
|
||||
INet6
|
||||
};
|
||||
|
||||
//! Supported socket types
|
||||
enum ESocketType
|
||||
enum class SocketType : uint8_t
|
||||
{
|
||||
kDGRAM,
|
||||
kSTREAM
|
||||
DataGram,
|
||||
Stream
|
||||
};
|
||||
|
||||
//! Events for \c poll()
|
||||
@ -72,12 +72,12 @@ public:
|
||||
Events for \c poll() are bitmasks and can be combined using the
|
||||
bitwise operators.
|
||||
*/
|
||||
enum
|
||||
struct PollEventMask
|
||||
{
|
||||
kPOLLIN = 1, //!< Socket is readable
|
||||
kPOLLOUT = 2, //!< Socket is writable
|
||||
kPOLLERR = 4, //!< The socket is in an error state
|
||||
kPOLLNVAL = 8 //!< The socket is invalid
|
||||
inline static const int In = 1; //!< Socket is readable
|
||||
inline static const int Out = 2; //!< Socket is writable
|
||||
inline static const int Error = 4; //!< The socket is in an error state
|
||||
inline static const int Invalid = 8; //!< The socket is invalid
|
||||
};
|
||||
|
||||
//! A socket query for \c poll()
|
||||
@ -89,8 +89,7 @@ public:
|
||||
|
||||
//! The events to query for
|
||||
/*!
|
||||
The events to query for can be any combination of kPOLLIN and
|
||||
kPOLLOUT.
|
||||
The events to query for can be any combination of PollEventMask::In and PollEventMask::Out.
|
||||
*/
|
||||
unsigned short m_events;
|
||||
|
||||
@ -105,7 +104,7 @@ public:
|
||||
/*!
|
||||
The socket is an opaque data type.
|
||||
*/
|
||||
virtual ArchSocket newSocket(EAddressFamily, ESocketType) = 0;
|
||||
virtual ArchSocket newSocket(AddressFamily, SocketType) = 0;
|
||||
|
||||
//! Copy a socket object
|
||||
/*!
|
||||
@ -175,9 +174,9 @@ public:
|
||||
and/or writable (or indefinitely if \c timeout < 0). Returns the
|
||||
number of sockets that were readable (if readability was being
|
||||
queried) or writable (if writablility was being queried) and sets
|
||||
the \c m_revents members of the entries. \c kPOLLERR and \c kPOLLNVAL
|
||||
the \c m_revents members of the entries. \c PollEventMask::Error and \c PollEventMask::Invalid
|
||||
are set in \c m_revents as appropriate. If a socket indicates
|
||||
\c kPOLLERR then \c throwErrorOnSocket() can be used to determine
|
||||
\c PollEventMask::Error then \c throwErrorOnSocket() can be used to determine
|
||||
the type of error. Returns 0 immediately regardless of the \c timeout
|
||||
if no valid sockets are selected for testing.
|
||||
|
||||
@ -236,7 +235,7 @@ public:
|
||||
virtual std::string getHostName() = 0;
|
||||
|
||||
//! Create an "any" network address
|
||||
virtual ArchNetAddress newAnyAddr(EAddressFamily) = 0;
|
||||
virtual ArchNetAddress newAnyAddr(AddressFamily) = 0;
|
||||
|
||||
//! Copy a network address
|
||||
virtual ArchNetAddress copyAddr(ArchNetAddress) = 0;
|
||||
@ -254,7 +253,7 @@ public:
|
||||
virtual std::string addrToString(ArchNetAddress) = 0;
|
||||
|
||||
//! Get an address's family
|
||||
virtual EAddressFamily getAddrFamily(ArchNetAddress) = 0;
|
||||
virtual AddressFamily getAddrFamily(ArchNetAddress) = 0;
|
||||
|
||||
//! Set the port of an address
|
||||
virtual void setAddrPort(ArchNetAddress, int port) = 0;
|
||||
@ -275,4 +274,15 @@ public:
|
||||
//@}
|
||||
|
||||
virtual void init() = 0;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief throwError, Used to throw network errors
|
||||
*/
|
||||
[[noreturn]] virtual void throwError(int) const = 0;
|
||||
|
||||
/**
|
||||
* @brief throwNameError, Errors related to client names.
|
||||
*/
|
||||
[[noreturn]] virtual void throwNameError(int) const = 0;
|
||||
};
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/IInterface.h"
|
||||
|
||||
//! Interface for architecture dependent sleeping
|
||||
/*!
|
||||
This interface defines the sleep operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchSleep : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Sleep
|
||||
/*!
|
||||
Blocks the calling thread for \c timeout seconds. If
|
||||
\c timeout < 0.0 then the call returns immediately. If \c timeout
|
||||
== 0.0 then the calling thread yields the CPU.
|
||||
|
||||
(cancellation point)
|
||||
*/
|
||||
virtual void sleep(double timeout) = 0;
|
||||
|
||||
//@}
|
||||
};
|
||||
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/IInterface.h"
|
||||
|
||||
//! Interface for architecture dependent time operations
|
||||
/*!
|
||||
This interface defines the time operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchTime : public IInterface
|
||||
{
|
||||
public:
|
||||
//! @name manipulators
|
||||
//@{
|
||||
|
||||
//! Get the current time
|
||||
/*!
|
||||
Returns the number of seconds since some arbitrary starting time.
|
||||
This should return as high a precision as reasonable.
|
||||
*/
|
||||
virtual double time() = 0;
|
||||
|
||||
//@}
|
||||
};
|
||||
@ -41,7 +41,7 @@ int execSelfNonDaemonized()
|
||||
|
||||
bool alreadyDaemonized()
|
||||
{
|
||||
return getenv("_DESKFLOW_DAEMONIZED") != nullptr;
|
||||
return std::getenv("_DESKFLOW_DAEMONIZED") != nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -28,24 +28,25 @@ void ArchLogUnix::showLog(bool)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchLogUnix::writeLog(ELevel level, const char *msg)
|
||||
void ArchLogUnix::writeLog(LogLevel level, const char *msg)
|
||||
{
|
||||
// convert level
|
||||
int priority;
|
||||
switch (level) {
|
||||
case kERROR:
|
||||
using enum LogLevel;
|
||||
case Error:
|
||||
priority = LOG_ERR;
|
||||
break;
|
||||
|
||||
case kWARNING:
|
||||
case Warning:
|
||||
priority = LOG_WARNING;
|
||||
break;
|
||||
|
||||
case kNOTE:
|
||||
case Note:
|
||||
priority = LOG_NOTICE;
|
||||
break;
|
||||
|
||||
case kINFO:
|
||||
case Info:
|
||||
priority = LOG_INFO;
|
||||
break;
|
||||
|
||||
|
||||
@ -22,5 +22,5 @@ public:
|
||||
void openLog(const char *name) override;
|
||||
void closeLog() override;
|
||||
void showLog(bool) override;
|
||||
void writeLog(ELevel, const char *) override;
|
||||
void writeLog(LogLevel, const char *) override;
|
||||
};
|
||||
|
||||
@ -10,32 +10,13 @@
|
||||
#include "arch/Arch.h"
|
||||
#include "arch/XArch.h"
|
||||
|
||||
#include <signal.h>
|
||||
#if TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <cerrno>
|
||||
#include <signal.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
#define SIGWAKEUP SIGUSR1
|
||||
|
||||
#if !HAVE_PTHREAD_SIGNAL
|
||||
// boy, is this platform broken. forget about pthread signal
|
||||
// handling and let signals through to every process. deskflow
|
||||
// will not terminate cleanly when it gets SIGTERM or SIGINT.
|
||||
#define pthread_sigmask sigprocmask
|
||||
#define pthread_kill(tid_, sig_) kill(0, (sig_))
|
||||
#define sigwait(set_, sig_)
|
||||
#undef HAVE_POSIX_SIGWAIT
|
||||
#define HAVE_POSIX_SIGWAIT 1
|
||||
#endif
|
||||
|
||||
static void setSignalSet(sigset_t *sigset)
|
||||
{
|
||||
sigemptyset(sigset);
|
||||
@ -80,14 +61,11 @@ ArchMultithreadPosix::ArchMultithreadPosix()
|
||||
s_instance = this;
|
||||
|
||||
// no signal handlers
|
||||
for (size_t i = 0; i < kNUM_SIGNALS; ++i) {
|
||||
for (size_t i = 0; i < static_cast<size_t>(ThreadSignal::MaxSignals); ++i) {
|
||||
m_signalFunc[i] = nullptr;
|
||||
m_signalUserData[i] = nullptr;
|
||||
}
|
||||
|
||||
// create mutex for thread list
|
||||
m_threadMutex = newMutex();
|
||||
|
||||
// create thread for calling (main) thread and add it to our
|
||||
// list. no need to lock the mutex since we're the only thread.
|
||||
m_mainThread = new ArchThreadImpl;
|
||||
@ -123,25 +101,20 @@ ArchMultithreadPosix::ArchMultithreadPosix()
|
||||
ArchMultithreadPosix::~ArchMultithreadPosix()
|
||||
{
|
||||
assert(s_instance != nullptr);
|
||||
|
||||
closeMutex(m_threadMutex);
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::setNetworkDataForCurrentThread(void *data)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
thread->m_networkData = data;
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getNetworkDataForThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *data = thread->m_networkData;
|
||||
unlockMutex(m_threadMutex);
|
||||
return data;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_networkData;
|
||||
}
|
||||
|
||||
ArchMultithreadPosix *ArchMultithreadPosix::getInstance()
|
||||
@ -308,12 +281,11 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data)
|
||||
// can't tell the difference.
|
||||
if (!m_newThreadCalled) {
|
||||
m_newThreadCalled = true;
|
||||
#if HAVE_PTHREAD_SIGNAL
|
||||
startSignalHandler();
|
||||
#endif
|
||||
}
|
||||
|
||||
lockMutex(m_threadMutex);
|
||||
// note that the child thread will wait until we release this mutex
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread impl for new thread
|
||||
auto *thread = new ArchThreadImpl;
|
||||
@ -342,17 +314,13 @@ ArchThread ArchMultithreadPosix::newThread(ThreadFunc func, void *data)
|
||||
refThread(thread);
|
||||
}
|
||||
|
||||
// note that the child thread will wait until we release this mutex
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
ArchThread ArchMultithreadPosix::newCurrentThread()
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(pthread_self());
|
||||
unlockMutex(m_threadMutex);
|
||||
assert(thread != nullptr);
|
||||
return thread;
|
||||
}
|
||||
@ -369,10 +337,11 @@ void ArchMultithreadPosix::closeThread(ArchThread thread)
|
||||
}
|
||||
|
||||
// remove thread from list
|
||||
lockMutex(m_threadMutex);
|
||||
assert(findNoRef(thread->m_thread) == thread);
|
||||
erase(thread);
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
assert(findNoRef(thread->m_thread) == thread);
|
||||
erase(thread);
|
||||
}
|
||||
|
||||
// done with thread
|
||||
delete thread;
|
||||
@ -391,12 +360,14 @@ void ArchMultithreadPosix::cancelThread(ArchThread thread)
|
||||
|
||||
// set cancel and wakeup flags if thread can be cancelled
|
||||
bool wakeup = false;
|
||||
lockMutex(m_threadMutex);
|
||||
if (!thread->m_exited && !thread->m_cancelling) {
|
||||
thread->m_cancel = true;
|
||||
wakeup = true;
|
||||
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
if (!thread->m_exited && !thread->m_cancelling) {
|
||||
thread->m_cancel = true;
|
||||
wakeup = true;
|
||||
}
|
||||
}
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
// force thread to exit system calls if wakeup is true
|
||||
if (wakeup) {
|
||||
@ -414,10 +385,11 @@ void ArchMultithreadPosix::setPriorityOfThread(ArchThread thread, int /*n*/)
|
||||
void ArchMultithreadPosix::testCancelThread()
|
||||
{
|
||||
// find current thread
|
||||
lockMutex(m_threadMutex);
|
||||
ArchThreadImpl *thread = findNoRef(pthread_self());
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
ArchThreadImpl *thread = nullptr;
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread = findNoRef(pthread_self());
|
||||
}
|
||||
// test cancel on thread
|
||||
testCancelThreadImpl(thread);
|
||||
}
|
||||
@ -426,22 +398,19 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||
{
|
||||
assert(target != nullptr);
|
||||
|
||||
lockMutex(m_threadMutex);
|
||||
|
||||
// find current thread
|
||||
ArchThreadImpl *self = findNoRef(pthread_self());
|
||||
|
||||
// ignore wait if trying to wait on ourself
|
||||
if (target == self) {
|
||||
unlockMutex(m_threadMutex);
|
||||
return false;
|
||||
ArchThreadImpl *self = nullptr;
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
// find current thread
|
||||
self = findNoRef(pthread_self());
|
||||
// ignore wait if trying to wait on ourself
|
||||
if (target == self) {
|
||||
return false;
|
||||
}
|
||||
// ref the target so it can't go away while we're watching it
|
||||
refThread(target);
|
||||
}
|
||||
|
||||
// ref the target so it can't go away while we're watching it
|
||||
refThread(target);
|
||||
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
try {
|
||||
// do first test regardless of timeout
|
||||
testCancelThreadImpl(self);
|
||||
@ -452,10 +421,10 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||
|
||||
// wait and repeat test if there's a timeout
|
||||
if (timeout != 0.0) {
|
||||
const double start = ARCH->time();
|
||||
const double start = Arch::time();
|
||||
do {
|
||||
// wait a little
|
||||
ARCH->sleep(0.05);
|
||||
Arch::sleep(0.05);
|
||||
|
||||
// repeat test
|
||||
testCancelThreadImpl(self);
|
||||
@ -465,7 +434,7 @@ bool ArchMultithreadPosix::wait(ArchThread target, double timeout)
|
||||
}
|
||||
|
||||
// repeat wait and test until timed out
|
||||
} while (timeout < 0.0 || (ARCH->time() - start) <= timeout);
|
||||
} while (timeout < 0.0 || (Arch::time() - start) <= timeout);
|
||||
}
|
||||
|
||||
closeThread(target);
|
||||
@ -483,18 +452,14 @@ bool ArchMultithreadPosix::isSameThread(ArchThread thread1, ArchThread thread2)
|
||||
|
||||
bool ArchMultithreadPosix::isExitedThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
bool exited = thread->m_exited;
|
||||
unlockMutex(m_threadMutex);
|
||||
return exited;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_exited;
|
||||
}
|
||||
|
||||
void *ArchMultithreadPosix::getResultOfThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *result = thread->m_result;
|
||||
unlockMutex(m_threadMutex);
|
||||
return result;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_result;
|
||||
}
|
||||
|
||||
IArchMultithread::ThreadID ArchMultithreadPosix::getIDOfThread(ArchThread thread)
|
||||
@ -502,24 +467,26 @@ IArchMultithread::ThreadID ArchMultithreadPosix::getIDOfThread(ArchThread thread
|
||||
return thread->m_id;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||
void ArchMultithreadPosix::setSignalHandler(ThreadSignal signal, SignalFunc func, void *userData)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
m_signalFunc[signal] = func;
|
||||
m_signalUserData[signal] = userData;
|
||||
unlockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
const auto index = static_cast<int>(signal);
|
||||
m_signalFunc[index] = func;
|
||||
m_signalUserData[index] = userData;
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::raiseSignal(ESignal signal)
|
||||
void ArchMultithreadPosix::raiseSignal(ThreadSignal signal)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
if (m_signalFunc[signal] != nullptr) {
|
||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||
using enum ThreadSignal;
|
||||
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
const auto index = static_cast<int>(signal);
|
||||
if (m_signalFunc[index] != nullptr) {
|
||||
m_signalFunc[index](signal, m_signalUserData[index]);
|
||||
pthread_kill(m_mainThread->m_thread, SIGWAKEUP);
|
||||
} else if (signal == kINTERRUPT || signal == kTERMINATE) {
|
||||
} else if (signal == Interrupt || signal == Terminate) {
|
||||
ARCH->cancelThread(m_mainThread);
|
||||
}
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void ArchMultithreadPosix::startSignalHandler()
|
||||
@ -607,14 +574,13 @@ void ArchMultithreadPosix::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||
assert(thread != nullptr);
|
||||
|
||||
// update cancel state
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
bool cancel = false;
|
||||
if (thread->m_cancel && !thread->m_cancelling) {
|
||||
thread->m_cancelling = true;
|
||||
thread->m_cancel = false;
|
||||
cancel = true;
|
||||
}
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
// unwind thread's stack if cancelling
|
||||
if (cancel) {
|
||||
@ -644,8 +610,9 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
setPriorityOfThread(thread, 1);
|
||||
|
||||
// wait for parent to initialize this object
|
||||
lockMutex(m_threadMutex);
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
}
|
||||
|
||||
void *result = nullptr;
|
||||
try {
|
||||
@ -659,18 +626,20 @@ void ArchMultithreadPosix::doThreadFunc(ArchThread thread)
|
||||
result = nullptr;
|
||||
} catch (...) {
|
||||
// note -- don't catch (...) to avoid masking bugs
|
||||
lockMutex(m_threadMutex);
|
||||
thread->m_exited = true;
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_exited = true;
|
||||
}
|
||||
closeThread(thread);
|
||||
throw;
|
||||
}
|
||||
|
||||
// thread has exited
|
||||
lockMutex(m_threadMutex);
|
||||
thread->m_result = result;
|
||||
thread->m_exited = true;
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_result = result;
|
||||
thread->m_exited = true;
|
||||
}
|
||||
|
||||
// done with thread
|
||||
closeThread(thread);
|
||||
@ -712,20 +681,21 @@ void *ArchMultithreadPosix::threadSignalHandler(void *)
|
||||
|
||||
// if we get here then the signal was raised
|
||||
switch (signal) {
|
||||
using enum ThreadSignal;
|
||||
case SIGINT:
|
||||
ARCH->raiseSignal(kINTERRUPT);
|
||||
ARCH->raiseSignal(Interrupt);
|
||||
break;
|
||||
|
||||
case SIGTERM:
|
||||
ARCH->raiseSignal(kTERMINATE);
|
||||
ARCH->raiseSignal(Terminate);
|
||||
break;
|
||||
|
||||
case SIGHUP:
|
||||
ARCH->raiseSignal(kHANGUP);
|
||||
ARCH->raiseSignal(Hangup);
|
||||
break;
|
||||
|
||||
case SIGUSR2:
|
||||
ARCH->raiseSignal(kUSER);
|
||||
ARCH->raiseSignal(User);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "arch/IArchMultithread.h"
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <pthread.h>
|
||||
|
||||
#define ARCH_MULTITHREAD ArchMultithreadPosix
|
||||
@ -75,8 +76,8 @@ public:
|
||||
bool isExitedThread(ArchThread) override;
|
||||
void *getResultOfThread(ArchThread) override;
|
||||
ThreadID getIDOfThread(ArchThread) override;
|
||||
void setSignalHandler(ESignal, SignalFunc, void *) override;
|
||||
void raiseSignal(ESignal) override;
|
||||
void setSignalHandler(ThreadSignal, SignalFunc, void *) override;
|
||||
void raiseSignal(ThreadSignal) override;
|
||||
|
||||
private:
|
||||
void startSignalHandler();
|
||||
@ -94,19 +95,18 @@ private:
|
||||
static void threadCancel(int);
|
||||
static void *threadSignalHandler(void *vrep);
|
||||
|
||||
private:
|
||||
using ThreadList = std::list<ArchThread>;
|
||||
|
||||
static ArchMultithreadPosix *s_instance;
|
||||
|
||||
bool m_newThreadCalled = false;
|
||||
|
||||
ArchMutex m_threadMutex;
|
||||
std::mutex m_threadMutex;
|
||||
ArchThread m_mainThread;
|
||||
ThreadList m_threadList;
|
||||
ThreadID m_nextID = 0;
|
||||
|
||||
pthread_t m_signalThread;
|
||||
SignalFunc m_signalFunc[kNUM_SIGNALS];
|
||||
void *m_signalUserData[kNUM_SIGNALS];
|
||||
SignalFunc m_signalFunc[static_cast<int>(ThreadSignal::MaxSignals)];
|
||||
void *m_signalUserData[static_cast<int>(ThreadSignal::MaxSignals)];
|
||||
};
|
||||
|
||||
@ -18,10 +18,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if !defined(TCP_NODELAY)
|
||||
#include <netinet/tcp.h>
|
||||
@ -66,7 +63,7 @@ static in_addr_t inet_aton(const char *cp, struct in_addr *inp)
|
||||
|
||||
void ArchNetworkBSD::Deps::sleep(double seconds)
|
||||
{
|
||||
ARCH->sleep(seconds);
|
||||
Arch::sleep(seconds);
|
||||
}
|
||||
|
||||
int ArchNetworkBSD::Deps::poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
@ -76,10 +73,7 @@ int ArchNetworkBSD::Deps::poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
|
||||
std::shared_ptr<struct pollfd[]> ArchNetworkBSD::Deps::makePollFD(nfds_t n)
|
||||
{
|
||||
// C++20 supports std::make_shared<struct pollfd[]>(n) but this is not
|
||||
// implemented on the compiler that comes with Ubuntu 22 and a few other
|
||||
// distros, so use the manual new and delete until we drop those distros.
|
||||
return std::shared_ptr<struct pollfd[]>(new struct pollfd[n], std::default_delete<struct pollfd[]>());
|
||||
return std::make_shared<struct pollfd[]>(n);
|
||||
}
|
||||
|
||||
ssize_t ArchNetworkBSD::Deps::read(int fd, void *buf, size_t len)
|
||||
@ -96,22 +90,15 @@ void ArchNetworkBSD::Deps::testCancelThread()
|
||||
// ArchNetworkBSD
|
||||
//
|
||||
|
||||
ArchNetworkBSD::~ArchNetworkBSD()
|
||||
{
|
||||
if (m_mutex)
|
||||
ARCH->closeMutex(m_mutex);
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::init()
|
||||
{
|
||||
// create mutex to make some calls thread safe
|
||||
m_mutex = ARCH->newMutex();
|
||||
// do nothing
|
||||
}
|
||||
|
||||
ArchSocket ArchNetworkBSD::newSocket(EAddressFamily family, ESocketType type)
|
||||
ArchSocket ArchNetworkBSD::newSocket(AddressFamily family, SocketType type)
|
||||
{
|
||||
// create socket
|
||||
int fd = socket(s_family[family], s_type[type], 0);
|
||||
int fd = socket(s_family[static_cast<int>(family)], s_type[static_cast<int>(type)], 0);
|
||||
if (fd == -1) {
|
||||
throwError(errno);
|
||||
}
|
||||
@ -134,9 +121,8 @@ ArchSocket ArchNetworkBSD::copySocket(ArchSocket s)
|
||||
assert(s != nullptr);
|
||||
|
||||
// ref the socket and return it
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -144,19 +130,22 @@ void ArchNetworkBSD::closeSocket(ArchSocket s)
|
||||
{
|
||||
assert(s != nullptr);
|
||||
|
||||
bool doClose = false;
|
||||
// unref the socket and note if it should be released
|
||||
ARCH->lockMutex(m_mutex);
|
||||
const bool doClose = (--s->m_refCount == 0);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
doClose = (--s->m_refCount == 0);
|
||||
}
|
||||
|
||||
// close the socket if necessary
|
||||
if (doClose) {
|
||||
if (close(s->m_fd) == -1) {
|
||||
// close failed. restore the last ref and throw.
|
||||
int err = errno;
|
||||
ARCH->lockMutex(m_mutex);
|
||||
++s->m_refCount;
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
}
|
||||
throwError(err);
|
||||
}
|
||||
delete s;
|
||||
@ -289,10 +278,10 @@ int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
for (int i = 0; i < num; ++i) {
|
||||
pfd[i].fd = (pe[i].m_socket == nullptr) ? -1 : pe[i].m_socket->m_fd;
|
||||
pfd[i].events = 0;
|
||||
if ((pe[i].m_events & kPOLLIN) != 0) {
|
||||
if ((pe[i].m_events & PollEventMask::In) != 0) {
|
||||
pfd[i].events |= POLLIN;
|
||||
}
|
||||
if ((pe[i].m_events & kPOLLOUT) != 0) {
|
||||
if ((pe[i].m_events & PollEventMask::Out) != 0) {
|
||||
pfd[i].events |= POLLOUT;
|
||||
}
|
||||
}
|
||||
@ -339,16 +328,16 @@ int ArchNetworkBSD::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
for (int i = 0; i < num; ++i) {
|
||||
pe[i].m_revents = 0;
|
||||
if ((pfd[i].revents & POLLIN) != 0) {
|
||||
pe[i].m_revents |= kPOLLIN;
|
||||
pe[i].m_revents |= PollEventMask::In;
|
||||
}
|
||||
if ((pfd[i].revents & POLLOUT) != 0) {
|
||||
pe[i].m_revents |= kPOLLOUT;
|
||||
pe[i].m_revents |= PollEventMask::Out;
|
||||
}
|
||||
if ((pfd[i].revents & POLLERR) != 0) {
|
||||
pe[i].m_revents |= kPOLLERR;
|
||||
pe[i].m_revents |= PollEventMask::Error;
|
||||
}
|
||||
if ((pfd[i].revents & POLLNVAL) != 0) {
|
||||
pe[i].m_revents |= kPOLLNVAL;
|
||||
pe[i].m_revents |= PollEventMask::Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
@ -360,9 +349,7 @@ void ArchNetworkBSD::unblockPollSocket(ArchThread thread)
|
||||
const int *unblockPipe = getUnblockPipeForThread(thread);
|
||||
if (unblockPipe != nullptr) {
|
||||
char dummy = 0;
|
||||
int ignore;
|
||||
|
||||
ignore = write(unblockPipe[1], &dummy, 1);
|
||||
std::ignore = write(unblockPipe[1], &dummy, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,14 +467,16 @@ std::string ArchNetworkBSD::getHostName()
|
||||
return name;
|
||||
}
|
||||
|
||||
ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family)
|
||||
ArchNetAddress ArchNetworkBSD::newAnyAddr(AddressFamily family)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
// allocate address
|
||||
auto *addr = new ArchNetAddressImpl;
|
||||
|
||||
// fill it in
|
||||
switch (family) {
|
||||
case kINET: {
|
||||
case INet: {
|
||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
ipAddr->sin_family = AF_INET;
|
||||
ipAddr->sin_port = 0;
|
||||
@ -496,7 +485,7 @@ ArchNetAddress ArchNetworkBSD::newAnyAddr(EAddressFamily family)
|
||||
break;
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case INet6: {
|
||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
ipAddr->sin6_family = AF_INET6;
|
||||
ipAddr->sin6_port = 0;
|
||||
@ -539,11 +528,10 @@ std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
|
||||
}
|
||||
|
||||
// done with static buffer
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
struct addrinfo *pResult = nullptr;
|
||||
|
||||
if (int ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult); ret != 0) {
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
throwNameError(ret);
|
||||
}
|
||||
|
||||
@ -561,7 +549,6 @@ std::vector<ArchNetAddress> ArchNetworkBSD::nameToAddr(const std::string &name)
|
||||
}
|
||||
|
||||
freeaddrinfo(pResult);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
|
||||
return addresses;
|
||||
}
|
||||
@ -578,45 +565,43 @@ std::string ArchNetworkBSD::addrToName(ArchNetAddress addr)
|
||||
assert(addr != nullptr);
|
||||
|
||||
// mutexed name lookup (ugh)
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
char host[1024];
|
||||
char service[20];
|
||||
|
||||
if (int ret =
|
||||
getnameinfo(TYPED_ADDR(struct sockaddr, addr), addr->m_len, host, sizeof(host), service, sizeof(service), 0);
|
||||
ret != 0) {
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
throwNameError(ret);
|
||||
}
|
||||
|
||||
// save (primary) name
|
||||
std::string name = host;
|
||||
|
||||
// done with static buffer
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case INet: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
std::string s = inet_ntoa(ipAddr->sin_addr);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
return s;
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case INet6: {
|
||||
char strAddr[INET6_ADDRSTRLEN];
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
ARCH->lockMutex(m_mutex);
|
||||
inet_ntop(AF_INET6, &ipAddr->sin6_addr, strAddr, INET6_ADDRSTRLEN);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
inet_ntop(AF_INET6, &ipAddr->sin6_addr, strAddr, INET6_ADDRSTRLEN);
|
||||
}
|
||||
return strAddr;
|
||||
}
|
||||
|
||||
@ -626,33 +611,37 @@ std::string ArchNetworkBSD::addrToString(ArchNetAddress addr)
|
||||
}
|
||||
}
|
||||
|
||||
IArchNetwork::EAddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr)
|
||||
IArchNetwork::AddressFamily ArchNetworkBSD::getAddrFamily(ArchNetAddress addr)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (addr->m_addr.ss_family) {
|
||||
case AF_INET:
|
||||
return kINET;
|
||||
return INet;
|
||||
case AF_INET6:
|
||||
return kINET6;
|
||||
return INet6;
|
||||
|
||||
default:
|
||||
return kUNKNOWN;
|
||||
return Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case INet: {
|
||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
ipAddr->sin_port = htons(port);
|
||||
break;
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case INet6: {
|
||||
auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
ipAddr->sin6_port = htons(port);
|
||||
break;
|
||||
@ -666,15 +655,17 @@ void ArchNetworkBSD::setAddrPort(ArchNetAddress addr, int port)
|
||||
|
||||
int ArchNetworkBSD::getAddrPort(ArchNetAddress addr)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case INet: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return ntohs(ipAddr->sin_port);
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case INet6: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
return ntohs(ipAddr->sin6_port);
|
||||
}
|
||||
@ -687,15 +678,17 @@ int ArchNetworkBSD::getAddrPort(ArchNetAddress addr)
|
||||
|
||||
bool ArchNetworkBSD::isAnyAddr(ArchNetAddress addr)
|
||||
{
|
||||
using enum AddressFamily;
|
||||
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case INet: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return (ipAddr->sin_addr.s_addr == INADDR_ANY && addr->m_len == static_cast<socklen_t>(sizeof(struct sockaddr_in)));
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case INet6: {
|
||||
const auto *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
return (
|
||||
addr->m_len == (socklen_t)sizeof(struct sockaddr_in6) &&
|
||||
@ -747,7 +740,7 @@ const int *ArchNetworkBSD::getUnblockPipeForThread(ArchThread thread)
|
||||
return unblockPipe;
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::throwError(int err) const
|
||||
[[noreturn]] void ArchNetworkBSD::throwError(int err) const
|
||||
{
|
||||
switch (err) {
|
||||
case EINTR:
|
||||
@ -818,7 +811,7 @@ void ArchNetworkBSD::throwError(int err) const
|
||||
}
|
||||
}
|
||||
|
||||
void ArchNetworkBSD::throwNameError(int err) const
|
||||
[[noreturn]] void ArchNetworkBSD::throwNameError(int err) const
|
||||
{
|
||||
static const char *s_msg[] = {
|
||||
"The specified host is unknown", "The requested name is valid but does not have an IP address",
|
||||
|
||||
@ -11,29 +11,9 @@
|
||||
#include "arch/IArchNetwork.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_SYS_SOCKET_H
|
||||
#include <sys/socket.h>
|
||||
#else
|
||||
struct sockaddr_storage
|
||||
{
|
||||
unsigned char ss_len; /* address length */
|
||||
unsigned char ss_family; /* [XSI] address family */
|
||||
char __ss_pad1[_SS_PAD1SIZE];
|
||||
long long __ss_align; /* force structure storage alignment */
|
||||
char __ss_pad2[_SS_PAD2SIZE];
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !HAVE_SOCKLEN_T
|
||||
using socklen_t = int;
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#define ARCH_NETWORK ArchNetworkBSD
|
||||
#define TYPED_ADDR(type_, addr_) (reinterpret_cast<type_ *>(&addr_->m_addr))
|
||||
@ -83,7 +63,7 @@ public:
|
||||
}
|
||||
ArchNetworkBSD(ArchNetworkBSD const &) = delete;
|
||||
ArchNetworkBSD(ArchNetworkBSD &&) = delete;
|
||||
~ArchNetworkBSD() override;
|
||||
~ArchNetworkBSD() override = default;
|
||||
|
||||
ArchNetworkBSD &operator=(ArchNetworkBSD const &) = delete;
|
||||
ArchNetworkBSD &operator=(ArchNetworkBSD &&) = delete;
|
||||
@ -91,7 +71,7 @@ public:
|
||||
void init() override;
|
||||
|
||||
// IArchNetwork overrides
|
||||
ArchSocket newSocket(EAddressFamily, ESocketType) override;
|
||||
ArchSocket newSocket(AddressFamily, SocketType) override;
|
||||
ArchSocket copySocket(ArchSocket s) override;
|
||||
void closeSocket(ArchSocket s) override;
|
||||
void closeSocketForRead(ArchSocket s) override;
|
||||
@ -108,13 +88,13 @@ public:
|
||||
bool setNoDelayOnSocket(ArchSocket, bool noDelay) override;
|
||||
bool setReuseAddrOnSocket(ArchSocket, bool reuse) override;
|
||||
std::string getHostName() override;
|
||||
ArchNetAddress newAnyAddr(EAddressFamily) override;
|
||||
ArchNetAddress newAnyAddr(AddressFamily) override;
|
||||
ArchNetAddress copyAddr(ArchNetAddress) override;
|
||||
std::vector<ArchNetAddress> nameToAddr(const std::string &) override;
|
||||
void closeAddr(ArchNetAddress) override;
|
||||
std::string addrToName(ArchNetAddress) override;
|
||||
std::string addrToString(ArchNetAddress) override;
|
||||
EAddressFamily getAddrFamily(ArchNetAddress) override;
|
||||
AddressFamily getAddrFamily(ArchNetAddress) override;
|
||||
void setAddrPort(ArchNetAddress, int port) override;
|
||||
int getAddrPort(ArchNetAddress) override;
|
||||
bool isAnyAddr(ArchNetAddress) override;
|
||||
@ -124,10 +104,9 @@ private:
|
||||
const int *getUnblockPipe();
|
||||
const int *getUnblockPipeForThread(ArchThread);
|
||||
void setBlockingOnSocket(int fd, bool blocking) const;
|
||||
void throwError(int) const;
|
||||
void throwNameError(int) const;
|
||||
[[noreturn]] void throwError(int) const override;
|
||||
[[noreturn]] void throwNameError(int) const override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Deps> m_pDeps;
|
||||
ArchMutex m_mutex{};
|
||||
std::mutex m_mutex;
|
||||
};
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "arch/unix/ArchSleepUnix.h"
|
||||
|
||||
#include "arch/Arch.h"
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
#if !HAVE_NANOSLEEP
|
||||
#if HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// ArchSleepUnix
|
||||
//
|
||||
|
||||
void ArchSleepUnix::sleep(double timeout)
|
||||
{
|
||||
ARCH->testCancelThread();
|
||||
if (timeout < 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if HAVE_NANOSLEEP
|
||||
// prep timeout
|
||||
struct timespec t;
|
||||
t.tv_sec = (long)timeout;
|
||||
t.tv_nsec = (long)(1.0e+9 * (timeout - (double)t.tv_sec));
|
||||
|
||||
// wait
|
||||
while (nanosleep(&t, &t) < 0)
|
||||
ARCH->testCancelThread();
|
||||
#else
|
||||
/* emulate nanosleep() with select() */
|
||||
double startTime = ARCH->time();
|
||||
double timeLeft = timeout;
|
||||
while (timeLeft > 0.0) {
|
||||
struct timeval timeout2;
|
||||
timeout2.tv_sec = static_cast<int>(timeLeft);
|
||||
timeout2.tv_usec = static_cast<int>(1.0e+6 * (timeLeft - timeout2.tv_sec));
|
||||
select(
|
||||
(SELECT_TYPE_ARG1)0, SELECT_TYPE_ARG234 nullptr, SELECT_TYPE_ARG234 nullptr, SELECT_TYPE_ARG234 nullptr,
|
||||
SELECT_TYPE_ARG5 & timeout2
|
||||
);
|
||||
ARCH->testCancelThread();
|
||||
timeLeft = timeout - (ARCH->time() - startTime);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchSleep.h"
|
||||
|
||||
#define ARCH_SLEEP ArchSleepUnix
|
||||
|
||||
//! Unix implementation of IArchSleep
|
||||
class ArchSleepUnix : public IArchSleep
|
||||
{
|
||||
public:
|
||||
ArchSleepUnix() = default;
|
||||
~ArchSleepUnix() override = default;
|
||||
|
||||
// IArchSleep overrides
|
||||
void sleep(double timeout) override;
|
||||
};
|
||||
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "arch/unix/ArchTimeUnix.h"
|
||||
|
||||
#if TIME_WITH_SYS_TIME
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
#if HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//
|
||||
// ArchTimeUnix
|
||||
//
|
||||
|
||||
double ArchTimeUnix::time()
|
||||
{
|
||||
struct timeval t;
|
||||
gettimeofday(&t, nullptr);
|
||||
return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchTime.h"
|
||||
|
||||
#define ARCH_TIME ArchTimeUnix
|
||||
|
||||
//! Generic Unix implementation of IArchTime
|
||||
class ArchTimeUnix : public IArchTime
|
||||
{
|
||||
public:
|
||||
ArchTimeUnix() = default;
|
||||
~ArchTimeUnix() override = default;
|
||||
|
||||
// IArchTime overrides
|
||||
double time() override;
|
||||
};
|
||||
@ -12,7 +12,9 @@
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
#include "arch/win32/XArchWindows.h"
|
||||
#include "base/Log.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
inline static const auto kDefaultDaemonName = _T(kAppName);
|
||||
//
|
||||
// ArchDaemonWindows
|
||||
//
|
||||
@ -167,7 +169,7 @@ void ArchDaemonWindows::uninstallDaemon(const char *name)
|
||||
// give windows a chance to remove the service before we check if it still exists.
|
||||
// 100ms should be plenty of time.
|
||||
LOG_DEBUG("waiting for service to be removed");
|
||||
ARCH->sleep(0.1);
|
||||
Arch::sleep(0.1);
|
||||
|
||||
// handle failure. ignore error if service isn't installed anymore.
|
||||
if (!okay && isDaemonInstalled(name)) {
|
||||
@ -604,17 +606,17 @@ void ArchDaemonWindows::stop(const char *name)
|
||||
void ArchDaemonWindows::installDaemon()
|
||||
{
|
||||
// install default daemon if not already installed.
|
||||
if (!isDaemonInstalled(DEFAULT_DAEMON_NAME)) {
|
||||
if (!isDaemonInstalled(kDefaultDaemonName)) {
|
||||
char binPath[MAX_PATH];
|
||||
GetModuleFileName(ArchMiscWindows::instanceWin32(), binPath, MAX_PATH);
|
||||
|
||||
// wrap in quotes so a malicious user can't start \Program.exe as admin.
|
||||
const auto command = "\"" + std::string(binPath) + "\"";
|
||||
|
||||
installDaemon(DEFAULT_DAEMON_NAME, DEFAULT_DAEMON_INFO, command.c_str(), "", "");
|
||||
installDaemon(kDefaultDaemonName, DEFAULT_DAEMON_INFO, command.c_str(), "", "");
|
||||
}
|
||||
|
||||
start(DEFAULT_DAEMON_NAME);
|
||||
start(kDefaultDaemonName);
|
||||
}
|
||||
|
||||
void ArchDaemonWindows::uninstallDaemon()
|
||||
@ -628,7 +630,7 @@ void ArchDaemonWindows::uninstallDaemon()
|
||||
}
|
||||
|
||||
// remove new service if installed.
|
||||
if (isDaemonInstalled(DEFAULT_DAEMON_NAME)) {
|
||||
uninstallDaemon(DEFAULT_DAEMON_NAME);
|
||||
if (isDaemonInstalled(kDefaultDaemonName)) {
|
||||
uninstallDaemon(kDefaultDaemonName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
|
||||
#include "arch/IArchDaemon.h"
|
||||
#include "arch/IArchMultithread.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
@ -77,7 +76,7 @@ public:
|
||||
int daemonize(const char *name, DaemonFunc const &func) override;
|
||||
bool canInstallDaemon(const char *name) override;
|
||||
bool isDaemonInstalled(const char *name) override;
|
||||
std::string commandLine() const
|
||||
std::string commandLine() const override
|
||||
{
|
||||
return m_commandLine;
|
||||
}
|
||||
@ -136,7 +135,6 @@ private:
|
||||
std::string m_commandLine;
|
||||
};
|
||||
|
||||
#define DEFAULT_DAEMON_NAME _T(kAppName)
|
||||
#define DEFAULT_DAEMON_INFO _T("Runs the Core process on secure desktops (UAC prompts, login screen, etc).")
|
||||
|
||||
#define LEGACY_SERVER_DAEMON_NAME _T("Deskflow Server")
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "arch/win32/ArchLogWindows.h"
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -39,17 +38,17 @@ void ArchLogWindows::showLog(bool)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
void ArchLogWindows::writeLog(ELevel level, const char *msg)
|
||||
void ArchLogWindows::writeLog(LogLevel level, const char *msg)
|
||||
{
|
||||
if (m_eventLog != nullptr) {
|
||||
// convert priority
|
||||
WORD type;
|
||||
switch (level) {
|
||||
case kERROR:
|
||||
case LogLevel::Error:
|
||||
type = EVENTLOG_ERROR_TYPE;
|
||||
break;
|
||||
|
||||
case kWARNING:
|
||||
case LogLevel::Warning:
|
||||
type = EVENTLOG_WARNING_TYPE;
|
||||
break;
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ public:
|
||||
void openLog(const char *name) override;
|
||||
void closeLog() override;
|
||||
void showLog(bool showIfEmpty) override;
|
||||
void writeLog(ELevel, const char *) override;
|
||||
void writeLog(LogLevel, const char *) override;
|
||||
|
||||
private:
|
||||
HANDLE m_eventLog;
|
||||
|
||||
@ -7,11 +7,11 @@
|
||||
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
|
||||
#include "arch/XArch.h"
|
||||
#include "arch/win32/ArchDaemonWindows.h"
|
||||
#include "arch/win32/XArchWindows.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/String.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
#include <Psapi.h>
|
||||
|
||||
|
||||
@ -80,13 +80,12 @@ ArchMultithreadWindows::ArchMultithreadWindows()
|
||||
s_instance = this;
|
||||
|
||||
// no signal handlers
|
||||
for (size_t i = 0; i < kNUM_SIGNALS; ++i) {
|
||||
for (size_t i = 0; i < static_cast<size_t>(ThreadSignal::MaxSignals); ++i) {
|
||||
m_signalFunc[i] = nullptr;
|
||||
m_signalUserData[i] = nullptr;
|
||||
}
|
||||
|
||||
// create mutex for thread list
|
||||
m_threadMutex = newMutex();
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread for calling (main) thread and add it to our
|
||||
// list. no need to lock the mutex since we're the only thread.
|
||||
@ -104,33 +103,25 @@ ArchMultithreadWindows::~ArchMultithreadWindows()
|
||||
for (ThreadList::iterator index = m_threadList.begin(); index != m_threadList.end(); ++index) {
|
||||
delete *index;
|
||||
}
|
||||
|
||||
// done with mutex
|
||||
delete m_threadMutex;
|
||||
}
|
||||
|
||||
void ArchMultithreadWindows::setNetworkDataForCurrentThread(void *data)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
thread->m_networkData = data;
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
void *ArchMultithreadWindows::getNetworkDataForThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *data = thread->m_networkData;
|
||||
unlockMutex(m_threadMutex);
|
||||
return data;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_networkData;
|
||||
}
|
||||
|
||||
HANDLE
|
||||
ArchMultithreadWindows::getCancelEventForCurrentThread()
|
||||
HANDLE ArchMultithreadWindows::getCancelEventForCurrentThread()
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
unlockMutex(m_threadMutex);
|
||||
return thread->m_cancel;
|
||||
}
|
||||
|
||||
@ -263,7 +254,8 @@ void ArchMultithreadWindows::unlockMutex(ArchMutex mutex)
|
||||
|
||||
ArchThread ArchMultithreadWindows::newThread(ThreadFunc func, void *data)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
// note that the child thread will wait until we release this mutex
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
|
||||
// create thread impl for new thread
|
||||
ArchThreadImpl *thread = new ArchThreadImpl;
|
||||
@ -288,17 +280,13 @@ ArchThread ArchMultithreadWindows::newThread(ThreadFunc func, void *data)
|
||||
refThread(thread);
|
||||
}
|
||||
|
||||
// note that the child thread will wait until we release this mutex
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
ArchThread ArchMultithreadWindows::newCurrentThread()
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = find(GetCurrentThreadId());
|
||||
unlockMutex(m_threadMutex);
|
||||
assert(thread != nullptr);
|
||||
return thread;
|
||||
}
|
||||
@ -315,10 +303,11 @@ void ArchMultithreadWindows::closeThread(ArchThread thread)
|
||||
}
|
||||
|
||||
// remove thread from list
|
||||
lockMutex(m_threadMutex);
|
||||
assert(findNoRefOrCreate(thread->m_id) == thread);
|
||||
erase(thread);
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
assert(findNoRefOrCreate(thread->m_id) == thread);
|
||||
erase(thread);
|
||||
}
|
||||
|
||||
// done with thread
|
||||
delete thread;
|
||||
@ -400,9 +389,8 @@ void ArchMultithreadWindows::setPriorityOfThread(ArchThread thread, int n)
|
||||
void ArchMultithreadWindows::testCancelThread()
|
||||
{
|
||||
// find current thread
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
ArchThreadImpl *thread = findNoRef(GetCurrentThreadId());
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
// test cancel on thread
|
||||
testCancelThreadImpl(thread);
|
||||
@ -412,22 +400,19 @@ bool ArchMultithreadWindows::wait(ArchThread target, double timeout)
|
||||
{
|
||||
assert(target != nullptr);
|
||||
|
||||
lockMutex(m_threadMutex);
|
||||
|
||||
// find current thread
|
||||
ArchThreadImpl *self = findNoRef(GetCurrentThreadId());
|
||||
|
||||
// ignore wait if trying to wait on ourself
|
||||
if (target == self) {
|
||||
unlockMutex(m_threadMutex);
|
||||
return false;
|
||||
ArchThreadImpl *self = nullptr;
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
// find current thread
|
||||
self = findNoRef(GetCurrentThreadId());
|
||||
// ignore wait if trying to wait on ourself
|
||||
if (target == self) {
|
||||
return false;
|
||||
}
|
||||
// ref the target so it can't go away while we're watching it
|
||||
refThread(target);
|
||||
}
|
||||
|
||||
// ref the target so it can't go away while we're watching it
|
||||
refThread(target);
|
||||
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
// convert timeout
|
||||
DWORD t;
|
||||
if (timeout < 0.0) {
|
||||
@ -480,10 +465,8 @@ bool ArchMultithreadWindows::isExitedThread(ArchThread thread)
|
||||
|
||||
void *ArchMultithreadWindows::getResultOfThread(ArchThread thread)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
void *result = thread->m_result;
|
||||
unlockMutex(m_threadMutex);
|
||||
return result;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
return thread->m_result;
|
||||
}
|
||||
|
||||
IArchMultithread::ThreadID ArchMultithreadWindows::getIDOfThread(ArchThread thread)
|
||||
@ -491,24 +474,25 @@ IArchMultithread::ThreadID ArchMultithreadWindows::getIDOfThread(ArchThread thre
|
||||
return static_cast<ThreadID>(thread->m_id);
|
||||
}
|
||||
|
||||
void ArchMultithreadWindows::setSignalHandler(ESignal signal, SignalFunc func, void *userData)
|
||||
void ArchMultithreadWindows::setSignalHandler(ThreadSignal signal, SignalFunc func, void *userData)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
m_signalFunc[signal] = func;
|
||||
m_signalUserData[signal] = userData;
|
||||
unlockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
const auto index = static_cast<int>(signal);
|
||||
m_signalFunc[index] = func;
|
||||
m_signalUserData[index] = userData;
|
||||
}
|
||||
|
||||
void ArchMultithreadWindows::raiseSignal(ESignal signal)
|
||||
void ArchMultithreadWindows::raiseSignal(ThreadSignal signal)
|
||||
{
|
||||
lockMutex(m_threadMutex);
|
||||
if (m_signalFunc[signal] != nullptr) {
|
||||
m_signalFunc[signal](signal, m_signalUserData[signal]);
|
||||
using enum IArchMultithread::ThreadSignal;
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
const auto index = static_cast<int>(signal);
|
||||
if (m_signalFunc[index] != nullptr) {
|
||||
m_signalFunc[index](signal, m_signalUserData[index]);
|
||||
ARCH->unblockPollSocket(m_mainThread);
|
||||
} else if (signal == kINTERRUPT || signal == kTERMINATE) {
|
||||
} else if (signal == Interrupt || signal == Terminate) {
|
||||
ARCH->cancelThread(m_mainThread);
|
||||
}
|
||||
unlockMutex(m_threadMutex);
|
||||
}
|
||||
|
||||
ArchThreadImpl *ArchMultithreadWindows::find(DWORD id)
|
||||
@ -586,11 +570,10 @@ void ArchMultithreadWindows::testCancelThreadImpl(ArchThreadImpl *thread)
|
||||
}
|
||||
|
||||
// update cancel state
|
||||
lockMutex(m_threadMutex);
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
bool cancel = !thread->m_cancelling;
|
||||
thread->m_cancelling = true;
|
||||
ResetEvent(thread->m_cancel);
|
||||
unlockMutex(m_threadMutex);
|
||||
|
||||
// unwind thread's stack if cancelling
|
||||
if (cancel) {
|
||||
@ -613,8 +596,9 @@ unsigned int __stdcall ArchMultithreadWindows::threadFunc(void *vrep)
|
||||
void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
|
||||
{
|
||||
// wait for parent to initialize this object
|
||||
lockMutex(m_threadMutex);
|
||||
unlockMutex(m_threadMutex);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
}
|
||||
|
||||
void *result = nullptr;
|
||||
try {
|
||||
@ -626,16 +610,20 @@ void ArchMultithreadWindows::doThreadFunc(ArchThread thread)
|
||||
// client called cancel()
|
||||
} catch (...) {
|
||||
// note -- don't catch (...) to avoid masking bugs
|
||||
SetEvent(thread->m_exit);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
SetEvent(thread->m_exit);
|
||||
}
|
||||
closeThread(thread);
|
||||
throw;
|
||||
}
|
||||
|
||||
// thread has exited
|
||||
lockMutex(m_threadMutex);
|
||||
thread->m_result = result;
|
||||
unlockMutex(m_threadMutex);
|
||||
SetEvent(thread->m_exit);
|
||||
{
|
||||
std::scoped_lock lock{m_threadMutex};
|
||||
thread->m_result = result;
|
||||
SetEvent(thread->m_exit);
|
||||
}
|
||||
|
||||
// done with thread
|
||||
closeThread(thread);
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "arch/IArchMultithread.h"
|
||||
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
@ -82,8 +83,8 @@ public:
|
||||
bool isExitedThread(ArchThread) override;
|
||||
void *getResultOfThread(ArchThread) override;
|
||||
ThreadID getIDOfThread(ArchThread) override;
|
||||
void setSignalHandler(ESignal, SignalFunc, void *) override;
|
||||
void raiseSignal(ESignal) override;
|
||||
void setSignalHandler(ThreadSignal, SignalFunc, void *) override;
|
||||
void raiseSignal(ThreadSignal) override;
|
||||
|
||||
private:
|
||||
ArchThreadImpl *find(DWORD id);
|
||||
@ -103,11 +104,11 @@ private:
|
||||
|
||||
static ArchMultithreadWindows *s_instance;
|
||||
|
||||
ArchMutex m_threadMutex;
|
||||
std::mutex m_threadMutex;
|
||||
|
||||
ThreadList m_threadList;
|
||||
ArchThread m_mainThread;
|
||||
|
||||
SignalFunc m_signalFunc[kNUM_SIGNALS];
|
||||
void *m_signalUserData[kNUM_SIGNALS];
|
||||
SignalFunc m_signalFunc[static_cast<int>(ThreadSignal::MaxSignals)];
|
||||
void *m_signalUserData[static_cast<int>(ThreadSignal::MaxSignals)];
|
||||
};
|
||||
|
||||
@ -82,10 +82,6 @@ ArchNetAddressImpl *ArchNetAddressImpl::alloc(size_t size)
|
||||
// ArchNetworkWinsock
|
||||
//
|
||||
|
||||
ArchNetworkWinsock::ArchNetworkWinsock() : m_mutex(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ArchNetworkWinsock::~ArchNetworkWinsock()
|
||||
{
|
||||
if (s_networkModule != nullptr) {
|
||||
@ -95,9 +91,6 @@ ArchNetworkWinsock::~ArchNetworkWinsock()
|
||||
WSACleanup_winsock = nullptr;
|
||||
s_networkModule = nullptr;
|
||||
}
|
||||
if (m_mutex != nullptr) {
|
||||
ARCH->closeMutex(m_mutex);
|
||||
}
|
||||
|
||||
EventList::iterator it;
|
||||
for (it = m_unblockEvents.begin(); it != m_unblockEvents.end(); it++) {
|
||||
@ -116,7 +109,6 @@ void ArchNetworkWinsock::init()
|
||||
for (size_t i = 0; i < sizeof(s_library) / sizeof(s_library[0]); ++i) {
|
||||
try {
|
||||
initModule((HMODULE)::LoadLibrary(s_library[i]));
|
||||
m_mutex = ARCH->newMutex();
|
||||
return;
|
||||
} catch (XArchNetwork &) {
|
||||
// ignore
|
||||
@ -200,10 +192,10 @@ void ArchNetworkWinsock::initModule(HMODULE module)
|
||||
s_networkModule = module;
|
||||
}
|
||||
|
||||
ArchSocket ArchNetworkWinsock::newSocket(EAddressFamily family, ESocketType type)
|
||||
ArchSocket ArchNetworkWinsock::newSocket(AddressFamily family, SocketType type)
|
||||
{
|
||||
// create socket
|
||||
SOCKET fd = socket_winsock(s_family[family], s_type[type], 0);
|
||||
SOCKET fd = socket_winsock(s_family[static_cast<int>(family)], s_type[static_cast<int>(type)], 0);
|
||||
if (fd == INVALID_SOCKET) {
|
||||
throwError(getsockerror_winsock());
|
||||
}
|
||||
@ -233,9 +225,8 @@ ArchSocket ArchNetworkWinsock::copySocket(ArchSocket s)
|
||||
assert(s != nullptr);
|
||||
|
||||
// ref the socket and return it
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -244,18 +235,21 @@ void ArchNetworkWinsock::closeSocket(ArchSocket s)
|
||||
assert(s != nullptr);
|
||||
|
||||
// unref the socket and note if it should be released
|
||||
ARCH->lockMutex(m_mutex);
|
||||
const bool doClose = (--s->m_refCount == 0);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
bool doClose = false;
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
doClose = (--s->m_refCount == 0);
|
||||
}
|
||||
|
||||
// close the socket if necessary
|
||||
if (doClose) {
|
||||
if (close_winsock(s->m_socket) == SOCKET_ERROR) {
|
||||
// close failed. restore the last ref and throw.
|
||||
int err = getsockerror_winsock();
|
||||
ARCH->lockMutex(m_mutex);
|
||||
++s->m_refCount;
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
{
|
||||
std::scoped_lock lock{m_mutex};
|
||||
++s->m_refCount;
|
||||
}
|
||||
throwError(err);
|
||||
}
|
||||
WSACloseEvent_winsock(s->m_event);
|
||||
@ -386,16 +380,16 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
|
||||
// set invalid flag if socket is bogus then go to next socket
|
||||
if (pe[i].m_socket == nullptr) {
|
||||
pe[i].m_revents |= kPOLLNVAL;
|
||||
pe[i].m_revents |= PollEventMask::Invalid;
|
||||
continue;
|
||||
}
|
||||
|
||||
// select desired events
|
||||
long socketEvents = 0;
|
||||
if ((pe[i].m_events & kPOLLIN) != 0) {
|
||||
if ((pe[i].m_events & PollEventMask::In) != 0) {
|
||||
socketEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
|
||||
}
|
||||
if ((pe[i].m_events & kPOLLOUT) != 0) {
|
||||
if ((pe[i].m_events & PollEventMask::Out) != 0) {
|
||||
socketEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE;
|
||||
|
||||
// if m_pollWrite is false then we assume the socket is
|
||||
@ -403,7 +397,7 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
// when the state changes from unwritable.
|
||||
if (!pe[i].m_socket->m_pollWrite) {
|
||||
canWrite = true;
|
||||
pe[i].m_revents |= kPOLLOUT;
|
||||
pe[i].m_revents |= PollEventMask::Out;
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,7 +462,7 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
}
|
||||
for (i = 0, n = 0; i < num; ++i) {
|
||||
// skip events we didn't check
|
||||
if (pe[i].m_socket == nullptr || (pe[i].m_events & (kPOLLIN | kPOLLOUT)) == 0) {
|
||||
if (pe[i].m_socket == nullptr || (pe[i].m_events & (PollEventMask::In | PollEventMask::Out)) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -478,13 +472,13 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
continue;
|
||||
}
|
||||
if ((info.lNetworkEvents & FD_READ) != 0) {
|
||||
pe[i].m_revents |= kPOLLIN;
|
||||
pe[i].m_revents |= PollEventMask::In;
|
||||
}
|
||||
if ((info.lNetworkEvents & FD_ACCEPT) != 0) {
|
||||
pe[i].m_revents |= kPOLLIN;
|
||||
pe[i].m_revents |= PollEventMask::In;
|
||||
}
|
||||
if ((info.lNetworkEvents & FD_WRITE) != 0) {
|
||||
pe[i].m_revents |= kPOLLOUT;
|
||||
pe[i].m_revents |= PollEventMask::Out;
|
||||
|
||||
// socket is now writable so don't bothing polling for
|
||||
// writable until it becomes unwritable.
|
||||
@ -492,21 +486,21 @@ int ArchNetworkWinsock::pollSocket(PollEntry pe[], int num, double timeout)
|
||||
}
|
||||
if ((info.lNetworkEvents & FD_CONNECT) != 0) {
|
||||
if (info.iErrorCode[FD_CONNECT_BIT] != 0) {
|
||||
pe[i].m_revents |= kPOLLERR;
|
||||
pe[i].m_revents |= PollEventMask::Error;
|
||||
} else {
|
||||
pe[i].m_revents |= kPOLLOUT;
|
||||
pe[i].m_revents |= PollEventMask::Out;
|
||||
pe[i].m_socket->m_pollWrite = false;
|
||||
}
|
||||
}
|
||||
if ((info.lNetworkEvents & FD_CLOSE) != 0) {
|
||||
if (info.iErrorCode[FD_CLOSE_BIT] != 0) {
|
||||
pe[i].m_revents |= kPOLLERR;
|
||||
pe[i].m_revents |= PollEventMask::Error;
|
||||
} else {
|
||||
if ((pe[i].m_events & kPOLLIN) != 0) {
|
||||
pe[i].m_revents |= kPOLLIN;
|
||||
if ((pe[i].m_events & PollEventMask::In) != 0) {
|
||||
pe[i].m_revents |= PollEventMask::In;
|
||||
}
|
||||
if ((pe[i].m_events & kPOLLOUT) != 0) {
|
||||
pe[i].m_revents |= kPOLLOUT;
|
||||
if ((pe[i].m_events & PollEventMask::Out) != 0) {
|
||||
pe[i].m_revents |= PollEventMask::Out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -642,11 +636,11 @@ std::string ArchNetworkWinsock::getHostName()
|
||||
return name;
|
||||
}
|
||||
|
||||
ArchNetAddress ArchNetworkWinsock::newAnyAddr(EAddressFamily family)
|
||||
ArchNetAddress ArchNetworkWinsock::newAnyAddr(AddressFamily family)
|
||||
{
|
||||
ArchNetAddressImpl *addr = nullptr;
|
||||
switch (family) {
|
||||
case kINET: {
|
||||
case AddressFamily::INet: {
|
||||
addr = ArchNetAddressImpl::alloc(sizeof(struct sockaddr_in));
|
||||
struct sockaddr_in *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
ipAddr->sin_family = AF_INET;
|
||||
@ -655,7 +649,7 @@ ArchNetAddress ArchNetworkWinsock::newAnyAddr(EAddressFamily family)
|
||||
break;
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case AddressFamily::INet6: {
|
||||
addr = ArchNetAddressImpl::alloc(sizeof(struct sockaddr_in6));
|
||||
struct sockaddr_in6 *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
ipAddr->sin6_family = AF_INET6;
|
||||
@ -690,9 +684,8 @@ std::vector<ArchNetAddress> ArchNetworkWinsock::nameToAddr(const std::string &na
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
int ret = -1;
|
||||
|
||||
ARCH->lockMutex(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if ((ret = getaddrinfo(name.c_str(), nullptr, &hints, &pResult)) != 0) {
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
throwNameError(ret);
|
||||
}
|
||||
|
||||
@ -708,7 +701,6 @@ std::vector<ArchNetAddress> ArchNetworkWinsock::nameToAddr(const std::string &na
|
||||
}
|
||||
|
||||
freeaddrinfo(pResult);
|
||||
ARCH->unlockMutex(m_mutex);
|
||||
return addresses;
|
||||
}
|
||||
|
||||
@ -742,12 +734,12 @@ std::string ArchNetworkWinsock::addrToString(ArchNetAddress addr)
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case AddressFamily::INet: {
|
||||
struct sockaddr_in *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return inet_ntoa_winsock(ipAddr->sin_addr);
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case AddressFamily::INet6: {
|
||||
char strAddr[INET6_ADDRSTRLEN];
|
||||
struct sockaddr_in6 *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
inet_ntop(AF_INET6, &ipAddr->sin6_addr, strAddr, INET6_ADDRSTRLEN);
|
||||
@ -760,19 +752,19 @@ std::string ArchNetworkWinsock::addrToString(ArchNetAddress addr)
|
||||
}
|
||||
}
|
||||
|
||||
IArchNetwork::EAddressFamily ArchNetworkWinsock::getAddrFamily(ArchNetAddress addr)
|
||||
IArchNetwork::AddressFamily ArchNetworkWinsock::getAddrFamily(ArchNetAddress addr)
|
||||
{
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (addr->m_addr.ss_family) {
|
||||
case AF_INET:
|
||||
return kINET;
|
||||
return AddressFamily::INet;
|
||||
|
||||
case AF_INET6:
|
||||
return kINET6;
|
||||
return AddressFamily::INet6;
|
||||
|
||||
default:
|
||||
return kUNKNOWN;
|
||||
return AddressFamily::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
@ -781,13 +773,13 @@ void ArchNetworkWinsock::setAddrPort(ArchNetAddress addr, int port)
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case AddressFamily::INet: {
|
||||
struct sockaddr_in *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
ipAddr->sin_port = htons_winsock(static_cast<u_short>(port));
|
||||
break;
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case AddressFamily::INet6: {
|
||||
struct sockaddr_in6 *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
ipAddr->sin6_port = htons_winsock(static_cast<u_short>(port));
|
||||
break;
|
||||
@ -804,12 +796,12 @@ int ArchNetworkWinsock::getAddrPort(ArchNetAddress addr)
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case AddressFamily::INet: {
|
||||
struct sockaddr_in *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return ntohs_winsock(ipAddr->sin_port);
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case AddressFamily::INet6: {
|
||||
struct sockaddr_in6 *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
return ntohs_winsock(ipAddr->sin6_port);
|
||||
}
|
||||
@ -825,12 +817,12 @@ bool ArchNetworkWinsock::isAnyAddr(ArchNetAddress addr)
|
||||
assert(addr != nullptr);
|
||||
|
||||
switch (getAddrFamily(addr)) {
|
||||
case kINET: {
|
||||
case AddressFamily::INet: {
|
||||
struct sockaddr_in *ipAddr = TYPED_ADDR(struct sockaddr_in, addr);
|
||||
return (addr->m_len == sizeof(struct sockaddr_in) && ipAddr->sin_addr.s_addr == INADDR_ANY);
|
||||
}
|
||||
|
||||
case kINET6: {
|
||||
case AddressFamily::INet6: {
|
||||
struct sockaddr_in6 *ipAddr = TYPED_ADDR(struct sockaddr_in6, addr);
|
||||
return (
|
||||
addr->m_len == sizeof(struct sockaddr_in) && memcmp(&ipAddr->sin6_addr, &in6addr_any, sizeof(in6addr_any)) == 0
|
||||
@ -848,7 +840,7 @@ bool ArchNetworkWinsock::isEqualAddr(ArchNetAddress a, ArchNetAddress b)
|
||||
return (a == b || (a->m_len == b->m_len && memcmp(&a->m_addr, &b->m_addr, a->m_len) == 0));
|
||||
}
|
||||
|
||||
void ArchNetworkWinsock::throwError(int err)
|
||||
[[noreturn]] void ArchNetworkWinsock::throwError(int err) const
|
||||
{
|
||||
switch (err) {
|
||||
case WSAEACCES:
|
||||
@ -918,7 +910,7 @@ void ArchNetworkWinsock::throwError(int err)
|
||||
}
|
||||
}
|
||||
|
||||
void ArchNetworkWinsock::throwNameError(int err)
|
||||
[[noreturn]] void ArchNetworkWinsock::throwNameError(int err) const
|
||||
{
|
||||
switch (err) {
|
||||
case WSAHOST_NOT_FOUND:
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
@ -51,13 +52,13 @@ public:
|
||||
class ArchNetworkWinsock : public IArchNetwork
|
||||
{
|
||||
public:
|
||||
ArchNetworkWinsock();
|
||||
ArchNetworkWinsock() = default;
|
||||
~ArchNetworkWinsock() override;
|
||||
|
||||
void init() override;
|
||||
|
||||
// IArchNetwork overrides
|
||||
ArchSocket newSocket(EAddressFamily, ESocketType) override;
|
||||
ArchSocket newSocket(AddressFamily, SocketType) override;
|
||||
ArchSocket copySocket(ArchSocket s) override;
|
||||
void closeSocket(ArchSocket s) override;
|
||||
void closeSocketForRead(ArchSocket s) override;
|
||||
@ -74,13 +75,13 @@ public:
|
||||
bool setNoDelayOnSocket(ArchSocket, bool noDelay) override;
|
||||
bool setReuseAddrOnSocket(ArchSocket, bool reuse) override;
|
||||
std::string getHostName() override;
|
||||
ArchNetAddress newAnyAddr(EAddressFamily) override;
|
||||
ArchNetAddress newAnyAddr(AddressFamily) override;
|
||||
ArchNetAddress copyAddr(ArchNetAddress) override;
|
||||
std::vector<ArchNetAddress> nameToAddr(const std::string &) override;
|
||||
void closeAddr(ArchNetAddress) override;
|
||||
std::string addrToName(ArchNetAddress) override;
|
||||
std::string addrToString(ArchNetAddress) override;
|
||||
EAddressFamily getAddrFamily(ArchNetAddress) override;
|
||||
AddressFamily getAddrFamily(ArchNetAddress) override;
|
||||
void setAddrPort(ArchNetAddress, int port) override;
|
||||
int getAddrPort(ArchNetAddress) override;
|
||||
bool isAnyAddr(ArchNetAddress) override;
|
||||
@ -91,12 +92,11 @@ private:
|
||||
|
||||
void setBlockingOnSocket(SOCKET, bool blocking);
|
||||
|
||||
void throwError(int);
|
||||
void throwNameError(int);
|
||||
[[noreturn]] void throwError(int) const override;
|
||||
[[noreturn]] void throwNameError(int) const override;
|
||||
|
||||
private:
|
||||
using EventList = std::list<WSAEVENT>;
|
||||
|
||||
ArchMutex m_mutex;
|
||||
std::mutex m_mutex;
|
||||
EventList m_unblockEvents;
|
||||
};
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "arch/win32/ArchSleepWindows.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "arch/win32/ArchMultithreadWindows.h"
|
||||
|
||||
//
|
||||
// ArchSleepWindows
|
||||
//
|
||||
|
||||
void ArchSleepWindows::sleep(double timeout)
|
||||
{
|
||||
ARCH->testCancelThread();
|
||||
if (timeout < 0.0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// get the cancel event from the current thread. this only
|
||||
// works if we're using the windows multithread object but
|
||||
// this is windows so that's pretty certain; we'll get a
|
||||
// link error if we're not, though.
|
||||
ArchMultithreadWindows *mt = ArchMultithreadWindows::getInstance();
|
||||
if (mt != nullptr) {
|
||||
HANDLE cancelEvent = mt->getCancelEventForCurrentThread();
|
||||
WaitForSingleObject(cancelEvent, (DWORD)(1000.0 * timeout));
|
||||
if (timeout == 0.0) {
|
||||
Sleep(0);
|
||||
}
|
||||
} else {
|
||||
Sleep((DWORD)(1000.0 * timeout));
|
||||
}
|
||||
ARCH->testCancelThread();
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchSleep.h"
|
||||
|
||||
#define ARCH_SLEEP ArchSleepWindows
|
||||
|
||||
//! Win32 implementation of IArchSleep
|
||||
class ArchSleepWindows : public IArchSleep
|
||||
{
|
||||
public:
|
||||
ArchSleepWindows() = default;
|
||||
~ArchSleepWindows() override = default;
|
||||
|
||||
// IArchSleep overrides
|
||||
void sleep(double timeout) override;
|
||||
};
|
||||
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "arch/win32/ArchTimeWindows.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#define MMNODRV // Disable: Installable driver support
|
||||
#define MMNOSOUND // Disable: Sound support
|
||||
#define MMNOWAVE // Disable: Waveform support
|
||||
#define MMNOMIDI // Disable: MIDI support
|
||||
#define MMNOAUX // Disable: Auxiliary audio support
|
||||
#define MMNOMIXER // Disable: Mixer support
|
||||
#define MMNOJOY // Disable: Joystick support
|
||||
#define MMNOMCI // Disable: MCI support
|
||||
#define MMNOMMIO // Disable: Multimedia file I/O support
|
||||
#define MMNOMMSYSTEM // Disable: General MMSYSTEM functions
|
||||
#include <MMSystem.h>
|
||||
|
||||
typedef WINMMAPI DWORD(WINAPI *PTimeGetTime)(void);
|
||||
|
||||
static double s_freq = 0.0;
|
||||
static HINSTANCE s_mmInstance = nullptr;
|
||||
static PTimeGetTime s_tgt = nullptr;
|
||||
|
||||
//
|
||||
// ArchTimeWindows
|
||||
//
|
||||
|
||||
ArchTimeWindows::ArchTimeWindows()
|
||||
{
|
||||
assert(s_freq == 0.0 || s_mmInstance == nullptr);
|
||||
|
||||
LARGE_INTEGER freq;
|
||||
if (QueryPerformanceFrequency(&freq) && freq.QuadPart != 0) {
|
||||
s_freq = 1.0 / static_cast<double>(freq.QuadPart);
|
||||
} else {
|
||||
// load winmm.dll and get timeGetTime
|
||||
s_mmInstance = LoadLibrary("winmm");
|
||||
if (s_mmInstance != nullptr) {
|
||||
s_tgt = (PTimeGetTime)GetProcAddress(s_mmInstance, "timeGetTime");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArchTimeWindows::~ArchTimeWindows()
|
||||
{
|
||||
s_freq = 0.0;
|
||||
if (s_mmInstance == nullptr) {
|
||||
FreeLibrary(static_cast<HMODULE>(s_mmInstance));
|
||||
s_tgt = nullptr;
|
||||
s_mmInstance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
double ArchTimeWindows::time()
|
||||
{
|
||||
// get time. we try three ways, in order of descending precision
|
||||
if (s_freq != 0.0) {
|
||||
LARGE_INTEGER c;
|
||||
QueryPerformanceCounter(&c);
|
||||
return s_freq * static_cast<double>(c.QuadPart);
|
||||
} else if (s_tgt != nullptr) {
|
||||
return 0.001 * static_cast<double>(s_tgt());
|
||||
} else {
|
||||
return 0.001 * static_cast<double>(GetTickCount());
|
||||
}
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchTime.h"
|
||||
|
||||
#define ARCH_TIME ArchTimeWindows
|
||||
|
||||
//! Win32 implementation of IArchTime
|
||||
class ArchTimeWindows : public IArchTime
|
||||
{
|
||||
public:
|
||||
ArchTimeWindows();
|
||||
~ArchTimeWindows() override;
|
||||
|
||||
// IArchTime overrides
|
||||
double time() override;
|
||||
};
|
||||
@ -7,7 +7,6 @@
|
||||
*/
|
||||
|
||||
#include "arch/win32/XArchWindows.h"
|
||||
#include "arch/win32/ArchNetworkWinsock.h"
|
||||
#include "base/String.h"
|
||||
|
||||
std::string windowsErrorToString(DWORD error)
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
add_library(base STATIC
|
||||
ELevel.h
|
||||
DirectionTypes.h
|
||||
Event.cpp
|
||||
Event.h
|
||||
EventQueue.cpp
|
||||
@ -24,6 +24,7 @@ add_library(base STATIC
|
||||
LogOutputters.h
|
||||
Log.cpp
|
||||
Log.h
|
||||
LogLevel.h
|
||||
Path.cpp
|
||||
Path.h
|
||||
PriorityQueue.h
|
||||
@ -33,7 +34,6 @@ add_library(base STATIC
|
||||
Stopwatch.h
|
||||
String.cpp
|
||||
String.h
|
||||
TMethodEventJob.h
|
||||
TMethodJob.h
|
||||
Unicode.cpp
|
||||
Unicode.h
|
||||
@ -41,3 +41,4 @@ add_library(base STATIC
|
||||
XBase.h
|
||||
)
|
||||
|
||||
target_link_libraries(base PRIVATE arch)
|
||||
|
||||
47
src/lib/base/DirectionTypes.h
Normal file
47
src/lib/base/DirectionTypes.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
/**
|
||||
* @brief Screen edge directions for mouse movement
|
||||
*
|
||||
* Used to specify which edge of a screen the mouse cursor crosses
|
||||
* when moving between primary and secondary screens.
|
||||
*
|
||||
* @since Protocol version 1.0
|
||||
*/
|
||||
enum class Direction : uint8_t
|
||||
{
|
||||
NoDirection, ///< No specific direction
|
||||
Left, ///< Left edge of screen
|
||||
Right, ///< Right edge of screen
|
||||
Top, ///< Top edge of screen
|
||||
Bottom, ///< Bottom edge of screen
|
||||
FirstDirection = Direction::Left, ///< First valid direction value
|
||||
LastDirection = Direction::Bottom, ///< Last valid direction value
|
||||
NumDirections = Direction::LastDirection - Direction::FirstDirection + 1 ///< Total number of directions
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Bitmask values for screen edge directions
|
||||
*
|
||||
* Used to create bitmasks representing multiple screen edges.
|
||||
* Useful for configuration and edge detection.
|
||||
*
|
||||
* @since Protocol version 1.0
|
||||
*/
|
||||
enum class DirectionMask
|
||||
{
|
||||
NoDirMask = 0, ///< No direction mask
|
||||
LeftMask = 1 << static_cast<int>(Direction::Left), ///< Left edge mask
|
||||
RightMask = 1 << static_cast<int>(Direction::Right), ///< Right edge mask
|
||||
TopMask = 1 << static_cast<int>(Direction::Top), ///< Top edge mask
|
||||
BottomMask = 1 << static_cast<int>(Direction::Bottom) ///< Bottom edge mask
|
||||
};
|
||||
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//! Log levels
|
||||
/*!
|
||||
The logging priority levels in order of highest to lowest priority.
|
||||
*/
|
||||
enum ELevel
|
||||
{
|
||||
kPRINT = -1, //!< For print only (no file or time)
|
||||
kFATAL, //!< For fatal errors
|
||||
kERROR, //!< For serious errors
|
||||
kWARNING, //!< For minor errors and warnings
|
||||
kNOTE, //!< For messages about notable events
|
||||
kINFO, //!< For informational messages
|
||||
kDEBUG, //!< For important debugging messages
|
||||
kDEBUG1, //!< For verbosity +1 debugging messages
|
||||
kDEBUG2, //!< For verbosity +2 debugging messages
|
||||
kDEBUG3, //!< For verbosity +3 debugging messages
|
||||
kDEBUG4, //!< For verbosity +4 debugging messages
|
||||
kDEBUG5 //!< For verbosity +5 debugging messages
|
||||
};
|
||||
@ -55,14 +55,15 @@ Event::Flags Event::getFlags() const
|
||||
void Event::deleteData(const Event &event)
|
||||
{
|
||||
switch (event.getType()) {
|
||||
case EventTypes::Unknown:
|
||||
case EventTypes::Quit:
|
||||
case EventTypes::System:
|
||||
case EventTypes::Timer:
|
||||
using enum EventTypes;
|
||||
case Unknown:
|
||||
case Quit:
|
||||
case System:
|
||||
case Timer:
|
||||
break;
|
||||
|
||||
default:
|
||||
if ((event.getFlags() & kDontFreeData) == 0) {
|
||||
if ((event.getFlags() & EventFlags::DontFreeData) == 0) {
|
||||
free(event.getData());
|
||||
delete event.getDataObject();
|
||||
}
|
||||
|
||||
@ -27,11 +27,11 @@ class Event
|
||||
{
|
||||
public:
|
||||
using Flags = uint32_t;
|
||||
enum
|
||||
struct EventFlags
|
||||
{
|
||||
kNone = 0x00, //!< No flags
|
||||
kDeliverImmediately = 0x01, //!< Dispatch and free event immediately
|
||||
kDontFreeData = 0x02 //!< Don't free data in deleteData
|
||||
inline static const Flags NoFlags = 0x00; //!< No flags
|
||||
inline static const Flags DeliverImmediately = 0x01; //!< Dispatch and free event immediately
|
||||
inline static const Flags DontFreeData = 0x02; //!< Don't free data in deleteData
|
||||
};
|
||||
|
||||
Event() = default;
|
||||
@ -45,7 +45,7 @@ public:
|
||||
\p target is the intended recipient of the event.
|
||||
\p flags is any combination of \c Flags.
|
||||
*/
|
||||
Event(EventTypes type, void *target = nullptr, void *data = nullptr, Flags flags = kNone);
|
||||
Event(EventTypes type, void *target = nullptr, void *data = nullptr, Flags flags = EventFlags::NoFlags);
|
||||
|
||||
//! Create \c Event with non-POD data
|
||||
/*!
|
||||
@ -113,6 +113,6 @@ private:
|
||||
EventTypes m_type = EventTypes::Unknown;
|
||||
void *m_target = nullptr;
|
||||
void *m_data = nullptr;
|
||||
Flags m_flags = kNone;
|
||||
Flags m_flags = EventFlags::NoFlags;
|
||||
EventData *m_dataObject = nullptr;
|
||||
};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
@ -8,7 +9,6 @@
|
||||
#include "base/EventQueue.h"
|
||||
|
||||
#include "arch/Arch.h"
|
||||
#include "base/IEventJob.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/SimpleEventQueueBuffer.h"
|
||||
#include "mt/Lock.h"
|
||||
@ -17,7 +17,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
// interrupt handler. this just adds a quit event to the queue.
|
||||
static void interrupt(Arch::ESignal, void *data)
|
||||
static void interrupt(Arch::ThreadSignal, void *data)
|
||||
{
|
||||
auto *events = static_cast<EventQueue *>(data);
|
||||
events->addEvent(Event(EventTypes::Quit));
|
||||
@ -29,9 +29,8 @@ static void interrupt(Arch::ESignal, void *data)
|
||||
|
||||
EventQueue::EventQueue() : m_readyMutex(new Mutex), m_readyCondVar(new CondVar<bool>(m_readyMutex, false))
|
||||
{
|
||||
m_mutex = ARCH->newMutex();
|
||||
ARCH->setSignalHandler(Arch::kINTERRUPT, &interrupt, this);
|
||||
ARCH->setSignalHandler(Arch::kTERMINATE, &interrupt, this);
|
||||
ARCH->setSignalHandler(Arch::ThreadSignal::Interrupt, &interrupt, this);
|
||||
ARCH->setSignalHandler(Arch::ThreadSignal::Terminate, &interrupt, this);
|
||||
m_buffer = std::make_unique<SimpleEventQueueBuffer>();
|
||||
}
|
||||
|
||||
@ -40,9 +39,8 @@ EventQueue::~EventQueue()
|
||||
delete m_readyCondVar;
|
||||
delete m_readyMutex;
|
||||
|
||||
ARCH->setSignalHandler(Arch::kINTERRUPT, nullptr, nullptr);
|
||||
ARCH->setSignalHandler(Arch::kTERMINATE, nullptr, nullptr);
|
||||
ARCH->closeMutex(m_mutex);
|
||||
ARCH->setSignalHandler(Arch::ThreadSignal::Interrupt, nullptr, nullptr);
|
||||
ARCH->setSignalHandler(Arch::ThreadSignal::Terminate, nullptr, nullptr);
|
||||
}
|
||||
|
||||
void EventQueue::loop()
|
||||
@ -72,7 +70,7 @@ void EventQueue::loop()
|
||||
|
||||
void EventQueue::adoptBuffer(IEventQueueBuffer *buffer)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
LOG((CLOG_DEBUG "adopting new buffer"));
|
||||
|
||||
@ -128,7 +126,8 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
|
||||
uint32_t dataID;
|
||||
IEventQueueBuffer::Type type = m_buffer->getEvent(event, dataID);
|
||||
switch (type) {
|
||||
case IEventQueueBuffer::kNone:
|
||||
using enum IEventQueueBuffer::Type;
|
||||
case Unknown:
|
||||
if (timeout < 0.0 || timeout <= timer.getTime()) {
|
||||
// don't want to fail if client isn't expecting that
|
||||
// so if getEvent() fails with an infinite timeout
|
||||
@ -137,11 +136,11 @@ bool EventQueue::processEvent(Event &event, double timeout, Stopwatch &timer)
|
||||
}
|
||||
return false;
|
||||
|
||||
case IEventQueueBuffer::kSystem:
|
||||
case System:
|
||||
return true;
|
||||
|
||||
case IEventQueueBuffer::kUser: {
|
||||
ArchMutexLock lock(m_mutex);
|
||||
case User: {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
event = removeEvent(dataID);
|
||||
return true;
|
||||
}
|
||||
@ -161,12 +160,12 @@ bool EventQueue::getEvent(Event &event, double timeout)
|
||||
bool EventQueue::dispatchEvent(const Event &event)
|
||||
{
|
||||
void *target = event.getTarget();
|
||||
IEventJob *job = getHandler(event.getType(), target);
|
||||
if (job == nullptr) {
|
||||
job = getHandler(EventTypes::Unknown, target);
|
||||
if (const auto *type_handler = getHandler(event.getType(), target); type_handler) {
|
||||
(*type_handler)(event);
|
||||
return true;
|
||||
}
|
||||
if (job != nullptr) {
|
||||
job->run(event);
|
||||
if (const auto *any_handler = getHandler(EventTypes::Unknown, target); any_handler) {
|
||||
(*any_handler)(event);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -185,7 +184,7 @@ void EventQueue::addEvent(const Event &event)
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.getFlags() & Event::kDeliverImmediately) != 0) {
|
||||
if ((event.getFlags() & Event::EventFlags::DeliverImmediately) != 0) {
|
||||
dispatchEvent(event);
|
||||
Event::deleteData(event);
|
||||
} else if (!(*m_readyCondVar)) {
|
||||
@ -197,7 +196,7 @@ void EventQueue::addEvent(const Event &event)
|
||||
|
||||
void EventQueue::addEventToBuffer(const Event &event)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
// store the event's data locally
|
||||
auto eventID = saveEvent(event);
|
||||
@ -218,7 +217,7 @@ EventQueueTimer *EventQueue::newTimer(double duration, void *target)
|
||||
if (target == nullptr) {
|
||||
target = timer;
|
||||
}
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_timers.insert(timer);
|
||||
// initial duration is requested duration plus whatever's on
|
||||
// the clock currently because the latter will be subtracted
|
||||
@ -235,7 +234,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
|
||||
if (target == nullptr) {
|
||||
target = timer;
|
||||
}
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_timers.insert(timer);
|
||||
// initial duration is requested duration plus whatever's on
|
||||
// the clock currently because the latter will be subtracted
|
||||
@ -246,7 +245,7 @@ EventQueueTimer *EventQueue::newOneShotTimer(double duration, void *target)
|
||||
|
||||
void EventQueue::deleteTimer(EventQueueTimer *timer)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
for (auto index = m_timerQueue.begin(); index != m_timerQueue.end(); ++index) {
|
||||
if (index->getTimer() == timer) {
|
||||
m_timerQueue.erase(index);
|
||||
@ -259,46 +258,32 @@ void EventQueue::deleteTimer(EventQueueTimer *timer)
|
||||
m_buffer->deleteTimer(timer);
|
||||
}
|
||||
|
||||
void EventQueue::adoptHandler(EventTypes type, void *target, IEventJob *handler)
|
||||
void EventQueue::addHandler(EventTypes type, void *target, const EventHandler &handler)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
m_handlers[target][type].reset(handler);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_handlers[target][type] = handler;
|
||||
}
|
||||
|
||||
void EventQueue::removeHandler(EventTypes type, void *target)
|
||||
{
|
||||
std::unique_ptr<IEventJob> handler;
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
TypeHandlerTable &typeHandlers = index->second;
|
||||
TypeHandlerTable::iterator index2 = typeHandlers.find(type);
|
||||
if (index2 != typeHandlers.end()) {
|
||||
handler = std::move(index2->second);
|
||||
typeHandlers.erase(index2);
|
||||
}
|
||||
std::scoped_lock lock{m_mutex};
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
TypeHandlerTable &typeHandlers = index->second;
|
||||
TypeHandlerTable::iterator index2 = typeHandlers.find(type);
|
||||
if (index2 != typeHandlers.end()) {
|
||||
typeHandlers.erase(index2);
|
||||
}
|
||||
}
|
||||
// handler is erased here. It is done outside of lock in order to avoid potential deadlock.
|
||||
}
|
||||
|
||||
void EventQueue::removeHandlers(void *target)
|
||||
{
|
||||
std::vector<std::unique_ptr<IEventJob>> handlers;
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
// copy to handlers array and clear table for target
|
||||
TypeHandlerTable &typeHandlers = index->second;
|
||||
for (auto &[key, value] : typeHandlers) {
|
||||
handlers.push_back(std::move(value));
|
||||
}
|
||||
typeHandlers.clear();
|
||||
}
|
||||
std::scoped_lock lock{m_mutex};
|
||||
HandlerTable::iterator index = m_handlers.find(target);
|
||||
if (index != m_handlers.end()) {
|
||||
index->second.clear();
|
||||
}
|
||||
// handler is erased here. It is done outside of lock in order to avoid potential deadlock.
|
||||
}
|
||||
|
||||
bool EventQueue::isEmpty() const
|
||||
@ -306,14 +291,14 @@ bool EventQueue::isEmpty() const
|
||||
return (m_buffer->isEmpty() && getNextTimerTimeout() != 0.0);
|
||||
}
|
||||
|
||||
IEventJob *EventQueue::getHandler(EventTypes type, void *target) const
|
||||
const EventQueue::EventHandler *EventQueue::getHandler(EventTypes type, void *target) const
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (HandlerTable::const_iterator index = m_handlers.find(target); index != m_handlers.end()) {
|
||||
const TypeHandlerTable &typeHandlers = index->second;
|
||||
TypeHandlerTable::const_iterator index2 = typeHandlers.find(type);
|
||||
if (index2 != typeHandlers.end()) {
|
||||
return index2->second.get();
|
||||
return &index2->second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
@ -417,11 +402,11 @@ void *EventQueue::getSystemTarget()
|
||||
|
||||
void EventQueue::waitForReady() const
|
||||
{
|
||||
double timeout = ARCH->time() + 10;
|
||||
double timeout = Arch::time() + 10;
|
||||
Lock lock(m_readyMutex);
|
||||
|
||||
while (!m_readyCondVar->wait()) {
|
||||
if (ARCH->time() > timeout) {
|
||||
if (Arch::time() > timeout) {
|
||||
throw std::runtime_error("event queue is not ready within 5 sec");
|
||||
}
|
||||
}
|
||||
@ -480,8 +465,3 @@ void EventQueue::Timer::fillEvent(TimerEvent &event) const
|
||||
event.m_count = static_cast<uint32_t>((m_timeout - m_time) / m_timeout);
|
||||
}
|
||||
}
|
||||
|
||||
bool EventQueue::Timer::operator<(const Timer &t) const
|
||||
{
|
||||
return m_time < t.m_time;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
@ -15,11 +16,10 @@
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
|
||||
class Mutex;
|
||||
|
||||
//! Event queue
|
||||
/*!
|
||||
An event queue that implements the platform independent parts and
|
||||
@ -44,15 +44,15 @@ public:
|
||||
EventQueueTimer *newTimer(double duration, void *target) override;
|
||||
EventQueueTimer *newOneShotTimer(double duration, void *target) override;
|
||||
void deleteTimer(EventQueueTimer *) override;
|
||||
void adoptHandler(EventTypes type, void *target, IEventJob *handler) override;
|
||||
void addHandler(EventTypes type, void *target, const EventHandler &handler) override;
|
||||
void removeHandler(EventTypes type, void *target) override;
|
||||
void removeHandlers(void *target) override;
|
||||
bool isEmpty() const override;
|
||||
IEventJob *getHandler(EventTypes type, void *target) const override;
|
||||
void *getSystemTarget() override;
|
||||
void waitForReady() const override;
|
||||
|
||||
private:
|
||||
const EventHandler *getHandler(EventTypes type, void *target) const;
|
||||
uint32_t saveEvent(const Event &event);
|
||||
Event removeEvent(uint32_t eventID);
|
||||
bool hasTimerExpired(Event &event);
|
||||
@ -86,8 +86,6 @@ private:
|
||||
void *getTarget() const;
|
||||
void fillEvent(TimerEvent &) const;
|
||||
|
||||
bool operator<(const Timer &) const;
|
||||
|
||||
private:
|
||||
EventQueueTimer *m_timer;
|
||||
double m_timeout;
|
||||
@ -100,11 +98,11 @@ private:
|
||||
using TimerQueue = PriorityQueue<Timer>;
|
||||
using EventTable = std::map<uint32_t, Event>;
|
||||
using EventIDList = std::vector<uint32_t>;
|
||||
using TypeHandlerTable = std::map<EventTypes, std::unique_ptr<IEventJob>>;
|
||||
using TypeHandlerTable = std::map<EventTypes, EventHandler>;
|
||||
using HandlerTable = std::map<void *, TypeHandlerTable>;
|
||||
|
||||
int m_systemTarget = 0;
|
||||
ArchMutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
|
||||
// buffer of events
|
||||
std::unique_ptr<IEventQueueBuffer> m_buffer;
|
||||
@ -122,7 +120,6 @@ private:
|
||||
// event handlers
|
||||
HandlerTable m_handlers;
|
||||
|
||||
private:
|
||||
Mutex *m_readyMutex = nullptr;
|
||||
CondVar<bool> *m_readyCondVar = nullptr;
|
||||
std::queue<Event> m_pending;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
@ -10,9 +11,10 @@
|
||||
#include "base/Event.h"
|
||||
#include "base/EventTypes.h"
|
||||
#include "common/IInterface.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
class IEventJob;
|
||||
class IEventQueueBuffer;
|
||||
|
||||
// Opaque type for timer info. This is defined by subclasses of
|
||||
@ -29,6 +31,7 @@ timers which generate events periodically.
|
||||
class IEventQueue : public IInterface
|
||||
{
|
||||
public:
|
||||
using EventHandler = std::function<void(const Event &)>;
|
||||
class TimerEvent
|
||||
{
|
||||
public:
|
||||
@ -64,6 +67,9 @@ public:
|
||||
/*!
|
||||
Looks up the dispatcher for the event's target and invokes it.
|
||||
Returns true iff a dispatcher exists for the target.
|
||||
|
||||
The caller must ensure that the target of the event is not removed by removeHandler() or
|
||||
removeHandlers().
|
||||
*/
|
||||
virtual bool dispatchEvent(const Event &event) = 0;
|
||||
|
||||
@ -119,7 +125,7 @@ public:
|
||||
of type \p type. If no such handler exists it will use the handler
|
||||
for \p target and type \p kUnknown if it exists.
|
||||
*/
|
||||
virtual void adoptHandler(EventTypes type, void *target, IEventJob *handler) = 0;
|
||||
virtual void addHandler(EventTypes type, void *target, const EventHandler &handler) = 0;
|
||||
|
||||
//! Unregister an event handler for an event type
|
||||
/*!
|
||||
@ -152,13 +158,6 @@ public:
|
||||
*/
|
||||
virtual bool isEmpty() const = 0;
|
||||
|
||||
//! Get an event handler
|
||||
/*!
|
||||
Finds and returns the event handler for the \p type, \p target pair
|
||||
if it exists, otherwise it returns nullptr.
|
||||
*/
|
||||
virtual IEventJob *getHandler(EventTypes type, void *target) const = 0;
|
||||
|
||||
//! Get the system event type target
|
||||
/*!
|
||||
Returns the target to use for dispatching \c EventTypes::System events.
|
||||
|
||||
@ -20,11 +20,11 @@ An event queue buffer provides a queue of events for an IEventQueue.
|
||||
class IEventQueueBuffer : public IInterface
|
||||
{
|
||||
public:
|
||||
enum Type
|
||||
enum class Type : uint8_t
|
||||
{
|
||||
kNone, //!< No event is available
|
||||
kSystem, //!< Event is a system event
|
||||
kUser //!< Event is a user event
|
||||
Unknown, //!< No event is available
|
||||
System, //!< Event is a system event
|
||||
User //!< Event is a user event
|
||||
};
|
||||
|
||||
//! @name manipulators
|
||||
@ -45,11 +45,11 @@ public:
|
||||
|
||||
//! Get the next event
|
||||
/*!
|
||||
Get the next event from the buffer. Return kNone if no event is
|
||||
available. If a system event is next, return kSystem and fill in
|
||||
Get the next event from the buffer. Return None if no event is
|
||||
available. If a system event is next, return System and fill in
|
||||
event. The event data in a system event can point to a static
|
||||
buffer (because Event::deleteData() will not attempt to delete
|
||||
data in a kSystem event). Otherwise, return kUser and fill in
|
||||
data in a System event). Otherwise, return User and fill in
|
||||
\p dataID with the value passed to \c addEvent().
|
||||
*/
|
||||
virtual Type getEvent(Event &event, uint32_t &dataID) = 0;
|
||||
|
||||
@ -7,8 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base/ELevel.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/LogLevel.h"
|
||||
#include "common/IInterface.h"
|
||||
|
||||
//! Outputter interface
|
||||
@ -53,7 +53,7 @@ public:
|
||||
message to all outputters in the outputter chain, otherwise
|
||||
it continues. Most implementations should return true.
|
||||
*/
|
||||
virtual bool write(ELevel level, const char *message) = 0;
|
||||
virtual bool write(LogLevel level, const char *message) = 0;
|
||||
|
||||
//@}
|
||||
};
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
|
||||
#include "base/Log.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "base/LogLevel.h"
|
||||
#include "base/LogOutputters.h"
|
||||
#include "common/Constants.h"
|
||||
|
||||
@ -33,14 +34,14 @@ static const int g_numPriority = 11;
|
||||
// for visual studio, then NDEBUG will be set (even if your VS solution
|
||||
// config is Debug).
|
||||
#ifndef NDEBUG
|
||||
static const int g_defaultMaxPriority = kDEBUG;
|
||||
static const LogLevel g_defaultMaxPriority = LogLevel::Debug;
|
||||
#else
|
||||
static const int g_defaultMaxPriority = kINFO;
|
||||
static const LogLevel g_defaultMaxPriority = LogLevel::Info;
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
ELevel getPriority(const char *&fmt)
|
||||
LogLevel getPriority(const char *&fmt)
|
||||
{
|
||||
if (strnlen(fmt, SIZE_MAX) < kPriorityPrefixLength) {
|
||||
throw std::invalid_argument("invalid format string, too short");
|
||||
@ -50,7 +51,7 @@ ELevel getPriority(const char *&fmt)
|
||||
throw std::invalid_argument("invalid format string, missing priority");
|
||||
}
|
||||
|
||||
return static_cast<ELevel>(fmt[2] - '0');
|
||||
return static_cast<LogLevel>(fmt[2] - '0');
|
||||
}
|
||||
|
||||
void makeTimeString(std::vector<char> &buffer)
|
||||
@ -74,7 +75,7 @@ void makeTimeString(std::vector<char> &buffer)
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<char> makeMessage(const char *filename, int lineNumber, const char *message, ELevel priority)
|
||||
std::vector<char> makeMessage(const char *filename, int lineNumber, const char *message, LogLevel priority)
|
||||
{
|
||||
|
||||
// base size includes null terminator, colon, space, etc.
|
||||
@ -82,12 +83,13 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
|
||||
|
||||
const int timeBufferSize = 50;
|
||||
const int priorityMaxSize = 10;
|
||||
const auto currentPriority = static_cast<int>(priority);
|
||||
|
||||
std::vector<char> timeBuffer(timeBufferSize);
|
||||
makeTimeString(timeBuffer);
|
||||
|
||||
size_t timestampLength = strnlen(timeBuffer.data(), timeBufferSize);
|
||||
size_t priorityLength = strnlen(g_priority[priority], priorityMaxSize);
|
||||
size_t priorityLength = strnlen(g_priority[currentPriority], priorityMaxSize);
|
||||
size_t messageLength = strnlen(message, SIZE_MAX);
|
||||
size_t bufferSize = baseSize + timestampLength + priorityLength + messageLength;
|
||||
|
||||
@ -99,13 +101,13 @@ std::vector<char> makeMessage(const char *filename, int lineNumber, const char *
|
||||
|
||||
std::vector<char> buffer(bufferSize);
|
||||
snprintf(
|
||||
buffer.data(), bufferSize, "[%s] %s: %s\n\t%s:%d", timeBuffer.data(), g_priority[priority], message, filename,
|
||||
lineNumber
|
||||
buffer.data(), bufferSize, "[%s] %s: %s\n\t%s:%d", timeBuffer.data(), g_priority[currentPriority], message,
|
||||
filename, lineNumber
|
||||
);
|
||||
return buffer;
|
||||
} else {
|
||||
std::vector<char> buffer(bufferSize);
|
||||
snprintf(buffer.data(), bufferSize, "[%s] %s: %s", timeBuffer.data(), g_priority[priority], message);
|
||||
snprintf(buffer.data(), bufferSize, "[%s] %s: %s", timeBuffer.data(), g_priority[currentPriority], message);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
@ -123,9 +125,6 @@ Log::Log(bool singleton)
|
||||
assert(s_log == nullptr);
|
||||
}
|
||||
|
||||
// create mutex for multithread safe operation
|
||||
m_mutex = ARCH->newMutex();
|
||||
|
||||
// other initalization
|
||||
m_maxPriority = g_defaultMaxPriority;
|
||||
insert(new ConsoleLogOutputter); // NOSONAR - Adopted by `Log`
|
||||
@ -149,7 +148,6 @@ Log::~Log()
|
||||
for (auto index = m_alwaysOutputters.begin(); index != m_alwaysOutputters.end(); ++index) {
|
||||
delete *index;
|
||||
}
|
||||
ARCH->closeMutex(m_mutex);
|
||||
}
|
||||
|
||||
Log *Log::getInstance()
|
||||
@ -163,12 +161,13 @@ const char *Log::getFilterName() const
|
||||
return getFilterName(getFilter());
|
||||
}
|
||||
|
||||
const char *Log::getFilterName(int level) const
|
||||
const char *Log::getFilterName(LogLevel level) const
|
||||
{
|
||||
if (level < 0) {
|
||||
const auto levelIndex = static_cast<int>(level);
|
||||
if (levelIndex < 0) {
|
||||
return "Message";
|
||||
}
|
||||
return g_priority[level];
|
||||
return g_priority[levelIndex];
|
||||
}
|
||||
|
||||
void Log::print(const char *file, int line, const char *fmt, ...)
|
||||
@ -176,7 +175,7 @@ void Log::print(const char *file, int line, const char *fmt, ...)
|
||||
const int initBufferSize = 1024;
|
||||
const int bufferResizeScale = 2;
|
||||
|
||||
ELevel priority = getPriority(fmt);
|
||||
LogLevel priority = getPriority(fmt);
|
||||
fmt += kPriorityPrefixLength;
|
||||
|
||||
if (priority > getFilter()) {
|
||||
@ -200,7 +199,7 @@ void Log::print(const char *file, int line, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
if (priority == kPRINT) {
|
||||
if (priority == LogLevel::Print) {
|
||||
output(priority, buffer.data());
|
||||
} else {
|
||||
auto message = makeMessage(file, line, buffer.data(), priority);
|
||||
@ -212,7 +211,7 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||
{
|
||||
assert(adoptedOutputter != nullptr);
|
||||
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
if (alwaysAtHead) {
|
||||
m_alwaysOutputters.push_front(adoptedOutputter);
|
||||
} else {
|
||||
@ -224,14 +223,14 @@ void Log::insert(ILogOutputter *adoptedOutputter, bool alwaysAtHead)
|
||||
|
||||
void Log::remove(ILogOutputter *outputter)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_outputters.remove(outputter);
|
||||
m_alwaysOutputters.remove(outputter);
|
||||
}
|
||||
|
||||
void Log::pop_front(bool alwaysAtHead)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
OutputterList *list = alwaysAtHead ? &m_alwaysOutputters : &m_outputters;
|
||||
if (!list->empty()) {
|
||||
delete list->front();
|
||||
@ -244,7 +243,7 @@ bool Log::setFilter(const char *maxPriority)
|
||||
if (maxPriority != nullptr) {
|
||||
for (int i = 0; i < g_numPriority; ++i) {
|
||||
if (strcmp(maxPriority, g_priority[i]) == 0) {
|
||||
setFilter(i);
|
||||
setFilter(static_cast<LogLevel>(i));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -253,26 +252,26 @@ bool Log::setFilter(const char *maxPriority)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Log::setFilter(int maxPriority)
|
||||
void Log::setFilter(LogLevel maxPriority)
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
m_maxPriority = maxPriority;
|
||||
}
|
||||
|
||||
int Log::getFilter() const
|
||||
LogLevel Log::getFilter() const
|
||||
{
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
return m_maxPriority;
|
||||
}
|
||||
|
||||
void Log::output(ELevel priority, const char *msg)
|
||||
void Log::output(LogLevel priority, const char *msg)
|
||||
{
|
||||
assert(priority >= -1 && priority < g_numPriority);
|
||||
assert(static_cast<int>(priority) >= -1 && static_cast<int>(priority) < g_numPriority);
|
||||
assert(msg != nullptr);
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
ArchMutexLock lock(m_mutex);
|
||||
std::scoped_lock lock{m_mutex};
|
||||
|
||||
OutputterList::const_iterator i;
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#include "arch/IArchMultithread.h"
|
||||
#include "common/Common.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#define CLOG (Log::getInstance())
|
||||
#define BYE "\nTry `%s --help' for more information."
|
||||
|
||||
@ -85,7 +87,7 @@ public:
|
||||
bool setFilter(const char *name);
|
||||
|
||||
//! Set the minimum priority filter (by ordinal).
|
||||
void setFilter(int);
|
||||
void setFilter(LogLevel);
|
||||
|
||||
//@}
|
||||
//! @name accessors
|
||||
@ -100,38 +102,38 @@ public:
|
||||
void print(const char *file, int line, const char *format, ...);
|
||||
|
||||
//! Get the minimum priority level.
|
||||
int getFilter() const;
|
||||
LogLevel getFilter() const;
|
||||
|
||||
//! Get the filter name of the current filter level.
|
||||
const char *getFilterName() const;
|
||||
|
||||
//! Get the filter name of a specified filter level.
|
||||
const char *getFilterName(int level) const;
|
||||
const char *getFilterName(LogLevel level) const;
|
||||
|
||||
//! Get the singleton instance of the log
|
||||
static Log *getInstance();
|
||||
|
||||
//! Get the console filter level (messages above this are not sent to
|
||||
//! console).
|
||||
int getConsoleMaxLevel() const
|
||||
LogLevel getConsoleMaxLevel() const
|
||||
{
|
||||
return kDEBUG2;
|
||||
return LogLevel::Debug2;
|
||||
}
|
||||
|
||||
//@}
|
||||
|
||||
private:
|
||||
void output(ELevel priority, const char *msg);
|
||||
void output(LogLevel priority, const char *msg);
|
||||
|
||||
private:
|
||||
using OutputterList = std::list<ILogOutputter *>;
|
||||
|
||||
static Log *s_log;
|
||||
|
||||
ArchMutex m_mutex;
|
||||
mutable std::mutex m_mutex;
|
||||
OutputterList m_outputters;
|
||||
OutputterList m_alwaysOutputters;
|
||||
int m_maxPriority;
|
||||
LogLevel m_maxPriority;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -143,7 +145,7 @@ LOG((CLOG_XXX "%d and %d are %s", x, y, x == y ? "equal" : "not equal"));
|
||||
\endcode
|
||||
In particular, notice the double open and close parentheses. Also note
|
||||
that there is no comma after the \c CLOG_XXX. The \c XXX should be
|
||||
replaced by one of enumerants in \c Log::ELevel without the leading
|
||||
replaced by one of enumerants in \c Log::LogLevel without the leading
|
||||
\c k. For example, \c CLOG_INFO. The special \c CLOG_PRINT level will
|
||||
not be filtered and is never prefixed by the filename and line number.
|
||||
|
||||
@ -162,7 +164,7 @@ LOGC(x == y, (CLOG_XXX "%d and %d are equal", x, y));
|
||||
\endcode
|
||||
In particular, notice the parentheses around everything after the boolean
|
||||
expression. Also note that there is no comma after the \c CLOG_XXX.
|
||||
The \c XXX should be replaced by one of enumerants in \c Log::ELevel
|
||||
The \c XXX should be replaced by one of enumerants in \c Log::LogLevel
|
||||
without the leading \c k. For example, \c CLOG_INFO. The special
|
||||
\c CLOG_PRINT level will not be filtered and is never prefixed by the
|
||||
filename and line number.
|
||||
|
||||
28
src/lib/base/LogLevel.h
Normal file
28
src/lib/base/LogLevel.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
//! Log levels
|
||||
/*!
|
||||
The logging priority levels in order of highest to lowest priority.
|
||||
*/
|
||||
enum class LogLevel
|
||||
{
|
||||
Print = -1, //!< For print only (no file or time)
|
||||
Fatal, //!< For fatal errors
|
||||
Error, //!< For serious errors
|
||||
Warning, //!< For minor errors and warnings
|
||||
Note, //!< For messages about notable events
|
||||
Info, //!< For informational messages
|
||||
Debug, //!< For important debugging messages
|
||||
Debug1, //!< For verbosity +1 debugging messages
|
||||
Debug2, //!< For verbosity +2 debugging messages
|
||||
Debug3, //!< For verbosity +3 debugging messages
|
||||
Debug4, //!< For verbosity +4 debugging messages
|
||||
Debug5 //!< For verbosity +5 debugging messages
|
||||
};
|
||||
@ -14,10 +14,7 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
enum EFileLogOutputter
|
||||
{
|
||||
kFileSizeLimit = 1024 // kb
|
||||
};
|
||||
constexpr auto s_logFileSizeLimit = 1024 * 1024; //!< Max Log size before rotating (1Mb)
|
||||
|
||||
//
|
||||
// StopLogOutputter
|
||||
@ -38,7 +35,7 @@ void StopLogOutputter::show(bool)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
bool StopLogOutputter::write(ELevel, const char *)
|
||||
bool StopLogOutputter::write(LogLevel, const char *)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -62,9 +59,9 @@ void ConsoleLogOutputter::show(bool showIfEmpty)
|
||||
// do nothing
|
||||
}
|
||||
|
||||
bool ConsoleLogOutputter::write(ELevel level, const char *msg)
|
||||
bool ConsoleLogOutputter::write(LogLevel level, const char *msg)
|
||||
{
|
||||
if ((level >= kFATAL) && (level <= kWARNING))
|
||||
if ((level >= LogLevel::Fatal) && (level <= LogLevel::Warning))
|
||||
std::cerr << msg << std::endl;
|
||||
else
|
||||
std::cout << msg << std::endl;
|
||||
@ -96,7 +93,7 @@ void SystemLogOutputter::show(bool showIfEmpty)
|
||||
ARCH->showLog(showIfEmpty);
|
||||
}
|
||||
|
||||
bool SystemLogOutputter::write(ELevel level, const char *msg)
|
||||
bool SystemLogOutputter::write(LogLevel level, const char *msg)
|
||||
{
|
||||
ARCH->writeLog(level, msg);
|
||||
return true;
|
||||
@ -143,7 +140,7 @@ void FileLogOutputter::setLogFilename(const char *logFile)
|
||||
m_fileName = logFile;
|
||||
}
|
||||
|
||||
bool FileLogOutputter::write(ELevel level, const char *message)
|
||||
bool FileLogOutputter::write(LogLevel level, const char *message)
|
||||
{
|
||||
bool moveFile = false;
|
||||
|
||||
@ -154,7 +151,7 @@ bool FileLogOutputter::write(ELevel level, const char *message)
|
||||
|
||||
// when file size exceeds limits, move to 'old log' filename.
|
||||
size_t p = m_handle.tellp();
|
||||
if (p > (kFileSizeLimit * 1024)) {
|
||||
if (p > s_logFileSizeLimit) {
|
||||
moveFile = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,7 @@ public:
|
||||
void open(const char *title) override;
|
||||
void close() override;
|
||||
void show(bool showIfEmpty) override;
|
||||
bool write(ELevel level, const char *message) override;
|
||||
bool write(LogLevel level, const char *message) override;
|
||||
};
|
||||
|
||||
//! Write log to console
|
||||
@ -46,7 +46,7 @@ public:
|
||||
void open(const char *title) override;
|
||||
void close() override;
|
||||
void show(bool showIfEmpty) override;
|
||||
bool write(ELevel level, const char *message) override;
|
||||
bool write(LogLevel level, const char *message) override;
|
||||
void flush() const;
|
||||
};
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
void open(const char *title) override;
|
||||
void close() override;
|
||||
void show(bool showIfEmpty) override;
|
||||
bool write(ELevel level, const char *message) override;
|
||||
bool write(LogLevel level, const char *message) override;
|
||||
|
||||
void setLogFilename(const char *title);
|
||||
|
||||
@ -88,7 +88,7 @@ public:
|
||||
void open(const char *title) override;
|
||||
void close() override;
|
||||
void show(bool showIfEmpty) override;
|
||||
bool write(ELevel level, const char *message) override;
|
||||
bool write(LogLevel level, const char *message) override;
|
||||
};
|
||||
|
||||
//! Write log to system log only
|
||||
|
||||
@ -10,9 +10,7 @@
|
||||
#include "arch/win32/ArchMiscWindows.h"
|
||||
#endif
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
namespace filesystem {
|
||||
namespace deskflow::filesystem {
|
||||
|
||||
#ifdef SYSAPI_WIN32
|
||||
|
||||
@ -36,6 +34,4 @@ std::string path(const std::string &filePath)
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace deskflow
|
||||
} // namespace deskflow::filesystem
|
||||
|
||||
@ -9,9 +9,7 @@
|
||||
#include "common/Common.h"
|
||||
#include <string>
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
namespace filesystem {
|
||||
namespace deskflow::filesystem {
|
||||
|
||||
#ifdef SYSAPI_WIN32
|
||||
std::wstring path(const std::string &filePath);
|
||||
@ -19,6 +17,4 @@ std::wstring path(const std::string &filePath);
|
||||
std::string path(const std::string &filePath);
|
||||
#endif
|
||||
|
||||
} // namespace filesystem
|
||||
|
||||
} // namespace deskflow
|
||||
} // namespace deskflow::filesystem
|
||||
|
||||
@ -76,13 +76,13 @@ public:
|
||||
}
|
||||
|
||||
//! Swap contents with another priority queue
|
||||
void swap(PriorityQueue<T, Container, Compare> &q)
|
||||
void swap(PriorityQueue<T, Container, Compare> &q) noexcept
|
||||
{
|
||||
c.swap(q.c);
|
||||
}
|
||||
|
||||
//! Swap contents with another container
|
||||
void swap(Container &c2)
|
||||
void swap(Container &c2) noexcept
|
||||
{
|
||||
c.swap(c2);
|
||||
std::make_heap(c.begin(), c.end(), comp);
|
||||
|
||||
@ -49,12 +49,12 @@ IEventQueueBuffer::Type SimpleEventQueueBuffer::getEvent(Event &, uint32_t &data
|
||||
{
|
||||
ArchMutexLock lock(m_queueMutex);
|
||||
if (!m_queueReady) {
|
||||
return kNone;
|
||||
return IEventQueueBuffer::Type::Unknown;
|
||||
}
|
||||
dataID = m_queue.back();
|
||||
m_queue.pop_back();
|
||||
m_queueReady = !m_queue.empty();
|
||||
return kUser;
|
||||
return IEventQueueBuffer::Type::User;
|
||||
}
|
||||
|
||||
bool SimpleEventQueueBuffer::addEvent(uint32_t dataID)
|
||||
|
||||
@ -29,6 +29,7 @@ public:
|
||||
// IEventQueueBuffer overrides
|
||||
void init() override
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
void waitForEvent(double timeout) override;
|
||||
Type getEvent(Event &event, uint32_t &dataID) override;
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
Stopwatch::Stopwatch(bool triggered) : m_triggered(triggered), m_stopped(triggered)
|
||||
{
|
||||
if (!triggered) {
|
||||
m_mark = ARCH->time();
|
||||
m_mark = Arch::time();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ double Stopwatch::reset()
|
||||
m_mark = 0.0;
|
||||
return dt;
|
||||
} else {
|
||||
const double t = ARCH->time();
|
||||
const double t = Arch::time();
|
||||
const double dt = t - m_mark;
|
||||
m_mark = t;
|
||||
return dt;
|
||||
@ -40,7 +40,7 @@ void Stopwatch::stop()
|
||||
}
|
||||
|
||||
// save the elapsed time
|
||||
m_mark = ARCH->time() - m_mark;
|
||||
m_mark = Arch::time() - m_mark;
|
||||
m_stopped = true;
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ void Stopwatch::start()
|
||||
}
|
||||
|
||||
// set the mark such that it reports the time elapsed at stop()
|
||||
m_mark = ARCH->time() - m_mark;
|
||||
m_mark = Arch::time() - m_mark;
|
||||
m_stopped = false;
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ double Stopwatch::getTime()
|
||||
} else if (m_stopped) {
|
||||
return m_mark;
|
||||
} else {
|
||||
return ARCH->time() - m_mark;
|
||||
return Arch::time() - m_mark;
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ double Stopwatch::getTime() const
|
||||
if (m_stopped) {
|
||||
return m_mark;
|
||||
} else {
|
||||
return ARCH->time() - m_mark;
|
||||
return Arch::time() - m_mark;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -13,8 +13,7 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace deskflow {
|
||||
namespace string {
|
||||
namespace deskflow::string {
|
||||
|
||||
std::string format(const char *fmt, ...)
|
||||
{
|
||||
@ -107,7 +106,8 @@ std::string sprintf(const char *fmt, ...)
|
||||
{
|
||||
char tmp[1024];
|
||||
char *buffer = tmp;
|
||||
auto len = (int)(sizeof(tmp) / sizeof(tmp[0]));
|
||||
auto len = static_cast<int>(std::size(tmp));
|
||||
|
||||
std::string result;
|
||||
while (buffer != nullptr) {
|
||||
// try printing into the buffer
|
||||
@ -145,7 +145,7 @@ std::string sizeTypeToString(size_t n)
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
size_t stringToSizeType(std::string string)
|
||||
size_t stringToSizeType(const std::string &string)
|
||||
{
|
||||
std::istringstream iss(string);
|
||||
size_t value;
|
||||
@ -164,7 +164,7 @@ bool CaselessCmp::operator()(const std::string &a, const std::string &b) const
|
||||
|
||||
bool CaselessCmp::less(const std::string_view &a, const std::string_view &b)
|
||||
{
|
||||
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), &deskflow::string::CaselessCmp::cmpLess);
|
||||
return std::ranges::lexicographical_compare(a, b, &deskflow::string::CaselessCmp::cmpLess);
|
||||
}
|
||||
|
||||
bool CaselessCmp::equal(const std::string &a, const std::string &b)
|
||||
@ -178,5 +178,4 @@ bool CaselessCmp::cmpLess(const std::string::value_type &a, const std::string::v
|
||||
return tolower(a) < tolower(b);
|
||||
}
|
||||
|
||||
} // namespace string
|
||||
} // namespace deskflow
|
||||
} // namespace deskflow::string
|
||||
|
||||
@ -12,13 +12,11 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace deskflow {
|
||||
|
||||
//! std::string utilities
|
||||
/*!
|
||||
Provides functions for string manipulation.
|
||||
*/
|
||||
namespace string {
|
||||
namespace deskflow::string {
|
||||
|
||||
//! Format positional arguments
|
||||
/*!
|
||||
@ -54,7 +52,7 @@ std::string sizeTypeToString(size_t n);
|
||||
/*!
|
||||
Convert an a \c string to an size type
|
||||
*/
|
||||
size_t stringToSizeType(std::string string);
|
||||
size_t stringToSizeType(const std::string &string);
|
||||
|
||||
//! Case-insensitive comparisons
|
||||
/*!
|
||||
@ -76,5 +74,4 @@ public:
|
||||
static bool cmpLess(const std::string::value_type &a, const std::string::value_type &b);
|
||||
};
|
||||
|
||||
} // namespace string
|
||||
} // namespace deskflow
|
||||
} // namespace deskflow::string
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2004 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "IEventJob.h"
|
||||
|
||||
//! Use a member function as an event job
|
||||
/*!
|
||||
An event job class that invokes a member function.
|
||||
*/
|
||||
template <class T> class TMethodEventJob : public IEventJob
|
||||
{
|
||||
public:
|
||||
//! run(event) invokes \c object->method(event, arg)
|
||||
TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg = nullptr);
|
||||
~TMethodEventJob() override = default;
|
||||
|
||||
// IJob overrides
|
||||
void run(const Event &) override;
|
||||
|
||||
private:
|
||||
T *m_object;
|
||||
void (T::*m_method)(const Event &, void *);
|
||||
void *m_arg;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline TMethodEventJob<T>::TMethodEventJob(T *object, void (T::*method)(const Event &, void *), void *arg)
|
||||
: m_object(object),
|
||||
m_method(method),
|
||||
m_arg(arg)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
template <class T> inline void TMethodEventJob<T>::run(const Event &event)
|
||||
{
|
||||
if (m_object != nullptr) {
|
||||
(m_object->*m_method)(event, m_arg);
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,9 @@ inline static uint16_t decode16(const uint8_t *n, bool byteSwapped)
|
||||
{
|
||||
uint8_t n8[2];
|
||||
uint16_t n16;
|
||||
} c;
|
||||
};
|
||||
x16 c;
|
||||
|
||||
if (byteSwapped) {
|
||||
c.n8[0] = n[1];
|
||||
c.n8[1] = n[0];
|
||||
@ -35,7 +37,8 @@ inline static uint32_t decode32(const uint8_t *n, bool byteSwapped)
|
||||
{
|
||||
uint8_t n8[4];
|
||||
uint32_t n32;
|
||||
} c;
|
||||
};
|
||||
x32 c;
|
||||
if (byteSwapped) {
|
||||
c.n8[0] = n[3];
|
||||
c.n8[1] = n[2];
|
||||
@ -216,7 +219,7 @@ std::string Unicode::UTF8ToText(const std::string &src, bool *errors)
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string Unicode::UCS2ToUTF8(const std::string &src, bool *errors)
|
||||
std::string Unicode::UCS2ToUTF8(const std::string_view &src, bool *errors)
|
||||
{
|
||||
// default to success
|
||||
resetError(errors);
|
||||
@ -563,29 +566,29 @@ uint32_t Unicode::fromUTF8(const uint8_t *&data, uint32_t &n)
|
||||
break;
|
||||
|
||||
case 2:
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x1f) << 6) | ((static_cast<uint32_t>(data[1]) & 0x3f));
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x1f) << 6) | (static_cast<uint32_t>(data[1]) & 0x3f);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x0f) << 12) | ((static_cast<uint32_t>(data[1]) & 0x3f) << 6) |
|
||||
((static_cast<uint32_t>(data[2]) & 0x3f));
|
||||
(static_cast<uint32_t>(data[2]) & 0x3f);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x07) << 18) | ((static_cast<uint32_t>(data[1]) & 0x3f) << 12) |
|
||||
((static_cast<uint32_t>(data[2]) & 0x3f) << 6) | ((static_cast<uint32_t>(data[3]) & 0x3f));
|
||||
((static_cast<uint32_t>(data[2]) & 0x3f) << 6) | (static_cast<uint32_t>(data[3]) & 0x3f);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x03) << 24) | ((static_cast<uint32_t>(data[1]) & 0x3f) << 18) |
|
||||
((static_cast<uint32_t>(data[2]) & 0x3f) << 12) | ((static_cast<uint32_t>(data[3]) & 0x3f) << 6) |
|
||||
((static_cast<uint32_t>(data[4]) & 0x3f));
|
||||
(static_cast<uint32_t>(data[4]) & 0x3f);
|
||||
break;
|
||||
|
||||
case 6:
|
||||
c = ((static_cast<uint32_t>(data[0]) & 0x01) << 30) | ((static_cast<uint32_t>(data[1]) & 0x3f) << 24) |
|
||||
((static_cast<uint32_t>(data[2]) & 0x3f) << 18) | ((static_cast<uint32_t>(data[3]) & 0x3f) << 12) |
|
||||
((static_cast<uint32_t>(data[4]) & 0x3f) << 6) | ((static_cast<uint32_t>(data[5]) & 0x3f));
|
||||
((static_cast<uint32_t>(data[4]) & 0x3f) << 6) | (static_cast<uint32_t>(data[5]) & 0x3f);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -630,6 +633,9 @@ uint32_t Unicode::fromUTF8(const uint8_t *&data, uint32_t &n)
|
||||
truncated = true;
|
||||
size = 1;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// update parameters
|
||||
|
||||
@ -74,7 +74,7 @@ public:
|
||||
Convert from UCS-2 to UTF-8. If errors is not nullptr then *errors is
|
||||
set to true iff any character could not be decoded.
|
||||
*/
|
||||
static std::string UCS2ToUTF8(const std::string &, bool *errors = nullptr);
|
||||
static std::string UCS2ToUTF8(const std::string_view &, bool *errors = nullptr);
|
||||
|
||||
//! Convert from UCS-4 to UTF-8
|
||||
/*!
|
||||
|
||||
@ -34,7 +34,7 @@ const char *XBase::what() const throw()
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
std::string XBase::format(const char * /*id*/, const char *fmt, ...) const throw()
|
||||
std::string XBase::format(const char * /*id*/, const char *fmt, ...) const noexcept
|
||||
{
|
||||
// FIXME -- lookup message string using id as an index. set
|
||||
// fmt to that string if it exists.
|
||||
|
||||
@ -28,7 +28,7 @@ public:
|
||||
|
||||
protected:
|
||||
//! Get a human readable string describing the exception
|
||||
virtual std::string getWhat() const throw()
|
||||
virtual std::string getWhat() const noexcept
|
||||
{
|
||||
return "";
|
||||
}
|
||||
@ -39,105 +39,8 @@ protected:
|
||||
no format can be found, then replaces positional parameters in
|
||||
the format string and returns the result.
|
||||
*/
|
||||
virtual std::string format(const char *id, const char *defaultFormat, ...) const throw();
|
||||
virtual std::string format(const char *id, const char *defaultFormat, ...) const noexcept;
|
||||
|
||||
private:
|
||||
mutable std::string m_what;
|
||||
};
|
||||
|
||||
/*!
|
||||
\def XBASE_SUBCLASS
|
||||
Convenience macro to subclass from XBase (or a subclass of it),
|
||||
providing the c'tor taking a const std::string&. getWhat() is not
|
||||
declared.
|
||||
*/
|
||||
#define XBASE_SUBCLASS(name_, super_) \
|
||||
class name_ : public super_ \
|
||||
{ \
|
||||
public: \
|
||||
name_() : super_() \
|
||||
{ \
|
||||
} \
|
||||
name_(const std::string &msg) : super_(msg) \
|
||||
{ \
|
||||
} \
|
||||
virtual ~name_() throw() \
|
||||
{ \
|
||||
} \
|
||||
}
|
||||
|
||||
/*!
|
||||
\def XBASE_SUBCLASS
|
||||
Convenience macro to subclass from XBase (or a subclass of it),
|
||||
providing the c'tor taking a const std::string&. getWhat() must be
|
||||
implemented.
|
||||
*/
|
||||
#define XBASE_SUBCLASS_WHAT(name_, super_) \
|
||||
class name_ : public super_ \
|
||||
{ \
|
||||
public: \
|
||||
name_() : super_() \
|
||||
{ \
|
||||
} \
|
||||
name_(const std::string &msg) : super_(msg) \
|
||||
{ \
|
||||
} \
|
||||
virtual ~name_() throw() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual std::string getWhat() const throw(); \
|
||||
}
|
||||
|
||||
/*!
|
||||
\def XBASE_SUBCLASS_FORMAT
|
||||
Convenience macro to subclass from XBase (or a subclass of it),
|
||||
providing the c'tor taking a const std::string&. what() is overridden
|
||||
to call getWhat() when first called; getWhat() can format the
|
||||
error message and can call what() to get the message passed to the
|
||||
c'tor.
|
||||
*/
|
||||
#define XBASE_SUBCLASS_FORMAT(name_, super_) \
|
||||
class name_ : public super_ \
|
||||
{ \
|
||||
private: \
|
||||
enum EState \
|
||||
{ \
|
||||
kFirst, \
|
||||
kFormat, \
|
||||
kDone \
|
||||
}; \
|
||||
\
|
||||
public: \
|
||||
name_() : super_(), m_state(kDone) \
|
||||
{ \
|
||||
} \
|
||||
name_(const std::string &msg) : super_(msg), m_state(kFirst) \
|
||||
{ \
|
||||
} \
|
||||
virtual ~name_() throw() \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
virtual const char *what() const throw() \
|
||||
{ \
|
||||
if (m_state == kFirst) { \
|
||||
m_state = kFormat; \
|
||||
m_formatted = getWhat(); \
|
||||
m_state = kDone; \
|
||||
} \
|
||||
if (m_state == kDone) { \
|
||||
return m_formatted.c_str(); \
|
||||
} else { \
|
||||
return super_::what(); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
protected: \
|
||||
virtual std::string getWhat() const throw(); \
|
||||
\
|
||||
private: \
|
||||
mutable EState m_state; \
|
||||
mutable std::string m_formatted; \
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
#include "arch/Arch.h"
|
||||
#include "base/IEventQueue.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/TMethodEventJob.h"
|
||||
#include "base/TMethodJob.h"
|
||||
#include "client/ServerProxy.h"
|
||||
#include "deskflow/AppUtil.h"
|
||||
@ -60,12 +59,8 @@ Client::Client(
|
||||
assert(m_screen != nullptr);
|
||||
|
||||
// register suspend/resume event handlers
|
||||
m_events->adoptHandler(
|
||||
EventTypes::ScreenSuspend, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleSuspend)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::ScreenResume, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleResume)
|
||||
);
|
||||
m_events->addHandler(EventTypes::ScreenSuspend, getEventTarget(), [this](const auto &) { handleSuspend(); });
|
||||
m_events->addHandler(EventTypes::ScreenResume, getEventTarget(), [this](const auto &) { handleResume(); });
|
||||
|
||||
m_pHelloBack = std::make_unique<HelloBack>(std::make_shared<HelloBack::Deps>(
|
||||
[this]() {
|
||||
@ -162,7 +157,7 @@ void Client::refuseConnection(const char *msg)
|
||||
if (msg) {
|
||||
auto info = new FailInfo(msg);
|
||||
info->m_retry = true;
|
||||
Event event(EventTypes::ClientConnectionRefused, getEventTarget(), info, Event::kDontFreeData);
|
||||
Event event(EventTypes::ClientConnectionRefused, getEventTarget(), info, Event::EventFlags::DontFreeData);
|
||||
m_events->addEvent(event);
|
||||
}
|
||||
}
|
||||
@ -386,7 +381,7 @@ void Client::sendConnectionFailedEvent(const char *msg)
|
||||
{
|
||||
auto *info = new FailInfo(msg);
|
||||
info->m_retry = true;
|
||||
Event event(EventTypes::ClientConnectionFailed, getEventTarget(), info, Event::kDontFreeData);
|
||||
Event event(EventTypes::ClientConnectionFailed, getEventTarget(), info, Event::EventFlags::DontFreeData);
|
||||
m_events->addEvent(event);
|
||||
}
|
||||
|
||||
@ -395,51 +390,41 @@ void Client::setupConnecting()
|
||||
assert(m_stream != nullptr);
|
||||
|
||||
if (m_args.m_enableCrypto) {
|
||||
m_events->adoptHandler(
|
||||
EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
||||
);
|
||||
m_events->addHandler(EventTypes::DataSocketSecureConnected, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleConnected();
|
||||
});
|
||||
} else {
|
||||
m_events->adoptHandler(
|
||||
EventTypes::DataSocketConnected, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnected)
|
||||
);
|
||||
m_events->addHandler(EventTypes::DataSocketConnected, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleConnected();
|
||||
});
|
||||
}
|
||||
|
||||
m_events->adoptHandler(
|
||||
EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleConnectionFailed)
|
||||
);
|
||||
m_events->addHandler(EventTypes::DataSocketConnectionFailed, m_stream->getEventTarget(), [this](const auto &e) {
|
||||
handleConnectionFailed(e);
|
||||
});
|
||||
}
|
||||
|
||||
void Client::setupConnection()
|
||||
{
|
||||
assert(m_stream != nullptr);
|
||||
|
||||
m_events->adoptHandler(
|
||||
EventTypes::SocketDisconnected, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::StreamInputReady, m_stream->getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleHello)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::StreamOutputError, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleOutputError)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::StreamInputShutdown, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::StreamOutputShutdown, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleDisconnected)
|
||||
);
|
||||
|
||||
m_events->adoptHandler(
|
||||
EventTypes::SocketStopRetry, m_stream->getEventTarget(),
|
||||
new TMethodEventJob<Client>(this, &Client::handleStopRetry)
|
||||
);
|
||||
m_events->addHandler(EventTypes::SocketDisconnected, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleDisconnected();
|
||||
});
|
||||
m_events->addHandler(EventTypes::StreamInputReady, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleHello();
|
||||
});
|
||||
m_events->addHandler(EventTypes::StreamOutputError, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleOutputError();
|
||||
});
|
||||
m_events->addHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleDisconnected();
|
||||
});
|
||||
m_events->addHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget(), [this](const auto &) {
|
||||
handleDisconnected();
|
||||
});
|
||||
m_events->addHandler(EventTypes::SocketStopRetry, m_stream->getEventTarget(), [this](const auto &) {
|
||||
m_args.m_restartable = false;
|
||||
});
|
||||
}
|
||||
|
||||
void Client::setupScreen()
|
||||
@ -448,19 +433,19 @@ void Client::setupScreen()
|
||||
|
||||
m_ready = false;
|
||||
m_server = new ServerProxy(this, m_stream, m_events);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::ScreenShapeChanged, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleShapeChanged)
|
||||
);
|
||||
m_events->adoptHandler(
|
||||
EventTypes::ClipboardGrabbed, getEventTarget(), new TMethodEventJob<Client>(this, &Client::handleClipboardGrabbed)
|
||||
);
|
||||
m_events->addHandler(EventTypes::ScreenShapeChanged, getEventTarget(), [this](const auto &) {
|
||||
handleShapeChanged();
|
||||
});
|
||||
m_events->addHandler(EventTypes::ClipboardGrabbed, getEventTarget(), [this](const auto &e) {
|
||||
handleClipboardGrabbed(e);
|
||||
});
|
||||
}
|
||||
|
||||
void Client::setupTimer()
|
||||
{
|
||||
assert(m_timer == nullptr);
|
||||
m_timer = m_events->newOneShotTimer(2.0, nullptr);
|
||||
m_events->adoptHandler(EventTypes::Timer, m_timer, new TMethodEventJob<Client>(this, &Client::handleConnectTimeout));
|
||||
m_events->addHandler(EventTypes::Timer, m_timer, [this](const auto &) { handleConnectTimeout(); });
|
||||
}
|
||||
|
||||
void Client::cleanup()
|
||||
@ -483,12 +468,13 @@ void Client::cleanupConnecting()
|
||||
void Client::cleanupConnection()
|
||||
{
|
||||
if (m_stream != nullptr) {
|
||||
m_events->removeHandler(EventTypes::StreamInputReady, m_stream->getEventTarget());
|
||||
m_events->removeHandler(EventTypes::StreamOutputError, m_stream->getEventTarget());
|
||||
m_events->removeHandler(EventTypes::StreamInputShutdown, m_stream->getEventTarget());
|
||||
m_events->removeHandler(EventTypes::StreamOutputShutdown, m_stream->getEventTarget());
|
||||
m_events->removeHandler(EventTypes::SocketDisconnected, m_stream->getEventTarget());
|
||||
m_events->removeHandler(EventTypes::SocketStopRetry, m_stream->getEventTarget());
|
||||
using enum EventTypes;
|
||||
m_events->removeHandler(StreamInputReady, m_stream->getEventTarget());
|
||||
m_events->removeHandler(StreamOutputError, m_stream->getEventTarget());
|
||||
m_events->removeHandler(StreamInputShutdown, m_stream->getEventTarget());
|
||||
m_events->removeHandler(StreamOutputShutdown, m_stream->getEventTarget());
|
||||
m_events->removeHandler(SocketDisconnected, m_stream->getEventTarget());
|
||||
m_events->removeHandler(SocketStopRetry, m_stream->getEventTarget());
|
||||
cleanupStream();
|
||||
}
|
||||
}
|
||||
@ -522,7 +508,7 @@ void Client::cleanupStream()
|
||||
m_stream = nullptr;
|
||||
}
|
||||
|
||||
void Client::handleConnected(const Event &, void *)
|
||||
void Client::handleConnected()
|
||||
{
|
||||
LOG((CLOG_DEBUG1 "connected, waiting for hello"));
|
||||
cleanupConnecting();
|
||||
@ -536,7 +522,7 @@ void Client::handleConnected(const Event &, void *)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleConnectionFailed(const Event &event, void *)
|
||||
void Client::handleConnectionFailed(const Event &event)
|
||||
{
|
||||
auto *info = static_cast<IDataSocket::ConnectionFailedInfo *>(event.getData());
|
||||
|
||||
@ -548,7 +534,7 @@ void Client::handleConnectionFailed(const Event &event, void *)
|
||||
delete info;
|
||||
}
|
||||
|
||||
void Client::handleConnectTimeout(const Event &, void *)
|
||||
void Client::handleConnectTimeout()
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupConnecting();
|
||||
@ -558,7 +544,7 @@ void Client::handleConnectTimeout(const Event &, void *)
|
||||
sendConnectionFailedEvent("Timed out");
|
||||
}
|
||||
|
||||
void Client::handleOutputError(const Event &, void *)
|
||||
void Client::handleOutputError()
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupScreen();
|
||||
@ -567,7 +553,7 @@ void Client::handleOutputError(const Event &, void *)
|
||||
sendEvent(EventTypes::ClientDisconnected, nullptr);
|
||||
}
|
||||
|
||||
void Client::handleDisconnected(const Event &, void *)
|
||||
void Client::handleDisconnected()
|
||||
{
|
||||
cleanupTimer();
|
||||
cleanupScreen();
|
||||
@ -576,13 +562,13 @@ void Client::handleDisconnected(const Event &, void *)
|
||||
sendEvent(EventTypes::ClientDisconnected, nullptr);
|
||||
}
|
||||
|
||||
void Client::handleShapeChanged(const Event &, void *)
|
||||
void Client::handleShapeChanged()
|
||||
{
|
||||
LOG((CLOG_DEBUG "resolution changed"));
|
||||
m_server->onInfoChanged();
|
||||
}
|
||||
|
||||
void Client::handleClipboardGrabbed(const Event &event, void *)
|
||||
void Client::handleClipboardGrabbed(const Event &event)
|
||||
{
|
||||
if (!m_enableClipboard || (m_maximumClipboardSize == 0)) {
|
||||
return;
|
||||
@ -605,7 +591,7 @@ void Client::handleClipboardGrabbed(const Event &event, void *)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleHello(const Event &, void *)
|
||||
void Client::handleHello()
|
||||
{
|
||||
m_pHelloBack->handleHello(m_stream, m_name);
|
||||
|
||||
@ -621,7 +607,7 @@ void Client::handleHello(const Event &, void *)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleSuspend(const Event &, void *)
|
||||
void Client::handleSuspend()
|
||||
{
|
||||
if (!m_suspended) {
|
||||
LOG((CLOG_INFO "suspend"));
|
||||
@ -632,7 +618,7 @@ void Client::handleSuspend(const Event &, void *)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleResume(const Event &, void *)
|
||||
void Client::handleResume()
|
||||
{
|
||||
if (m_suspended) {
|
||||
LOG((CLOG_INFO "resume"));
|
||||
@ -660,8 +646,3 @@ void Client::bindNetworkInterface(IDataSocket *socket) const
|
||||
LOG((CLOG_WARN "operating system will select network interface automatically"));
|
||||
}
|
||||
}
|
||||
|
||||
void Client::handleStopRetry(const Event &, void *)
|
||||
{
|
||||
m_args.m_restartable = false;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
||||
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
@ -168,17 +169,16 @@ private:
|
||||
void cleanupScreen();
|
||||
void cleanupTimer();
|
||||
void cleanupStream();
|
||||
void handleConnected(const Event &, void *);
|
||||
void handleConnectionFailed(const Event &, void *);
|
||||
void handleConnectTimeout(const Event &, void *);
|
||||
void handleOutputError(const Event &, void *);
|
||||
void handleDisconnected(const Event &, void *);
|
||||
void handleShapeChanged(const Event &, void *);
|
||||
void handleClipboardGrabbed(const Event &, void *);
|
||||
void handleHello(const Event &, void *);
|
||||
void handleSuspend(const Event &event, void *);
|
||||
void handleResume(const Event &event, void *);
|
||||
void handleStopRetry(const Event &, void *);
|
||||
void handleConnected();
|
||||
void handleConnectionFailed(const Event &event);
|
||||
void handleConnectTimeout();
|
||||
void handleOutputError();
|
||||
void handleDisconnected();
|
||||
void handleShapeChanged();
|
||||
void handleClipboardGrabbed(const Event &event);
|
||||
void handleHello();
|
||||
void handleSuspend();
|
||||
void handleResume();
|
||||
void sendClipboardThread(void *);
|
||||
void bindNetworkInterface(IDataSocket *socket) const;
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ bool HelloBack::shouldDowngrade(int major, int minor) const
|
||||
auto versions = map.find(minor);
|
||||
if (versions != map.end()) {
|
||||
auto compatibleVersions = versions->second;
|
||||
if (compatibleVersions.find(m_minorVersion) != compatibleVersions.end()) {
|
||||
if (compatibleVersions.contains(m_minorVersion)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user