Import CAN generator from low-level-can-service
[src/low-level-can-generator.git] / src / openxc / command.cpp
diff --git a/src/openxc/command.cpp b/src/openxc/command.cpp
new file mode 100755 (executable)
index 0000000..4cc0682
--- /dev/null
@@ -0,0 +1,45 @@
+#include "command.hpp"\r
+\r
+namespace openxc\r
+{\r
+       std::string command::name() const\r
+       {\r
+               return name_;\r
+       }\r
+       \r
+       bool command::enabled() const\r
+       {\r
+               return enabled_;\r
+       }\r
+       \r
+       std::string command::handler() const\r
+       {\r
+               return handler_;\r
+       }\r
+       \r
+       void command::from_json(const nlohmann::json& j)\r
+       {\r
+               name_ = j.count("name") ? j["name"].get<std::string>() : "";\r
+               enabled_ = j.count("enabled") ? j["enabled"].get<bool>() : true;\r
+               handler_ = j.count("handler") ? j["handler"].get<std::string>() : "";\r
+       }\r
+\r
+       nlohmann::json command::to_json() const\r
+       {\r
+               nlohmann::json j;\r
+               j["name"] = name_;\r
+               j["enabled"] = enabled_;\r
+               j["handler"] = handler_;\r
+               return j;\r
+       }\r
+\r
+       void to_json(nlohmann::json& j, const command& p)\r
+       {\r
+               j = p.to_json();\r
+       }\r
+\r
+       void from_json(const nlohmann::json& j, command& p)\r
+       {\r
+               p.from_json(j);\r
+       }\r
+}\r