Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NaturalTinyShell_ice libmDot-12Sept mbed-rtos mbed
Fork of ICE by
Diff: src/OutputTask/OutputTask.cpp
- Revision:
- 80:b12b0adfcdc2
- Parent:
- 77:43e0a3d9e536
- Child:
- 84:7b7cad3ba139
--- a/src/OutputTask/OutputTask.cpp Mon Sep 19 21:20:43 2016 +0000 +++ b/src/OutputTask/OutputTask.cpp Tue Sep 20 12:49:58 2016 +0000 @@ -23,7 +23,8 @@ typedef std::map<string, vector<Control> > StringOutputVector_t; StringOutputVector_t outputMap; -bool operator<(const Control &control1, const Control &control2) { +bool operator<(const Control &control1, const Control &control2) +{ return control1.getPriority() < control2.getPriority(); } @@ -36,6 +37,7 @@ *****************************************************************************/ void OutputTask(void const *args) { + int rc; UNUSED(args); printf("\r%s has started...\n", __func__); @@ -48,30 +50,41 @@ // wait for an event osEvent evt = OutputMasterMailBox.get(); if (evt.status == osEventMail) { + OutputControlMsg_t *msg = (OutputControlMsg_t*) evt.value.p; -#if 0 - printf("\r%s received message from someone...\n", __func__); - printf("\rmsg->relay = %s\n", msg->output); - printf("\rmsg->state = %s\n", msg->state == ON ? "ON" : "OFF"); - printf("\rmsg->priority = %u\n", msg->priority); -#endif switch ( msg->action ) { case ACTION_NEW: // read the file and and create an output entry - (void) createOutput(msg->controlFile); + rc = createOutput(msg->controlFile); + if ( rc != 0 ) { + logError("%s: failed to create output %s\n", + __func__, msg->controlFile); + } break; case ACTION_CONTROL_ON: logInfo("%s is requesting ON control of %s", msg->id, msg->output); - (void) enableOutputReq(msg->id, msg->priority, msg->output); + rc = enableOutputReq(msg->id, msg->priority, msg->output); + if ( rc != 0 ) { + logError("%s: failed to enabled output for %s", + __func__, msg->id); + } break; case ACTION_CONTROL_OFF: logInfo("%s is requesting OFF control of %s", msg->id, msg->output); - (void) disableOutputReq(msg->id, msg->priority, msg->output); + rc = disableOutputReq(msg->id, msg->priority, msg->output); + if ( rc != 0 ) { + printf("%s: failed to disabled output for %s", + __func__, msg->id); + } break; case ACTION_CONTROL_UNREGISTER: logInfo("%s is requesting its deletion from %s", msg->id, msg->output); - (void) unregisterControl(msg->id, msg->priority, msg->output); + rc = unregisterControl(msg->id, msg->priority, msg->output); + if ( rc != 0 ) { + printf("%s: failed to unregister control %s", + __func__, msg->id); + } break; default: break; @@ -204,7 +217,7 @@ return -1; } - // is the same id requesting? + // if the control list is empty, push this control on the list if ( pos->second.empty() ) { string cid(id); Control c(cid, priority, CONTROL_OFF); @@ -218,6 +231,14 @@ break; } } + + if ( v == pos->second.end() ) { + // this is a new request, so add it and sort the vector + string cid(id); + Control c(cid, priority, CONTROL_OFF); + pos->second.push_back(c); + std::sort(pos->second.begin(), pos->second.end()); + } } return 0; @@ -237,6 +258,7 @@ { // attempt to find the output in the map StringOutputVector_t::iterator pos; + bool found = false; pos = outputMap.find(output); if ( pos == outputMap.end() ) { @@ -251,9 +273,14 @@ if ( strcmp(v->getId().c_str(), id) == 0 ) { // delete this entry pos->second.erase(v); + found = true; break; } } + if ( !found ) { + logError("%s: failed to find control %s in list", __func__, id); + return -1; + } return 0; } @@ -292,7 +319,7 @@ string id = json_value["id"].get<string>(); printf("\r output %s loaded\n", i->name); - // emplace the empty control vector into the outputm map + // emplace the empty control vector into the output map vector<Control> v; outputMap[id] = v; }