deskflow/src/lib/client/ServerProxy.h

133 lines
3.2 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) 2002 Chris Schoeneman
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
2012-06-10 16:50:54 +00:00
*/
#pragma once
2012-06-10 16:50:54 +00:00
#include "base/Event.h"
#include "base/Stopwatch.h"
#include "deskflow/ClipboardTypes.h"
#include "deskflow/KeyTypes.h"
#include "deskflow/languages/LanguageManager.h"
2012-06-10 16:50:54 +00:00
2014-11-11 13:51:47 +00:00
class Client;
class ClientInfo;
class EventQueueTimer;
2012-06-10 16:50:54 +00:00
class IClipboard;
namespace deskflow {
class IStream;
}
2012-06-10 16:50:54 +00:00
class IEventQueue;
//! Proxy for server
/*!
This class acts a proxy for the server, converting calls into messages
to the server and messages from the server to calls on the client.
*/
class ServerProxy
{
2012-06-10 16:50:54 +00:00
public:
/*!
Process messages from the server on \p stream and forward to
\p client.
*/
ServerProxy(Client *client, deskflow::IStream *stream, IEventQueue *events);
ServerProxy(ServerProxy const &) = delete;
ServerProxy(ServerProxy &&) = delete;
~ServerProxy();
ServerProxy &operator=(ServerProxy const &) = delete;
ServerProxy &operator=(ServerProxy &&) = delete;
2012-06-10 16:50:54 +00:00
//! @name manipulators
//@{
2020-11-03 10:52:56 +00:00
void onInfoChanged();
bool onGrabClipboard(ClipboardID);
void onClipboardChanged(ClipboardID, const IClipboard *);
2012-06-10 16:50:54 +00:00
//@}
2012-06-10 16:50:54 +00:00
protected:
enum EResult
{
kOkay,
kUnknown,
kDisconnect
};
2025-01-11 00:09:43 +00:00
EResult parseHandshakeMessage(const uint8_t *code);
EResult parseMessage(const uint8_t *code);
2012-06-10 16:50:54 +00:00
private:
// if compressing mouse motion then send the last motion now
void flushCompressedMouse();
void sendInfo(const ClientInfo &);
void resetKeepAliveAlarm();
void setKeepAliveRate(double);
// modifier key translation
KeyID translateKey(KeyID) const;
KeyModifierMask translateModifierMask(KeyModifierMask) const;
// event handlers
void handleData(const Event &, void *);
void handleKeepAliveAlarm(const Event &, void *);
// message handlers
void enter();
void leave();
void setClipboard();
void grabClipboard();
2025-01-11 00:58:26 +00:00
void keyDown(uint16_t id, uint16_t mask, uint16_t button, const std::string &lang);
void keyRepeat();
void keyUp();
void mouseDown();
void mouseUp();
void mouseMove();
void mouseRelativeMove();
void mouseWheel();
void screensaver();
void resetOptions();
void setOptions();
void queryInfo();
void infoAcknowledgment();
void handleClipboardSendingEvent(const Event &, void *);
void secureInputNotification();
void setServerLanguages();
void setActiveServerLanguage(const std::string &language);
void checkMissedLanguages() const;
2012-06-10 16:50:54 +00:00
private:
2025-05-20 00:00:31 +00:00
using MessageParser = EResult (ServerProxy::*)(const uint8_t *);
2012-06-10 16:50:54 +00:00
Client *m_client;
deskflow::IStream *m_stream;
2012-06-10 16:50:54 +00:00
2025-01-11 02:13:19 +00:00
uint32_t m_seqNum;
2012-06-10 16:50:54 +00:00
bool m_compressMouse;
bool m_compressMouseRelative;
int32_t m_xMouse;
int32_t m_yMouse;
int32_t m_dxMouse;
int32_t m_dyMouse;
2012-06-10 16:50:54 +00:00
bool m_ignoreMouse;
2012-06-10 16:50:54 +00:00
KeyModifierID m_modifierTranslationTable[kKeyModifierIDLast];
2012-06-10 16:50:54 +00:00
double m_keepAliveAlarm;
EventQueueTimer *m_keepAliveAlarmTimer;
2012-06-10 16:50:54 +00:00
MessageParser m_parser;
IEventQueue *m_events;
std::string m_serverLanguage = "";
bool m_isUserNotifiedAboutLanguageSyncError = false;
deskflow::languages::LanguageManager m_languageManager;
2012-06-10 16:50:54 +00:00
};