Deskflow 1.26.0.134
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();
41
42private Q_SLOTS:
43 void handleDisconnected();
44 void handleErrorOccurred();
45 void handleReadyRead();
46
47protected:
48 virtual void processCommand(const QString &command, const QStringList &parts)
49 {
50 Q_UNUSED(command)
51 Q_UNUSED(parts)
52 }
53
54 void sendMessage(const QString &message);
55
56private:
57 void attemptConnection();
58 void handleHandshakeMessage(const QStringList &parts);
59
60 QLocalSocket *m_socket;
61 State m_state{State::Unconnected};
62 QString m_socketName;
63 QByteArray m_readBuffer;
64 int m_retryCount{0};
65 QString m_typeName;
66};
67
68} // 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:48
void sendMessage(const QString &message)
Definition IpcClient.cpp:197
Definition CoreProcess.h:22