Doug Anson / ReportDB
Committer:
ansond
Date:
Thu Aug 28 21:06:21 2014 +0000
Revision:
2:5a7b822b54d7
Parent:
1:67f91b0caa95
renamed definitions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:6a368cae1bdb 1 /* Copyright C2014 ARM, MIT License
ansond 0:6a368cae1bdb 2 *
ansond 0:6a368cae1bdb 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:6a368cae1bdb 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:6a368cae1bdb 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:6a368cae1bdb 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:6a368cae1bdb 7 * furnished to do so, subject to the following conditions:
ansond 0:6a368cae1bdb 8 *
ansond 0:6a368cae1bdb 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:6a368cae1bdb 10 * substantial portions of the Software.
ansond 0:6a368cae1bdb 11 *
ansond 0:6a368cae1bdb 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:6a368cae1bdb 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:6a368cae1bdb 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:6a368cae1bdb 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:6a368cae1bdb 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:6a368cae1bdb 17 */
ansond 0:6a368cae1bdb 18
ansond 0:6a368cae1bdb 19 #include "WidgetDB.h"
ansond 0:6a368cae1bdb 20
ansond 0:6a368cae1bdb 21 // min function
ansond 0:6a368cae1bdb 22 extern "C" int min(int val1,int val2) {
ansond 0:6a368cae1bdb 23 if (val1 < val2) return val1;
ansond 0:6a368cae1bdb 24 return val2;
ansond 0:6a368cae1bdb 25 }
ansond 0:6a368cae1bdb 26
ansond 0:6a368cae1bdb 27 // constructor
ansond 0:6a368cae1bdb 28 WidgetDB::WidgetDB() {
ansond 0:6a368cae1bdb 29 this->initDB();
ansond 0:6a368cae1bdb 30 }
ansond 0:6a368cae1bdb 31
ansond 0:6a368cae1bdb 32 // destructor
ansond 0:6a368cae1bdb 33 WidgetDB::~WidgetDB() {
ansond 0:6a368cae1bdb 34 }
ansond 0:6a368cae1bdb 35
ansond 0:6a368cae1bdb 36 // lookup and return a widget
ansond 0:6a368cae1bdb 37 WidgetEntry *WidgetDB::lookup(int rfid) {
ansond 0:6a368cae1bdb 38 WidgetEntry *entry = NULL;
ansond 0:6a368cae1bdb 39 bool found = false;
ansond 0:6a368cae1bdb 40
ansond 0:6a368cae1bdb 41 // linear search through the list until we end or find something...
ansond 2:5a7b822b54d7 42 for(int i=0;i<DB_MAX_NUM_WIDGETS &&!found;++i) {
ansond 0:6a368cae1bdb 43 if (this->m_db[i].rfid == rfid) {
ansond 0:6a368cae1bdb 44 found = true;
ansond 0:6a368cae1bdb 45 entry = &(this->m_db[i]);
ansond 0:6a368cae1bdb 46 }
ansond 0:6a368cae1bdb 47 }
ansond 0:6a368cae1bdb 48
ansond 0:6a368cae1bdb 49 return entry;
ansond 0:6a368cae1bdb 50 }
ansond 0:6a368cae1bdb 51
ansond 0:6a368cae1bdb 52 // lookup a widget and return its name
ansond 0:6a368cae1bdb 53 char *WidgetDB::lookupWidgetName(int rfid) {
ansond 0:6a368cae1bdb 54 WidgetEntry *entry = this->lookup(rfid);
ansond 0:6a368cae1bdb 55 if (entry != NULL) return entry->name;
ansond 0:6a368cae1bdb 56 return NULL;
ansond 0:6a368cae1bdb 57 }
ansond 0:6a368cae1bdb 58
ansond 0:6a368cae1bdb 59 // lookup a widget and return its description
ansond 0:6a368cae1bdb 60 char *WidgetDB::lookupWidgetDescription(int rfid) {
ansond 0:6a368cae1bdb 61 WidgetEntry *entry = this->lookup(rfid);
ansond 1:67f91b0caa95 62 if (entry != NULL) return entry->description;
ansond 0:6a368cae1bdb 63 return NULL;
ansond 0:6a368cae1bdb 64 }
ansond 0:6a368cae1bdb 65
ansond 0:6a368cae1bdb 66 // initialize the DB
ansond 0:6a368cae1bdb 67 void WidgetDB::initDB() {
ansond 0:6a368cae1bdb 68 // First Widget
ansond 0:6a368cae1bdb 69 memset((void *)&(this->m_db[FIRST_WIDGET]),0,sizeof(WidgetEntry));
ansond 0:6a368cae1bdb 70 this->m_db[FIRST_WIDGET].rfid = FIRST_WIDGET_RFID;
ansond 2:5a7b822b54d7 71 strncpy(this->m_db[FIRST_WIDGET].name,FIRST_WIDGET_NAME,min(strlen(FIRST_WIDGET_NAME),DB_MAX_NAME_LENGTH));
ansond 2:5a7b822b54d7 72 strncpy(this->m_db[FIRST_WIDGET].description,FIRST_WIDGET_DESCRIPTION,min(strlen(FIRST_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 0:6a368cae1bdb 73
ansond 0:6a368cae1bdb 74 // Second Widget
ansond 0:6a368cae1bdb 75 memset((void *)&(this->m_db[SECOND_WIDGET]),0,sizeof(WidgetEntry));
ansond 0:6a368cae1bdb 76 this->m_db[SECOND_WIDGET].rfid = SECOND_WIDGET_RFID;
ansond 2:5a7b822b54d7 77 strncpy(this->m_db[SECOND_WIDGET].name,SECOND_WIDGET_NAME,min(strlen(SECOND_WIDGET_NAME),DB_MAX_NAME_LENGTH));
ansond 2:5a7b822b54d7 78 strncpy(this->m_db[SECOND_WIDGET].description,SECOND_WIDGET_DESCRIPTION,min(strlen(SECOND_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 1:67f91b0caa95 79
ansond 1:67f91b0caa95 80 // Third Widget
ansond 1:67f91b0caa95 81 memset((void *)&(this->m_db[THIRD_WIDGET]),0,sizeof(WidgetEntry));
ansond 1:67f91b0caa95 82 this->m_db[THIRD_WIDGET].rfid = THIRD_WIDGET_RFID;
ansond 2:5a7b822b54d7 83 strncpy(this->m_db[THIRD_WIDGET].name,THIRD_WIDGET_NAME,min(strlen(THIRD_WIDGET_NAME),DB_MAX_NAME_LENGTH));
ansond 2:5a7b822b54d7 84 strncpy(this->m_db[THIRD_WIDGET].description,THIRD_WIDGET_DESCRIPTION,min(strlen(THIRD_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
ansond 0:6a368cae1bdb 85 }