deskflow/src/lib/platform/MSWindowsWatchdog.h

100 lines
2.5 KiB
C
Raw Normal View History

2012-06-10 16:50:54 +00:00
/*
* Deskflow -- mouse and keyboard sharing utility
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
* SPDX-FileCopyrightText: (C) 2009 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
#include "arch/IArchMultithread.h"
#include "deskflow/XDeskflow.h"
#include "platform/MSWindowsProcess.h"
#include "platform/MSWindowsSession.h"
2012-06-10 16:50:54 +00:00
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <memory>
#include <string>
2014-11-11 13:51:47 +00:00
class Thread;
class IpcLogOutputter;
class IpcServer;
class FileLogOutputter;
2012-06-10 16:50:54 +00:00
class MSWindowsWatchdog
{
2012-06-10 16:50:54 +00:00
public:
MSWindowsWatchdog(bool autoDetectCommand, IpcServer &ipcServer, IpcLogOutputter &ipcLogOutputter, bool foreground);
virtual ~MSWindowsWatchdog();
void startAsync();
std::string getCommand() const;
void setCommand(const std::string &command, bool elevate);
void stop();
bool isProcessRunning();
void setFileLogOutputter(FileLogOutputter *outputter);
2012-06-10 16:50:54 +00:00
private:
void mainLoop(void *);
void outputLoop(void *);
void shutdownExistingProcesses();
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security, bool elevatedToken);
void startProcess();
void sendSas();
void setStartupInfo(STARTUPINFO &si);
/**
* @brief Re-run the process to get the active desktop name.
*
* It is necessary to run a utility process because the daemon runs in session 0, which does not
* have access to the active desktop, and so cannot query it's name.
*
* @return std::string The name of the active desktop.
*/
std::string runActiveDesktopUtility();
2012-06-10 16:50:54 +00:00
private:
Thread *m_thread;
bool m_autoDetectCommand;
std::string m_command;
bool m_monitoring;
bool m_commandChanged;
HANDLE m_outputWritePipe;
HANDLE m_outputReadPipe;
Thread *m_outputThread;
IpcServer &m_ipcServer;
IpcLogOutputter &m_ipcLogOutputter;
bool m_elevateProcess;
MSWindowsSession m_session;
int m_processFailures;
bool m_processStarted;
FileLogOutputter *m_fileLogOutputter;
ArchMutex m_mutex;
ArchCond m_condVar;
bool m_ready;
bool m_foreground;
std::string m_activeDesktop;
std::unique_ptr<deskflow::platform::MSWindowsProcess> m_process;
};
//! Relauncher error
/*!
An error occured in the process watchdog.
*/
class XMSWindowsWatchdogError : public XDeskflow
{
public:
XMSWindowsWatchdogError(const std::string &msg) : XDeskflow(msg)
{
}
// XBase overrides
virtual std::string getWhat() const throw()
{
return what();
}
2012-06-10 16:50:54 +00:00
};