From a27ecb70699f6f48cd4ad75a1b643b6d1083af97 Mon Sep 17 00:00:00 2001
From: Dynamic Readme
Date: Fri, 10 Sep 2021 20:59:58 +0000
Subject: [PATCH 001/147] =?UTF-8?q?=F0=9F=92=AC=20-=20File=20Rebuilt=20|?=
=?UTF-8?q?=20Github=20Action=20Runner=20:=202?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 28 ++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)
diff --git a/README.md b/README.md
index 7725d8e..65f9ac5 100644
--- a/README.md
+++ b/README.md
@@ -8,26 +8,26 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
From f10d55eb46c782d5ddc0da70818c2602fb14baa0 Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Sat, 11 Sep 2021 20:40:14 -0300
Subject: [PATCH 002/147] Adding the Routine interface to the routine.cpp and
routine.hpp archives
---
src/classes/routine/routine.cpp | 10 ++++++++++
src/classes/routine/routine.hpp | 26 ++++++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/src/classes/routine/routine.cpp b/src/classes/routine/routine.cpp
index e69de29..83c6aef 100644
--- a/src/classes/routine/routine.cpp
+++ b/src/classes/routine/routine.cpp
@@ -0,0 +1,10 @@
+/*
+* service.cpp
+*
+* Author: Carlos Craveiro (@CarlosCraveiro)
+* Created On: September 11, 2021
+*
+*/
+
+#include "routine.hpp"
+
diff --git a/src/classes/routine/routine.hpp b/src/classes/routine/routine.hpp
index e69de29..7d53db2 100644
--- a/src/classes/routine/routine.hpp
+++ b/src/classes/routine/routine.hpp
@@ -0,0 +1,26 @@
+/*
+* routine.hpp
+*
+* Author: Carlos Craveiro (@CarlosCraveiro)
+* Created On: September 11, 2021
+*
+*/
+
+#pragma once
+
+typedef enum state_t {
+ MISSINGDEPENDENCIES = 0, UNINITIALIZED, INITIALIZED, RUNNING, STOPED, DEAD
+
+};
+
+class IRoutine {
+ public:
+ std::string id;
+ public:
+ virtual void onLoad()=0;
+ virtual void loop()=0;
+ virtual void unload()=0;
+ IRoutine(std::string id): id{id} {}
+ ~IRoutine(void){};
+};
+
From 7c0d8c505d02fc69192a737401f51ca1bf64221b Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Sat, 11 Sep 2021 20:44:25 -0300
Subject: [PATCH 003/147] Fixing compiling problems with routine.hpp
---
src/classes/routine/routine.hpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/classes/routine/routine.hpp b/src/classes/routine/routine.hpp
index 7d53db2..394246b 100644
--- a/src/classes/routine/routine.hpp
+++ b/src/classes/routine/routine.hpp
@@ -7,11 +7,12 @@
*/
#pragma once
+#include
-typedef enum state_t {
+typedef enum {
MISSINGDEPENDENCIES = 0, UNINITIALIZED, INITIALIZED, RUNNING, STOPED, DEAD
-};
+} stateT;
class IRoutine {
public:
From c1f7772efa04ccddf0944ae849a15ffb0464ba98 Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Sun, 12 Sep 2021 03:39:14 -0300
Subject: [PATCH 004/147] adding the routine-handler functionality
---
.../routine-handler/routine-handler.cpp | 68 +++++++++++++++++++
.../routine-handler/routine-handler.hpp | 30 ++++++++
src/classes/routine/routine.hpp | 12 +++-
3 files changed, 107 insertions(+), 3 deletions(-)
diff --git a/src/classes/routine-handler/routine-handler.cpp b/src/classes/routine-handler/routine-handler.cpp
index e69de29..eafc6a6 100644
--- a/src/classes/routine-handler/routine-handler.cpp
+++ b/src/classes/routine-handler/routine-handler.cpp
@@ -0,0 +1,68 @@
+/*
+* routine-handler.cpp
+*
+* Author: Carlos Craveiro (@CarlosCraveiro)
+* Created On: September 11, 2021
+*/
+
+#include "routine-handler.hpp"
+
+void routineModule(IRoutine& routine, Status& status) {
+ routine.onLoad();
+ status.mtx.lock();
+ status.state = Status::RUNNING;
+ status.mtx.unlock();
+ while(status.state == Status::STOPED){
+ status.mtx.unlock();
+ routine.loop();
+ status.mtx.lock();
+ }
+ status.mtx.unlock();
+}
+
+RoutineHandler::RoutineHandler(IRoutine& routine, nlohmann::json dependecies, nlohmann::json currentDependecies) {
+ (*this->routine) = routine;
+ this->status.mtx.lock();
+ this->status.state = Status::UNINITIALIZED;
+ this->status.mtx.unlock();
+ (*this->dependecies) = dependecies;
+ this->currentDependecies = currentDependecies;
+}
+
+RoutineHandler::~RoutineHandler() {
+ //DO NOTHING
+}
+
+void RoutineHandler::run(void) {
+ std::thread thread(routineModule, std::ref(*routine), std::ref(status));
+ status.mtx.lock();
+ status.state = Status::INITIALIZED;
+ status.mtx.unlock();
+ std::swap(thread, innerThread);
+}
+
+void RoutineHandler::stop(void) {
+ status.mtx.lock();
+ status.state = Status::STOPED;
+ status.mtx.unlock();
+ innerThread.join();
+ status.mtx.lock();
+ status.state = Status::DEAD;
+ status.mtx.unlock();
+}
+
+nlohmann::json RoutineHandler::getStatus(void) {
+ //DO NOTHING
+ nlohmann::json myjson;
+ myjson["pi"] = 3.14;
+ return myjson;
+
+}
+
+nlohmann::json RoutineHandler::update(nlohmann::json& updateList) {
+ //DO NOTHING
+ nlohmann::json myjson;
+ myjson["pi"] = 3.14;
+ return myjson;
+}
+
diff --git a/src/classes/routine-handler/routine-handler.hpp b/src/classes/routine-handler/routine-handler.hpp
index e69de29..f7fa92f 100644
--- a/src/classes/routine-handler/routine-handler.hpp
+++ b/src/classes/routine-handler/routine-handler.hpp
@@ -0,0 +1,30 @@
+/*
+* routine-handler.hpp
+*
+* Author: Carlos Craveiro (@CarlosCraveiro)
+* Created On: September 11, 2021
+*/
+
+#pragma once
+#include
+#include "../routine/routine.hpp"
+
+void routineModule(IRoutine& routine, Status& status);
+
+class RoutineHandler {
+ public:
+ IRoutine* routine;
+ Status status;
+ std::thread innerThread;
+ nlohmann::json* dependecies;
+ nlohmann::json currentDependecies;
+
+ public:
+ void run(void);
+ void stop(void);
+ nlohmann::json getStatus(void);
+ nlohmann::json update(nlohmann::json& updateList);
+ RoutineHandler(IRoutine& routine, nlohmann::json dependecies, nlohmann::json currentDependecies);
+ ~RoutineHandler(void);
+};
+
diff --git a/src/classes/routine/routine.hpp b/src/classes/routine/routine.hpp
index 394246b..fadb445 100644
--- a/src/classes/routine/routine.hpp
+++ b/src/classes/routine/routine.hpp
@@ -8,11 +8,17 @@
#pragma once
#include
+#include
-typedef enum {
- MISSINGDEPENDENCIES = 0, UNINITIALIZED, INITIALIZED, RUNNING, STOPED, DEAD
+class Status {
+ public:
+ enum stateT {
+ MISSINGDEPENDENCIES = 0, UNINITIALIZED, INITIALIZED, RUNNING, STOPED, DEAD
-} stateT;
+ };
+ stateT state;
+ std::mutex mtx;
+};
class IRoutine {
public:
From f4ee34b18f4428032dffcc248c74c21c1380fcb1 Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Sun, 12 Sep 2021 03:49:07 -0300
Subject: [PATCH 005/147] solving a mutex problem in routineModule
---
src/classes/routine-handler/routine-handler.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/classes/routine-handler/routine-handler.cpp b/src/classes/routine-handler/routine-handler.cpp
index eafc6a6..28069dc 100644
--- a/src/classes/routine-handler/routine-handler.cpp
+++ b/src/classes/routine-handler/routine-handler.cpp
@@ -11,7 +11,6 @@ void routineModule(IRoutine& routine, Status& status) {
routine.onLoad();
status.mtx.lock();
status.state = Status::RUNNING;
- status.mtx.unlock();
while(status.state == Status::STOPED){
status.mtx.unlock();
routine.loop();
From fc381229b8f995d7c44ea2a833adfd330f518cd6 Mon Sep 17 00:00:00 2001
From: Math-42
Date: Sun, 12 Sep 2021 13:57:46 +0200
Subject: [PATCH 006/147] adding cmake and conan simple setup files
---
CMakeLists.txt | 10 ++++++++++
conanfile.txt | 6 ++++++
2 files changed, 16 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 conanfile.txt
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..ea00286
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,10 @@
+cmake_minimum_required(VERSION 3.16.3)
+project(daemons-framework)
+
+add_definitions("-std=c++17")
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+add_executable(daemonTest tests/mainTest.cpp)
+target_link_libraries(daemonTest ${CONAN_LIBS})
\ No newline at end of file
diff --git a/conanfile.txt b/conanfile.txt
new file mode 100644
index 0000000..cb82b6e
--- /dev/null
+++ b/conanfile.txt
@@ -0,0 +1,6 @@
+[requires]
+nlohmann_json/3.10.2
+sdbus-cpp/0.8.3
+
+[generators]
+cmake
\ No newline at end of file
From b77c933c86f128e418cf0c6973588b86a47c0f0c Mon Sep 17 00:00:00 2001
From: Math-42
Date: Tue, 14 Sep 2021 01:25:33 +0200
Subject: [PATCH 007/147] adding test to git ignore
---
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 193da6a..a05b696 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1038,3 +1038,4 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf
+tests/mainTest.cpp
\ No newline at end of file
From 4c10a6b007c6dc8132e10f97a575b9b4754913af Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Tue, 14 Sep 2021 17:48:32 -0300
Subject: [PATCH 008/147] Adding checkStatus and update functionalities to the
routine-handler
---
.../routine-handler/routine-handler.cpp | 56 ++++++++++++++-----
.../routine-handler/routine-handler.hpp | 14 +++--
2 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/src/classes/routine-handler/routine-handler.cpp b/src/classes/routine-handler/routine-handler.cpp
index 28069dc..d2bd9f3 100644
--- a/src/classes/routine-handler/routine-handler.cpp
+++ b/src/classes/routine-handler/routine-handler.cpp
@@ -19,13 +19,18 @@ void routineModule(IRoutine& routine, Status& status) {
status.mtx.unlock();
}
-RoutineHandler::RoutineHandler(IRoutine& routine, nlohmann::json dependecies, nlohmann::json currentDependecies) {
+RoutineHandler::RoutineHandler(IRoutine& routine, nlohmann::json& configs) {
(*this->routine) = routine;
this->status.mtx.lock();
- this->status.state = Status::UNINITIALIZED;
+ this->status.state = Status::MISSINGDEPENDENCIES;
this->status.mtx.unlock();
- (*this->dependecies) = dependecies;
- this->currentDependecies = currentDependecies;
+ this->depsRefState = configs["dependencies"];
+ this->depsCrntState = configs["dependencies"];
+ for(nlohmann::json& dependencie : this->depsCrntState) {
+ dependencie["status"] = Status::MISSINGDEPENDENCIES;
+ }
+ this->info.data = configs;
+
}
RoutineHandler::~RoutineHandler() {
@@ -47,21 +52,44 @@ void RoutineHandler::stop(void) {
innerThread.join();
status.mtx.lock();
status.state = Status::DEAD;
- status.mtx.unlock();
+ status.mtx.unlock();
}
nlohmann::json RoutineHandler::getStatus(void) {
- //DO NOTHING
- nlohmann::json myjson;
- myjson["pi"] = 3.14;
- return myjson;
+ std::lock_guard lck(info.occupied);
+ status.mtx.lock();
+ info.data["state"] = status.state;
+ status.mtx.unlock();
+ return info.data;
}
-nlohmann::json RoutineHandler::update(nlohmann::json& updateList) {
- //DO NOTHING
- nlohmann::json myjson;
- myjson["pi"] = 3.14;
- return myjson;
+nlohmann::json RoutineHandler::update(void) {
+ int missingDeps = depsRefState["lenght"];
+ for(int i = 0; i < depsRefState["lenght"]; i++) {
+ using namespace nlohmann;
+ const json& dependencie = depsCrntState[i];
+ const json& dependencieRef = depsRefState[i];
+ if(dependencie["status"] == dependencieRef["status"]) {
+ missingDeps--;
+ }
+ }
+ if(!missingDeps) {
+ run();
+ nlohmann::json changes = getStatus();
+ return (nlohmann::json) {{{"changed", true}}, changes};
+ }
+ status.mtx.lock();
+ if(status.state == Status::RUNNING) {
+ status.mtx.unlock();
+ stop();
+ status.mtx.lock();
+ status.state = Status::MISSINGDEPENDENCIES;
+ status.mtx.unlock();
+ nlohmann::json changes = getStatus();
+ return (nlohmann::json) {{{"changed", true}}, changes};
+ }
+ status.mtx.unlock();
+ return (nlohmann::json) {{"changed", false}};
}
diff --git a/src/classes/routine-handler/routine-handler.hpp b/src/classes/routine-handler/routine-handler.hpp
index f7fa92f..e9f183c 100644
--- a/src/classes/routine-handler/routine-handler.hpp
+++ b/src/classes/routine-handler/routine-handler.hpp
@@ -7,6 +7,7 @@
#pragma once
#include
+#include
#include "../routine/routine.hpp"
void routineModule(IRoutine& routine, Status& status);
@@ -14,17 +15,22 @@ void routineModule(IRoutine& routine, Status& status);
class RoutineHandler {
public:
IRoutine* routine;
+ struct Info {
+ nlohmann::json data;
+ std::mutex occupied;
+ };
+ Info info;
Status status;
std::thread innerThread;
- nlohmann::json* dependecies;
- nlohmann::json currentDependecies;
+ nlohmann::json depsRefState;
+ nlohmann::json depsCrntState;
public:
void run(void);
void stop(void);
nlohmann::json getStatus(void);
- nlohmann::json update(nlohmann::json& updateList);
- RoutineHandler(IRoutine& routine, nlohmann::json dependecies, nlohmann::json currentDependecies);
+ nlohmann::json update(void);
+ RoutineHandler(IRoutine& routine, nlohmann::json& configs);
~RoutineHandler(void);
};
From aefd0e2694267997b2f032a2588db9bf1799d500 Mon Sep 17 00:00:00 2001
From: Math-42
Date: Thu, 16 Sep 2021 17:37:43 +0200
Subject: [PATCH 009/147] initial model of .conf deamon file
---
examples/configModel.json | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 examples/configModel.json
diff --git a/examples/configModel.json b/examples/configModel.json
new file mode 100644
index 0000000..02c66bb
--- /dev/null
+++ b/examples/configModel.json
@@ -0,0 +1,36 @@
+{
+ "daemonId": "DaemonIdExample",
+ "endpoints": [{
+ "id": "endpoint1Name",
+ "type": "signal",
+ "triggers": ["trigger1", "trigger2", "..."],
+ "dependencies": [{
+ "type": "routine",
+ "name": "org.zenith.daemons.daemon1.routineA",
+ "status": 0
+ }]
+ },
+ {
+ "id": "endpoint2Name",
+ "type": "method",
+ "triggers": ["trigger1"],
+ "dependencies": [{
+ "type": "daemon",
+ "name": "org.zenith.daemons.daemon2",
+ "status": 1
+ }]
+ }
+ ],
+ "routines": [{
+ "id": "routine1Name",
+ "signals": ["mySignal1, mySignal2"],
+ "dependencies": [{
+ "type": "endpoint",
+ "name": "org.zenith.daemons.daemon3.endpointB",
+ "status": 2
+ }]
+ }],
+ "data": {
+ "anything": "anything"
+ }
+}
\ No newline at end of file
From fdd2c30bb9e226079dcb9fdaf8e0f34c44c9626d Mon Sep 17 00:00:00 2001
From: Math-42
Date: Thu, 16 Sep 2021 17:37:53 +0200
Subject: [PATCH 010/147] removing gitkeep
---
examples/.gitkeep | 0
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 examples/.gitkeep
diff --git a/examples/.gitkeep b/examples/.gitkeep
deleted file mode 100644
index e69de29..0000000
From 7c0cfee46e0b67e5884c5c8fa9e87596abaad537 Mon Sep 17 00:00:00 2001
From: Math-42
Date: Wed, 15 Sep 2021 22:25:11 +0200
Subject: [PATCH 011/147] moving XML-configurator to the tools dir
---
{src/classes => tools}/XML-configurator/XML-configurator.cpp | 0
{src/classes => tools}/XML-configurator/XML-configurator.hpp | 0
2 files changed, 0 insertions(+), 0 deletions(-)
rename {src/classes => tools}/XML-configurator/XML-configurator.cpp (100%)
rename {src/classes => tools}/XML-configurator/XML-configurator.hpp (100%)
diff --git a/src/classes/XML-configurator/XML-configurator.cpp b/tools/XML-configurator/XML-configurator.cpp
similarity index 100%
rename from src/classes/XML-configurator/XML-configurator.cpp
rename to tools/XML-configurator/XML-configurator.cpp
diff --git a/src/classes/XML-configurator/XML-configurator.hpp b/tools/XML-configurator/XML-configurator.hpp
similarity index 100%
rename from src/classes/XML-configurator/XML-configurator.hpp
rename to tools/XML-configurator/XML-configurator.hpp
From 5345ba43eaa58d2f6ae85e126245c04e0680097c Mon Sep 17 00:00:00 2001
From: Math-42
Date: Wed, 15 Sep 2021 22:26:08 +0200
Subject: [PATCH 012/147] adding utilitie tool to handle dbus functionality
names
---
.../DBusNameHandler/dbus-name-handler.cpp | 37 +++++++++++++++++++
.../DBusNameHandler/dbus-name-handler.hpp | 24 ++++++++++++
2 files changed, 61 insertions(+)
create mode 100644 src/utilities/DBusNameHandler/dbus-name-handler.cpp
create mode 100644 src/utilities/DBusNameHandler/dbus-name-handler.hpp
diff --git a/src/utilities/DBusNameHandler/dbus-name-handler.cpp b/src/utilities/DBusNameHandler/dbus-name-handler.cpp
new file mode 100644
index 0000000..ab74b7f
--- /dev/null
+++ b/src/utilities/DBusNameHandler/dbus-name-handler.cpp
@@ -0,0 +1,37 @@
+#include "./dbus-name-handler.hpp"
+
+DBusName::DBusName(std::string serviceId) {
+ serviceIdDots = "org.frameworkd." + serviceId;
+ serviceIdSlashes = "/" + serviceIdDots;
+ std::replace(serviceIdSlashes.begin(), serviceIdSlashes.end(), '.', '/');
+}
+
+std::string DBusName::getDaemonId() {
+ return serviceIdDots;
+}
+
+std::string DBusName::getObjectPath(std::string objectName) {
+ return serviceIdSlashes + "/" + objectName;
+}
+
+std::string DBusName::getInterfaceName(std::string interfaceName) {
+ return serviceIdDots + "." + interfaceName;
+}
+
+nlohmann::json DBusName::parseFuncionalityPath(std::string functionalityPath) {
+ std::replace(functionalityPath.begin(), functionalityPath.end(), '/', ' ');
+ std::vector array;
+ std::stringstream ss(functionalityPath);
+
+ std::string word;
+ while (ss >> word) array.push_back(word);
+
+ nlohmann::json parsedResponse;
+
+ parsedResponse["serviceId"] = array[0] + "." + array[1] + "." + array[2];
+ parsedResponse["objectPath"] = "/" + array[0] + "/" + array[1] + "/" + array[2] + "/" + array[3];
+ parsedResponse["interfaceName"] = array[0] + "." + array[1] + "." + array[2] +"." + array[3];
+ parsedResponse["functionalityName"] = array[4];
+
+ return parsedResponse;
+}
diff --git a/src/utilities/DBusNameHandler/dbus-name-handler.hpp b/src/utilities/DBusNameHandler/dbus-name-handler.hpp
new file mode 100644
index 0000000..a477adb
--- /dev/null
+++ b/src/utilities/DBusNameHandler/dbus-name-handler.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include
+#include
+#include
+#include
+#include
+
+class DBusName {
+ private:
+
+ std::string serviceIdDots;
+ std::string serviceIdSlashes;
+
+ public:
+
+ DBusName(std::string serviceId);
+ std::string getObjectPath(std::string objectName);
+ std::string getDaemonId();
+ std::string getInterfaceName(std::string interfaceName);
+
+ static nlohmann::json parseFuncionalityPath(std::string funcionalityPath);
+
+};
\ No newline at end of file
From b5b49335191c9f2ac22aaa47fef327f0da688cf9 Mon Sep 17 00:00:00 2001
From: CarlosCraveiro
Date: Thu, 16 Sep 2021 01:04:27 -0300
Subject: [PATCH 013/147] Starting the service.hpp
---
src/classes/service/service.hpp | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/src/classes/service/service.hpp b/src/classes/service/service.hpp
index e69de29..9bce00b 100644
--- a/src/classes/service/service.hpp
+++ b/src/classes/service/service.hpp
@@ -0,0 +1,26 @@
+/*
+ * service.hpp
+ *
+ * Author: Carlos Craveiro (@CarlosCraveiro)
+ * Created On: September 15, 2021
+ */
+
+#pragma once
+#include
+#include
+#include "../routine-handler/routine-handler.hpp"
+
+class Service {
+ public:
+ std::vector routines;
+ std::vector endpoints;
+ public:
+ nlohmann::json getServiceStatus(void);
+ nlohmann::json updateAll(nlohmann::json updateList);
+ nlohmann::json registerEndpoints(void);
+ nlohmann::json registerRoutines(void);
+
+ void buildEndpoint(/*IEndpoint& newEndpoint*/);
+ void buildRoutine(IRoutine& newRoutine);
+};
+
From 04e44c30708c2af3814d2cbd1225eedccf7c7523 Mon Sep 17 00:00:00 2001
From: Math-42
Date: Thu, 16 Sep 2021 17:34:07 +0200
Subject: [PATCH 014/147] first version of DBusHandler methods
---
src/classes/dbus-handler/dbus-handler.cpp | 65 +++++++++++++++++++++++
src/classes/dbus-handler/dbus-handler.hpp | 24 +++++++++
2 files changed, 89 insertions(+)
diff --git a/src/classes/dbus-handler/dbus-handler.cpp b/src/classes/dbus-handler/dbus-handler.cpp
index e69de29..3b4453a 100644
--- a/src/classes/dbus-handler/dbus-handler.cpp
+++ b/src/classes/dbus-handler/dbus-handler.cpp
@@ -0,0 +1,65 @@
+#include "./dbus-handler.hpp"
+
+#include
+#include
+
+DBusHandler::DBusHandler(std::string serviceName, nlohmann::json DBusObjectConfig) {
+ std::string objectNameTemp = DBusObjectConfig["id"];
+ interfaceName = objectPath = serviceName + "." + objectNameTemp;
+
+ std::replace(objectPath.begin(), objectPath.end(), ".", "/");
+ objectPath = "/" + objectPath;
+
+ DBusObject = sdbus::createObject(*connection, objectPath);
+ SDbusEmitter = DBusObject.get();
+
+ std::vector signalsNames = DBusObjectConfig["emittedSignals"];
+ registerSignals(signalsNames);
+}
+
+/**
+ *
+ *@todo
+ * Adicionar regex para o endpoint name /word/word/word...
+ * Adicionar callMethod async(?)
+ */
+nlohmann::json DBusHandler::callMethod(std::string endpointName, nlohmann::json arg) {
+ if (DBusProxys.count(endpointName) != true) throw std::invalid_argument("endpoint not found");
+
+ std::vector response;
+ std::string destinationInterface = endpointName;
+
+ destinationInterface.erase(0, 1);
+ std::replace(destinationInterface.begin(), destinationInterface.end(), "/", ".");
+
+ auto method = DBusProxys[endpointName]->createMethodCall(interfaceName, endpointName);
+ method << nlohmann::json::to_bson(arg);
+ auto reply = DBusProxys[endpointName]->callMethod(method);
+
+ reply >> response;
+
+ return nlohmann::json::from_bson(response);
+}
+
+void DBusHandler::emitSignal(std::string signalName, nlohmann::json arg) {
+ auto signal = SDbusEmitter->createSignal(interfaceName, signalName);
+ signal << nlohmann::json::to_bson(arg);
+ SDbusEmitter->emitSignal(signal);
+}
+
+void DBusHandler::registerSignals(std::vector signalsNames) {
+ for (int i = 0; i < signalsNames.size(); i++) {
+ DBusObject->registerSignal(interfaceName, signalsNames[i], "ai");
+ }
+}
+
+void DBusHandler::getProxys(nlohmann::json DBusObjectConfig) {
+ std::vector tempDependencies = DBusObjectConfig["dependencies"];
+
+ for(const& dependency : tempDependencies){
+
+ }
+}
+
+void bind() {
+}
diff --git a/src/classes/dbus-handler/dbus-handler.hpp b/src/classes/dbus-handler/dbus-handler.hpp
index e69de29..aa1c770 100644
--- a/src/classes/dbus-handler/dbus-handler.hpp
+++ b/src/classes/dbus-handler/dbus-handler.hpp
@@ -0,0 +1,24 @@
+#include
+
+#include