timers is now complete. timer ubus model is in progress.

This commit is contained in:
2018-04-07 12:19:39 +02:00
parent 83396e3d20
commit 1d078ac2e9
5 changed files with 44 additions and 44 deletions

View File

@@ -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

View File

@@ -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;
}
/*! ----------------------------------------------------------------------------

View File

@@ -138,6 +138,7 @@ const Event &TimerManager::get(uint16_t an_id)
return (*the_timer_evt);
}
}
//todo return something.
}
/*! ----------------------------------------------------------------------------

View File

@@ -33,21 +33,19 @@ extern "C" {
#include <json-c/json.h>
#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;
}

View File

@@ -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 */