aboutsummaryrefslogtreecommitdiffstats
path: root/src/ProxyService.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/ProxyService.h')
-rw-r--r--src/ProxyService.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/ProxyService.h b/src/ProxyService.h
new file mode 100644
index 0000000..8e2cf66
--- /dev/null
+++ b/src/ProxyService.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2022,2023 Konsulko Group
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#ifndef _PROXY_SERVICE_H
+#define _PROXY_SERVICE_H
+
+#include <mutex>
+#include <glib.h>
+
+#include "KuksaConfig.h"
+#include "KuksaClient.h"
+#include "MqttConfig.h"
+#include "MqttClient.h"
+#include "SignalUpdateHandlers.h"
+
+class ProxyService
+{
+public:
+ ProxyService(const KuksaConfig &config,
+ const MqttConfig &mqttConfig,
+ const SignalUpdateHandlers &signalUpdateHandlers,
+ GMainLoop *loop = NULL);
+
+ ~ProxyService();
+
+ bool start();
+
+ // Callback for KuksaClient subscribe API reconnect
+ static gboolean resubscribe_cb(gpointer data) {
+ struct resubscribe_data *d = (struct resubscribe_data*) data;
+ if (d && d->self) {
+ ((ProxyService*) d->self)->Resubscribe(d->request);
+ }
+ return FALSE;
+ }
+
+private:
+ struct resubscribe_data {
+ ProxyService *self;
+ const SubscribeRequest *request;
+ };
+
+ GMainLoop *m_loop;
+ KuksaConfig m_kuksaConfig;
+ KuksaClient *m_kuksaClient;
+ MqttConfig m_mqttConfig;
+ MqttClient *m_mqttClient;
+ SignalUpdateHandlers m_signalUpdateHandlers;
+
+ void HandleSignalChange(const std::string &path, const Datapoint &dp);
+
+ void HandleSignalSetError(const std::string &path, const Error &error);
+
+ void HandleSubscribeDone(const SubscribeRequest *request, const Status &status);
+
+ void Resubscribe(const SubscribeRequest *request);
+};
+
+#endif // _PROXY_SERVICE_H