Deskflow 1.26.0.207
Keyboard and mouse sharing utility
Loading...
Searching...
No Matches
IpcClient.h
Go to the documentation of this file.
1/*
2 * Deskflow -- mouse and keyboard sharing utility
3 * SPDX-FileCopyrightText: (C) 2025-2026 Symless Ltd.
4 * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
5 */
6
7#pragma once
8
9#include <QObject>
10
11class QLocalSocket;
12
13namespace deskflow::gui::ipc {
14
15class IpcClient : public QObject
16{
17 Q_OBJECT
18
19 // Represents underlying socket state and whether the server responded to the hello message.
20 enum class State
21 {
22 Unconnected,
23 Connecting,
24 Connected,
25 Disconnecting,
26 };
27
28public:
29 explicit IpcClient(QObject *parent, const QString &socketName, const QString &typeName);
30 void connectToServer();
32
33 bool isConnected() const
34 {
35 return m_state == State::Connected;
36 }
37
38Q_SIGNALS:
39 void connected();
43
44private Q_SLOTS:
45 void handleDisconnected();
46 void handleErrorOccurred();
47 void handleReadyRead();
48
49protected:
50 virtual void processCommand(const QString &command, const QStringList &parts)
51 {
52 Q_UNUSED(command)
53 Q_UNUSED(parts)
54 }
55
56 void sendMessage(const QString &message);
57
58private:
59 void attemptConnection();
60 void handleHandshakeMessage(const QStringList &parts);
61
62 QLocalSocket *m_socket;
63 State m_state{State::Unconnected};
64 QString m_socketName;
65 QByteArray m_readBuffer;
66 int m_retryCount{0};
67 QString m_typeName;
68};
69
70} // namespace deskflow::gui::ipc
bool isConnected() const
Definition IpcClient.h:33
void connectToServer()
Definition IpcClient.cpp:28
IpcClient(QObject *parent, const QString &socketName, const QString &typeName)
Definition IpcClient.cpp:17
void disconnectFromServer()
Definition IpcClient.cpp:95
virtual void processCommand(const QString &command, const QStringList &parts)
Definition IpcClient.h:50
void sendMessage(const QString &message)
Definition IpcClient.cpp:206
Definition CoreProcess.h:22