trivial RFID tag database

Revision:
3:ea6ac7464011
Parent:
2:5a7b822b54d7
--- a/WidgetDB.cpp	Thu Aug 28 21:06:21 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/* Copyright C2014 ARM, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files the "Software", to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- 
- #include "WidgetDB.h"
- 
- // min function
- extern "C" int min(int val1,int val2) {
-     if (val1 < val2) return val1;
-     return val2;
- }
- 
- // constructor
- WidgetDB::WidgetDB() {
-     this->initDB();
- }
- 
- // destructor
- WidgetDB::~WidgetDB() {
- }
- 
- // lookup and return a widget
- WidgetEntry *WidgetDB::lookup(int rfid) {
-     WidgetEntry *entry = NULL;
-     bool         found = false;
-     
-     // linear search through the list until we end or find something...
-     for(int i=0;i<DB_MAX_NUM_WIDGETS &&!found;++i) {
-         if (this->m_db[i].rfid == rfid) {
-             found = true;
-             entry = &(this->m_db[i]);
-         }
-     }
-     
-     return entry;
- }
- 
- // lookup a widget and return its name
- char *WidgetDB::lookupWidgetName(int rfid) {
-     WidgetEntry *entry = this->lookup(rfid);
-     if (entry != NULL) return entry->name;
-     return NULL;
- }
-     
- // lookup a widget and return its description
- char *WidgetDB::lookupWidgetDescription(int rfid) {
-     WidgetEntry *entry = this->lookup(rfid);
-     if (entry != NULL) return entry->description;
-     return NULL;
- }
- 
- // initialize the DB
- void WidgetDB::initDB() {
-     // First Widget
-     memset((void *)&(this->m_db[FIRST_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[FIRST_WIDGET].rfid = FIRST_WIDGET_RFID;
-     strncpy(this->m_db[FIRST_WIDGET].name,FIRST_WIDGET_NAME,min(strlen(FIRST_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[FIRST_WIDGET].description,FIRST_WIDGET_DESCRIPTION,min(strlen(FIRST_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
-     
-     // Second Widget
-     memset((void *)&(this->m_db[SECOND_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[SECOND_WIDGET].rfid = SECOND_WIDGET_RFID;
-     strncpy(this->m_db[SECOND_WIDGET].name,SECOND_WIDGET_NAME,min(strlen(SECOND_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[SECOND_WIDGET].description,SECOND_WIDGET_DESCRIPTION,min(strlen(SECOND_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
-     
-     // Third Widget
-     memset((void *)&(this->m_db[THIRD_WIDGET]),0,sizeof(WidgetEntry));
-     this->m_db[THIRD_WIDGET].rfid = THIRD_WIDGET_RFID;
-     strncpy(this->m_db[THIRD_WIDGET].name,THIRD_WIDGET_NAME,min(strlen(THIRD_WIDGET_NAME),DB_MAX_NAME_LENGTH));
-     strncpy(this->m_db[THIRD_WIDGET].description,THIRD_WIDGET_DESCRIPTION,min(strlen(THIRD_WIDGET_DESCRIPTION),DB_MAX_DESCRIPTION_LENGTH));
- }
\ No newline at end of file