Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: operation/ReportThread.h
- Revision:
- 109:2ec12f10ebf4
- Parent:
- 106:c61f0d62b625
- Child:
- 116:4eb3c7e945cf
--- a/operation/ReportThread.h Wed May 13 13:03:20 2015 +0000 +++ b/operation/ReportThread.h Wed May 13 13:54:17 2015 +0000 @@ -1,13 +1,47 @@ #ifndef REPORTTHREAD_H #define REPORTTHREAD_H -#include "SmartRestSocket.h" #include "Operation.h" #include "SmartRestConf.h" +#include "SmartRestSocket.h" +#define OPERATION_DICT_SIZE 10 + +class OperationDict +{ +public: + OperationDict(): count(0) {} + const Operation& operator [](unsigned short i) const { return opl[i]; } + Operation *set(long id, OperationState state) { + unsigned short i = 0; + for (; i < count; ++i) { + if (opl[i].identifier == id) + break; + } + if (i < count) { + opl[i].identifier = id; + opl[i].state = state; + return &opl[i]; + } else if (count < OPERATION_DICT_SIZE) { + opl[i].identifier = id; + opl[i].state = state; + ++count; + return &opl[i]; + } else + return NULL; + + } + void clear() { count = 0; } + bool full() const { return count >= OPERATION_DICT_SIZE; } + unsigned short size() const { return count; } + virtual ~OperationDict() {} +private: + unsigned short count; + Operation opl[OPERATION_DICT_SIZE]; +}; class ReportThread { public: - ReportThread(OperationPool& pool) : ipool(pool), sock(), + ReportThread(OperationPool& pool) : ipool(pool), dict(), sock(), thread(ReportThread::threadWrapper, this) { strncpy(uri, "/s", sizeof(uri)); } @@ -17,6 +51,7 @@ private: char uri[4]; OperationPool& ipool; + OperationDict dict; char buf[SMARTREST_SIZE]; char buf2[SMARTREST_BODY_SIZE]; SmartRestSocket sock;