diff --git a/src/domod/src/timers/Timers.cpp b/src/domod/src/timers/Timers.cpp index 7ac09ee7..250ccd65 100644 --- a/src/domod/src/timers/Timers.cpp +++ b/src/domod/src/timers/Timers.cpp @@ -131,6 +131,27 @@ Event Timers::get (uint16_t anID) } +/*! ---------------------------------------------------------------------------- + * @fn remove + * + * @brief Method to remove a specific Timers Object. + */ +int Timers::remove (uint16_t anID) +{ + std::vector::iterator timer_evt; + + for (timer_evt = mTimers.begin(); timer_evt != mTimers.end(); timer_evt++) { + + if ((*timer_evt).getID() == anID) + + mTimers.erase (timer_evt); + return 0; + } + + return -1; +} + + /*! ---------------------------------------------------------------------------- * @fn to_json * diff --git a/src/domod/src/timers/Timers.h b/src/domod/src/timers/Timers.h index 642430b1..ee5c93ed 100644 --- a/src/domod/src/timers/Timers.h +++ b/src/domod/src/timers/Timers.h @@ -54,7 +54,8 @@ public: int save (void); Event get (uint16_t anID); - + int remove (uint16_t anID); + Json::Value to_json (void); private: diff --git a/src/domod/src/ubus/timers.cpp b/src/domod/src/ubus/timers.cpp index cd42a798..8079043e 100644 --- a/src/domod/src/ubus/timers.cpp +++ b/src/domod/src/ubus/timers.cpp @@ -44,7 +44,8 @@ using namespace UBus; static ObjectType gTimersModelUbus_types( "TimersModel", - Method("get", UBUS_CPP(TimersModel, Get)) + Method("get", UBUS_CPP(TimersModel, Get)), + Method("delete", UBUS_CPP(TimersModel, Delete)) ); } @@ -52,7 +53,7 @@ static ObjectType gTimersModelUbus_types( /*! ---------------------------------------------------------------------------- * @fn TimersModel * - * @brief Constructor of the UBus Mixer Volume. + * @brief Constructor of the Timer Objects. */ TimersModel::TimersModel (Timers *aTimers) : UBusObject (gTimersModelUbus_types, "domo.timers"), @@ -64,7 +65,7 @@ TimersModel::TimersModel (Timers *aTimers) : /*! ---------------------------------------------------------------------------- * @fn ~TimersModel * - * @brief Destructor of the UBus Mixer Volume. + * @brief Destructor of the Timer Objects. */ TimersModel::~TimersModel (void) { @@ -75,10 +76,10 @@ TimersModel::~TimersModel (void) /*! ---------------------------------------------------------------------------- * @fn Get * - * @brief Get the List of the Capabilities. + * @brief Get the List of timer objects. */ int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, - struct blob_attr *aMsg) + struct blob_attr *aMsg) { int theResult = 0; int theID = -1; @@ -92,12 +93,12 @@ int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, if (!theReader.parse (theString, theRoot)) { - fprintf (stderr, "Failed parse the parameters.\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } + fprintf (stderr, "Failed parse the parameters.\n"); + return UBUS_STATUS_INVALID_ARGUMENT; + } theID = theRoot["id"].asInt(); - + blob_buf_init (&theBuf, 0); if (theID == 0) @@ -113,3 +114,39 @@ int TimersModel::Get (struct ubus_context *aCtx, struct ubus_request_data *aReq, return theResult; } + + +/*! ---------------------------------------------------------------------------- + * @fn Delete + * + * @brief Delete a Timer Object. + */ +int TimersModel::Delete (struct ubus_context *aCtx, struct ubus_request_data *aReq, + struct blob_attr *aMsg) +{ + int theResult = 0; + Json::Reader theReader; + Json::Value theRoot; + int theID = -1; + char *theString = blobmsg_format_json (aMsg, true); + + if (!theReader.parse (theString, theRoot)) { + + fprintf (stderr, "Failed parse the parameters.\n"); + return UBUS_STATUS_INVALID_ARGUMENT; + } + + theID = theRoot["id"].asInt(); + + printf ("try to delete id: %d\n", theID); + + theResult = mTimers->remove (theID); + + if (theResult == 0) { + + printf ("Successfully removed.\n"); + //TODO SAVE and return OK. + } + + return theResult; +} diff --git a/src/domod/src/ubus/timers.h b/src/domod/src/ubus/timers.h index dbf4b056..71e36589 100644 --- a/src/domod/src/ubus/timers.h +++ b/src/domod/src/ubus/timers.h @@ -45,6 +45,7 @@ public: ~TimersModel (void); int Get (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); + int Delete (struct ubus_context*, struct ubus_request_data*, struct blob_attr*); private: Timers *mTimers;