2021-02-02 01:47:40 +03:00
|
|
|
#ifndef IPCCLIENT_H
|
|
|
|
|
#define IPCCLIENT_H
|
|
|
|
|
|
2021-02-03 15:42:36 +03:00
|
|
|
#include <QLocalSocket>
|
2021-02-02 01:47:40 +03:00
|
|
|
#include <QObject>
|
|
|
|
|
|
2021-09-15 08:03:28 -07:00
|
|
|
#include "rep_ipc_interface_replica.h"
|
2026-02-11 16:47:28 +01:00
|
|
|
#include "rep_ipc_process_interface_replica.h"
|
2021-02-02 01:47:40 +03:00
|
|
|
|
|
|
|
|
class IpcClient : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2025-12-19 04:09:50 +01:00
|
|
|
explicit IpcClient(QObject *parent = nullptr);
|
2021-10-26 12:59:20 +03:00
|
|
|
|
2025-12-19 15:44:42 +01:00
|
|
|
static IpcClient& Instance();
|
2021-02-02 01:47:40 +03:00
|
|
|
|
2025-12-19 04:09:50 +01:00
|
|
|
static QSharedPointer<IpcInterfaceReplica> Interface();
|
2026-02-11 16:47:28 +01:00
|
|
|
static QSharedPointer<IpcProcessInterfaceReplica> CreatePrivilegedProcess();
|
2025-12-19 04:09:50 +01:00
|
|
|
|
|
|
|
|
template <typename Func>
|
|
|
|
|
static auto withInterface(Func func)
|
|
|
|
|
{
|
2025-12-19 15:44:42 +01:00
|
|
|
QSharedPointer<IpcInterfaceReplica> iface = Instance().m_interface;
|
2025-12-19 04:09:50 +01:00
|
|
|
using ReturnType = decltype(func(std::declval<QSharedPointer<IpcInterfaceReplica>>()));
|
|
|
|
|
|
2025-12-19 15:44:42 +01:00
|
|
|
if (iface.isNull() || !iface->waitForSource(1000) || !iface->isReplicaValid()) {
|
2025-12-19 04:09:50 +01:00
|
|
|
qWarning() << "IpcClient::withInterface(): Service is not running";
|
|
|
|
|
|
|
|
|
|
if constexpr (std::is_void_v<ReturnType>)
|
|
|
|
|
return;
|
|
|
|
|
else
|
|
|
|
|
return ReturnType{};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return func(iface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename OnSuccess, typename OnFailure>
|
|
|
|
|
static auto withInterface(OnSuccess onSuccess, OnFailure onFailure)
|
|
|
|
|
{
|
2025-12-19 15:44:42 +01:00
|
|
|
QSharedPointer<IpcInterfaceReplica> iface = Instance().m_interface;
|
|
|
|
|
if (iface.isNull() || !iface->waitForSource(1000) || !iface->isReplicaValid()) {
|
2025-12-19 04:09:50 +01:00
|
|
|
return onFailure();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return onSuccess(iface);
|
|
|
|
|
}
|
2021-02-02 01:47:40 +03:00
|
|
|
signals:
|
|
|
|
|
|
|
|
|
|
private:
|
2025-12-19 15:44:42 +01:00
|
|
|
QRemoteObjectNode m_node;
|
|
|
|
|
QSharedPointer<IpcInterfaceReplica> m_interface;
|
2021-02-02 01:47:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // IPCCLIENT_H
|