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.
Diff: ICE-Application/src/ConfigurationHandler/Algorithms/CompositeAlgorithm.cpp
- Revision:
- 2:02cb20446785
- Parent:
- 1:b2e90cda7a5a
--- a/ICE-Application/src/ConfigurationHandler/Algorithms/CompositeAlgorithm.cpp Tue Jan 24 19:06:45 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/****************************************************************************** - * - * File: CompositeAlgorithm.cpp - * Desciption: source for the ICE Composite Algorithm - * - *****************************************************************************/ -#include "global.h" -#include "cJSON.h" -#include "ICELog.h" -#include "CompositeAlgorithm.h" -//#include "../add-ons/MTSLog/MTSLog.h" - -// -// method: load -// description: load the pertinents from the control file -// -// @param[in] _controlFile : name of the control file -// @param[out] none -// @return none -// -bool CompositeAlgorithm::load(const std::string _controlFile) -{ - controlFile = _controlFile; - - // read the data into a buffer - char dataBuf[MAX_FILE_SIZE]; - bool rc = GLOBAL_mdot->readUserFile(controlFile.c_str(), (void *)dataBuf, sizeof(dataBuf)); - if ( rc != true ) { - logError("%s: failed to read %s", __func__, controlFile.c_str()); - // caller should destroy the object - return false; - } - - // parse the JSON data - cJSON * root = cJSON_Parse(dataBuf); - - if ( !cJSON_HasObjectItem(root, "id") || - !cJSON_HasObjectItem(root, "opr") || - !cJSON_HasObjectItem(root, "op") || - !cJSON_HasObjectItem(root, "true") || - !cJSON_HasObjectItem(root, "false") ) { - logError("%s: control file is missing expected tags", __func__); - cJSON_Delete(root); - return false; - } - - id = cJSON_GetObjectItem(root, "id")->valuestring; - opr = cJSON_GetObjectItem(root, "opr")->valuestring; - op = cJSON_GetObjectItem(root, "op")->valuestring; - resultTrue = cJSON_GetObjectItem(root, "true")->valuestring; - resultFalse = cJSON_GetObjectItem(root, "false")->valuestring; - - cJSON_Delete(root); - return true; -} - -// -// method: validateControlData -// description: validate the JSON formatted string -// -// @param[in] buf -> JSON formatted string -// @param[out] none -// @return true if valid; false otherwise -// -bool CompositeAlgorithm::validateControlData(const char *buf) -{ - bool rc = true; - cJSON * root = cJSON_Parse(buf); - - if ( !cJSON_HasObjectItem(root, "id") || - !cJSON_HasObjectItem(root, "opr") || - !cJSON_HasObjectItem(root, "op") || - !cJSON_HasObjectItem(root, "true") || - !cJSON_HasObjectItem(root, "false") ) { - logError("%s: control file is missing expected tags", __func__); - rc = false; - } - cJSON_Delete(root); - return rc; -} - -// -// method: copyControlData -// description: copy JSON data to control data -// -// @param[in] buf -> JSON formatted string -// @param[out] none -// @return -void CompositeAlgorithm::copyControlData(const char *buf) -{ - cJSON * root = cJSON_Parse(buf); - - id = cJSON_GetObjectItem(root, "id")->valuestring; - opr = cJSON_GetObjectItem(root, "opr")->valuestring; - op = cJSON_GetObjectItem(root, "op")->valuestring; - resultTrue = cJSON_GetObjectItem(root, "true")->valuestring; - resultFalse = cJSON_GetObjectItem(root, "false")->valuestring; - - cJSON_Delete(root); -} - -// -// method: display -// description: display the pertinents -// -// @param[in] none -// @param[out] none -// @return none -// -void CompositeAlgorithm::display(void) -{ - printf("\r id : %s\n", id.c_str()); - printf("\r opr : %s\n", opr.c_str()); - printf("\r op : %s\n", op.c_str()); - printf("\r true : %s\n", resultTrue.c_str()); - printf("\r false : %s\n", resultFalse.c_str()); - printf("\r\n"); -} \ No newline at end of file