Sensor with Web Server
Dependencies: EthernetInterface mbed-rpc mbed-rtos mbed
RPCObjectManager.cpp@0:c385e589a779, 2014-04-08 (annotated)
- Committer:
- afilipem
- Date:
- Tue Apr 08 12:13:32 2014 +0000
- Revision:
- 0:c385e589a779
1 version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
afilipem | 0:c385e589a779 | 1 | #include "RPCObjectManager.h" |
afilipem | 0:c385e589a779 | 2 | #include "mbed.h" |
afilipem | 0:c385e589a779 | 3 | |
afilipem | 0:c385e589a779 | 4 | RPCObjectManager& RPCObjectManager::instance() |
afilipem | 0:c385e589a779 | 5 | { |
afilipem | 0:c385e589a779 | 6 | static RPCObjectManager om; |
afilipem | 0:c385e589a779 | 7 | return om; |
afilipem | 0:c385e589a779 | 8 | } |
afilipem | 0:c385e589a779 | 9 | |
afilipem | 0:c385e589a779 | 10 | RPCObjectManager::RPCObjectManager(): |
afilipem | 0:c385e589a779 | 11 | objects() |
afilipem | 0:c385e589a779 | 12 | { |
afilipem | 0:c385e589a779 | 13 | } |
afilipem | 0:c385e589a779 | 14 | |
afilipem | 0:c385e589a779 | 15 | RPCObjectManager::~RPCObjectManager() |
afilipem | 0:c385e589a779 | 16 | { |
afilipem | 0:c385e589a779 | 17 | for(std::list<char*>::iterator itor = objects.begin(); |
afilipem | 0:c385e589a779 | 18 | itor != objects.end(); |
afilipem | 0:c385e589a779 | 19 | ++itor) |
afilipem | 0:c385e589a779 | 20 | delete *itor; |
afilipem | 0:c385e589a779 | 21 | } |
afilipem | 0:c385e589a779 | 22 | |
afilipem | 0:c385e589a779 | 23 | void RPCObjectManager::store_object(char *obj_name) |
afilipem | 0:c385e589a779 | 24 | { |
afilipem | 0:c385e589a779 | 25 | char *obj = new char[strlen(obj_name)+1]; |
afilipem | 0:c385e589a779 | 26 | strcpy(obj, obj_name); |
afilipem | 0:c385e589a779 | 27 | obj[strlen(obj_name)] = '\0'; |
afilipem | 0:c385e589a779 | 28 | objects.push_back(obj); |
afilipem | 0:c385e589a779 | 29 | } |
afilipem | 0:c385e589a779 | 30 | |
afilipem | 0:c385e589a779 | 31 | void RPCObjectManager::remove_object(char *obj_name) |
afilipem | 0:c385e589a779 | 32 | { |
afilipem | 0:c385e589a779 | 33 | for(std::list<char*>::iterator itor = objects.begin(); |
afilipem | 0:c385e589a779 | 34 | itor != objects.end(); |
afilipem | 0:c385e589a779 | 35 | ++itor) |
afilipem | 0:c385e589a779 | 36 | if(!strcmp(obj_name, *itor)) |
afilipem | 0:c385e589a779 | 37 | { |
afilipem | 0:c385e589a779 | 38 | delete *itor; |
afilipem | 0:c385e589a779 | 39 | objects.erase(itor); |
afilipem | 0:c385e589a779 | 40 | break; |
afilipem | 0:c385e589a779 | 41 | } |
afilipem | 0:c385e589a779 | 42 | } |
afilipem | 0:c385e589a779 | 43 | |
afilipem | 0:c385e589a779 | 44 | bool RPCObjectManager::lookup_object(char *obj_name) |
afilipem | 0:c385e589a779 | 45 | { |
afilipem | 0:c385e589a779 | 46 | for(std::list<char*>::iterator itor = objects.begin(); |
afilipem | 0:c385e589a779 | 47 | itor != objects.end(); |
afilipem | 0:c385e589a779 | 48 | ++itor) |
afilipem | 0:c385e589a779 | 49 | if(!strcmp(obj_name, *itor)) |
afilipem | 0:c385e589a779 | 50 | return true; |
afilipem | 0:c385e589a779 | 51 | return false; |
afilipem | 0:c385e589a779 | 52 | } |
afilipem | 0:c385e589a779 | 53 | |
afilipem | 0:c385e589a779 | 54 | bool RPCObjectManager::is_empty() |
afilipem | 0:c385e589a779 | 55 | { |
afilipem | 0:c385e589a779 | 56 | return objects.empty(); |
afilipem | 0:c385e589a779 | 57 | } |
afilipem | 0:c385e589a779 | 58 | |
afilipem | 0:c385e589a779 | 59 | std::list<char*>::iterator RPCObjectManager::begin() |
afilipem | 0:c385e589a779 | 60 | { |
afilipem | 0:c385e589a779 | 61 | return objects.begin(); |
afilipem | 0:c385e589a779 | 62 | } |
afilipem | 0:c385e589a779 | 63 | |
afilipem | 0:c385e589a779 | 64 | std::list<char*>::iterator RPCObjectManager::end() |
afilipem | 0:c385e589a779 | 65 | { |
afilipem | 0:c385e589a779 | 66 | return objects.end(); |
afilipem | 0:c385e589a779 | 67 | } |
afilipem | 0:c385e589a779 | 68 |