From 1d078ac2e90bb1ae9ce24ae066c4d9f0bf518e27 Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Sat, 7 Apr 2018 12:19:39 +0200 Subject: [PATCH] timers is now complete. timer ubus model is in progress. --- src/prog/domod/builders/cmake/CMakeLists.txt | 2 +- src/prog/domod/src/timers/event.cpp | 32 +++++++------ src/prog/domod/src/timers/timers-manager.cpp | 1 + src/prog/domod/src/ubus/timers.cpp | 47 +++++++++----------- src/prog/domod/src/ubus/timers.h | 6 +-- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/prog/domod/builders/cmake/CMakeLists.txt b/src/prog/domod/builders/cmake/CMakeLists.txt index c5e6c2f7..c3065dc5 100644 --- a/src/prog/domod/builders/cmake/CMakeLists.txt +++ b/src/prog/domod/builders/cmake/CMakeLists.txt @@ -29,7 +29,7 @@ file( ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_lights.cpp ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_shutters.cpp ${workspaceRoot}/src/prog/domod/src/ubus/capabilities_sprinklers.cpp - #${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp + ${workspaceRoot}/src/prog/domod/src/ubus/timers.cpp # Timers ${workspaceRoot}/src/prog/domod/src/timers/timers-manager.cpp diff --git a/src/prog/domod/src/timers/event.cpp b/src/prog/domod/src/timers/event.cpp index e2b1a3d4..77e6756b 100644 --- a/src/prog/domod/src/timers/event.cpp +++ b/src/prog/domod/src/timers/event.cpp @@ -136,22 +136,28 @@ int Event::from_json(struct json_object *a_node) */ struct json_object *Event::to_json(void) const { -#if 0 - Json::Value aResult(Json::objectValue); + struct json_object *the_root_node; - aResult ["id"] = mID; + the_root_node = json_object_new_object(); - aResult ["active"] = mActive; - aResult ["device_id"] = mCapability + "/" + std::to_string(mDeviceID); - aResult ["action"] = mAction; + // id + json_object_object_add(the_root_node, k_entry_id, json_object_new_int(m_id)); + // active + json_object_object_add(the_root_node, k_entry_active, json_object_new_boolean(m_active)); + // device_id + std::string the_device_id = m_capability + "/" + std::to_string(m_device_id); + json_object_object_add(the_root_node, k_entry_device_id, json_object_new_string(the_device_id.c_str())); + // action + json_object_object_add(the_root_node, k_entry_action, json_object_new_string(m_action.c_str())); + // recurrence + json_object_object_add(the_root_node, k_entry_recurrence, json_object_new_int(m_recurrence)); + // duration + json_object_object_add(the_root_node, k_entry_duration, json_object_new_int(m_duration)); + //start_time + std::string the_start_time = std::to_string(m_hour) + ":" + std::to_string(m_minute); + json_object_object_add(the_root_node, k_entry_start_time, json_object_new_string(the_start_time.c_str())); - aResult["recurrence"] = mRecurrence; - aResult["duration"] = mDuration; - - aResult["start_time"] = std::to_string(mHour) + ":" + std::to_string(mMinute); - - return aResult; -#endif + return the_root_node; } /*! ---------------------------------------------------------------------------- diff --git a/src/prog/domod/src/timers/timers-manager.cpp b/src/prog/domod/src/timers/timers-manager.cpp index 514c85fe..66815462 100644 --- a/src/prog/domod/src/timers/timers-manager.cpp +++ b/src/prog/domod/src/timers/timers-manager.cpp @@ -138,6 +138,7 @@ const Event &TimerManager::get(uint16_t an_id) return (*the_timer_evt); } } + //todo return something. } /*! ---------------------------------------------------------------------------- diff --git a/src/prog/domod/src/ubus/timers.cpp b/src/prog/domod/src/ubus/timers.cpp index 8834d1a2..a3b0cd57 100644 --- a/src/prog/domod/src/ubus/timers.cpp +++ b/src/prog/domod/src/ubus/timers.cpp @@ -33,21 +33,19 @@ extern "C" { #include - -#include "timers/timers.h" +#include "timers/timers-manager.h" #include "timers.h" -namespace { +namespace +{ using namespace UBus; static ObjectType gTimersModelUbus_types( "TimersModel", - Method("get", UBUS_CPP(TimersModel, Get)), - Method("delete", UBUS_CPP(TimersModel, Delete)) -); - + Method("get", UBUS_CPP(TimersModel, get)), + Method("delete", UBUS_CPP(TimersModel, del))); } /*! ---------------------------------------------------------------------------- @@ -55,33 +53,29 @@ static ObjectType gTimersModelUbus_types( * * @brief Constructor of the Timer Objects. */ -TimersModel::TimersModel (Timers *aTimers) : - UBusObject (gTimersModelUbus_types, "domo.timers"), - mTimers (aTimers) +TimersModel::TimersModel(TimerManager *a_timer_manager) : UBusObject(gTimersModelUbus_types, "domo.timers"), + m_timer_manager(a_timer_manager) { } - /*! ---------------------------------------------------------------------------- * @fn ~TimersModel * * @brief Destructor of the Timer Objects. */ -TimersModel::~TimersModel (void) +TimersModel::~TimersModel(void) { - } - /*! ---------------------------------------------------------------------------- - * @fn Get + * @fn get * * @brief Get the List of timer objects. */ -int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) +int TimersModel::get(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { - int theResult = 0; + int the_result = 0; +#if 0 int theID = -1; Json::Reader theReader; Json::StyledWriter theWriter; @@ -111,20 +105,19 @@ int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, theResult = ubus_send_reply (aCtx, aReq, theBuf.head); blob_buf_free (&theBuf); - - return theResult; +#endif + return the_result; } - /*! ---------------------------------------------------------------------------- - * @fn Delete + * @fn del * * @brief Delete a Timer Object. */ -int TimersModel::Delete (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) +int TimersModel::del(struct ubus_context *a_ctx, struct ubus_request_data *a_req, struct blob_attr *a_msg) { - int theResult = 0; + int the_result = 0; +#if 0 Json::Reader theReader; Json::Value theRoot; int theID = -1; @@ -147,6 +140,6 @@ int TimersModel::Delete (struct ubus_context *aCtx, struct ubus_request_data *aR printf ("Successfully removed.\n"); //TODO SAVE and return OK. } - - return theResult; +#endif + return the_result; } diff --git a/src/prog/domod/src/ubus/timers.h b/src/prog/domod/src/ubus/timers.h index 91987d81..916dfbb4 100644 --- a/src/prog/domod/src/ubus/timers.h +++ b/src/prog/domod/src/ubus/timers.h @@ -34,7 +34,7 @@ /*--------------------------------- Define ----------------------------------*/ -class Timers; +class TimerManager; /*--------------------------------- CLASS ----------------------------------*/ @@ -42,14 +42,14 @@ class TimersModel : public UBusObject { public: - TimersModel(Timers *aTimers); + TimersModel(TimerManager *a_timer_manager); ~TimersModel(void); int get(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); int del(struct ubus_context *, struct ubus_request_data *, struct blob_attr *); private: - Timers *m_timers; + TimerManager *m_timer_manager; }; #endif /* _UBUS_TIMERS_H */