Deskflow
1.26.0.418
Keyboard and mouse sharing utility
Toggle main menu visibility
Loading...
Searching...
No Matches
MSWindowsWatchdog.h
Go to the documentation of this file.
1
/*
2
* Deskflow -- mouse and keyboard sharing utility
3
* SPDX-FileCopyrightText: (C) 2012 - 2025 Synergy App Ltd
4
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
5
*/
6
7
#pragma once
8
9
#include "
mt/Thread.h
"
10
#include "
platform/MSWindowsProcess.h
"
11
#include "
platform/MSWindowsSession.h
"
12
13
#define WIN32_LEAN_AND_MEAN
14
#include <Windows.h>
15
16
#include <memory>
17
#include <mutex>
18
#include <optional>
19
#include <string>
20
21
typedef
VOID(WINAPI *
SendSas
)(
BOOL
asUser);
22
23
class
FileLogOutputter
;
24
28
class
MSWindowsWatchdog
29
{
30
enum class
ProcessState
31
{
32
Idle,
33
StartScheduled,
34
StartPending,
35
StopPending,
36
Running
37
};
38
39
public
:
40
explicit
MSWindowsWatchdog
(
bool
foreground,
FileLogOutputter
&fileLogOutputter);
41
~MSWindowsWatchdog
() =
default
;
42
46
void
startAsync
();
47
51
void
setProcessConfig
(
const
std::string_view &command,
bool
elevate);
52
56
void
stop
();
57
61
bool
isProcessRunning
();
62
63
private
:
67
void
mainLoop(
const
void
*);
68
72
void
outputLoop(
const
void
*);
73
83
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
84
92
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security,
bool
elevatedToken);
93
97
void
startProcess();
98
102
ProcessState handleStartError(
const
std::string_view &message =
""
);
103
107
void
initOutputReadPipe();
108
112
void
initSasFunc();
113
119
void
sasLoop(
const
void
*);
120
124
static
std::string processStateToString(ProcessState state);
125
129
static
void
shutdownExistingProcesses();
130
131
private
:
132
bool
m_running =
true
;
133
std::unique_ptr<Thread> m_mainThread;
134
std::unique_ptr<Thread> m_outputThread;
135
std::unique_ptr<Thread> m_sasThread;
136
HANDLE m_outputWritePipe =
nullptr
;
137
HANDLE m_outputReadPipe =
nullptr
;
138
bool
m_elevateProcess =
false
;
139
MSWindowsSession
m_session;
140
int
m_startFailures = 0;
141
FileLogOutputter
&m_fileLogOutputter;
142
bool
m_foreground =
false
;
143
std::wstring m_activeDesktop = {};
144
std::unique_ptr<deskflow::platform::MSWindowsProcess> m_process;
145
std::optional<double> m_nextStartTime = std::nullopt;
146
ProcessState
m_processState = ProcessState::Idle;
147
std::wstring m_command = {};
148
SendSas
m_sendSasFunc =
nullptr
;
149
std::mutex m_processStateMutex;
150
};
BOOL
static const WSAEVENT FAR BOOL
Definition
ArchNetworkWinsock.cpp:56
MSWindowsProcess.h
MSWindowsSession.h
SendSas
VOID(WINAPI *) SendSas(BOOL asUser)
Definition
MSWindowsWatchdog.h:21
ProcessState
deskflow::core::ProcessState ProcessState
Definition
StatusBar.h:16
Thread.h
FileLogOutputter
Write log to file.
Definition
LogOutputters.h:57
MSWindowsSession
Definition
MSWindowsSession.h:15
MSWindowsWatchdog::isProcessRunning
bool isProcessRunning()
Definition
MSWindowsWatchdog.cpp:252
MSWindowsWatchdog::MSWindowsWatchdog
MSWindowsWatchdog(bool foreground, FileLogOutputter &fileLogOutputter)
Definition
MSWindowsWatchdog.cpp:69
MSWindowsWatchdog::startAsync
void startAsync()
Start threads for main loop and and output loop.
Definition
MSWindowsWatchdog.cpp:77
MSWindowsWatchdog::setProcessConfig
void setProcessConfig(const std::string_view &command, bool elevate)
Set the command to run and whether to elevate the process.
Definition
MSWindowsWatchdog.cpp:323
MSWindowsWatchdog::~MSWindowsWatchdog
~MSWindowsWatchdog()=default
MSWindowsWatchdog::stop
void stop()
Stop the main loop and output loop threads.
Definition
MSWindowsWatchdog.cpp:84
src
lib
platform
MSWindowsWatchdog.h
Generated by
1.18.0