From 920507bff803647c79dfce27c4c265b2caee7f8d Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Thu, 27 Jun 2024 21:04:53 +0000
Subject: [PATCH] some refactor, addedd google loggin', corrected plugin handling

---
 src/IPC.cpp |   44 ++++++++++++++++++++++++++++++++------------
 1 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/src/IPC.cpp b/src/IPC.cpp
index 0a90a17..f1ac09b 100644
--- a/src/IPC.cpp
+++ b/src/IPC.cpp
@@ -1,27 +1,47 @@
 #include "IPC.h"
+#include <iostream>
 
-IPC::IPC() {}
+IPC::IPC()
+{
+    DLOG(INFO) << "IPC ready.. queue size at init: " << messageQueue.size();
+}
 
-void IPC::registerHandler(std::shared_ptr<IPlugin> handler) {
+IPC::~IPC()
+{
+    while (!messageQueue.empty())
+    {
+        messageQueue.pop();
+    }
+}
+
+void IPC::registerHandler(std::shared_ptr<IPlugin> handler)
+{
     handlers.push_back(handler);
 }
 
-void IPC::sendMessage(const Command& cmd) {
-    {
-        std::lock_guard<std::mutex> lock(queueMutex);
-        messageQueue.push(cmd);
-    }
+void IPC::sendMessage(const Command &cmd)
+{
+    std::lock_guard lock(queueMutex);
+    std::string val;
+    tser::Serialize(cmd, val);
+    messageQueue.push(std::move(val));
     queueCondVar.notify_one();
 }
 
-std::optional<Command> IPC::receiveMessage() {
+std::optional<Command> IPC::receiveMessage()
+{
     std::unique_lock<std::mutex> lock(queueMutex);
-    queueCondVar.wait(lock, [this] { return !messageQueue.empty(); });
+    queueCondVar.wait(lock, [this]
+                      { return !messageQueue.empty(); });
 
-    if (!messageQueue.empty()) {
-        Command cmd = messageQueue.front();
+    if (!messageQueue.empty())
+    {
+        std::string a = std::move(messageQueue.front());
         messageQueue.pop();
-        return cmd;
+
+        Command c;
+        tser::DeSerialize(a, c);
+        return c;
     }
     return std::nullopt;
 }

--
Gitblit v1.9.3