Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
xinlei
Date:
Mon Aug 08 11:05:57 2016 +0000
Revision:
138:f8ab852e83e7
Parent:
115:4eb3c7e945cf
Etisalat and Teleena APN.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xinlei 93:61d44636f020 1 #ifndef REPORTTHREAD_H
xinlei 93:61d44636f020 2 #define REPORTTHREAD_H
xinlei 93:61d44636f020 3 #include "Operation.h"
xinlei 93:61d44636f020 4 #include "SmartRestConf.h"
xinlei 108:2ec12f10ebf4 5 #include "SmartRestSocket.h"
xinlei 108:2ec12f10ebf4 6 #define OPERATION_DICT_SIZE 10
xinlei 108:2ec12f10ebf4 7
xinlei 108:2ec12f10ebf4 8 class OperationDict
xinlei 108:2ec12f10ebf4 9 {
xinlei 108:2ec12f10ebf4 10 public:
xinlei 108:2ec12f10ebf4 11 OperationDict(): count(0) {}
xinlei 108:2ec12f10ebf4 12 const Operation& operator [](unsigned short i) const { return opl[i]; }
xinlei 108:2ec12f10ebf4 13 Operation *set(long id, OperationState state) {
xinlei 115:4eb3c7e945cf 14 short i = count-1;
xinlei 115:4eb3c7e945cf 15 for (; i >= 0; --i) {
xinlei 108:2ec12f10ebf4 16 if (opl[i].identifier == id)
xinlei 108:2ec12f10ebf4 17 break;
xinlei 108:2ec12f10ebf4 18 }
xinlei 115:4eb3c7e945cf 19 if (i >= 0) {
xinlei 108:2ec12f10ebf4 20 opl[i].identifier = id;
xinlei 108:2ec12f10ebf4 21 opl[i].state = state;
xinlei 108:2ec12f10ebf4 22 return &opl[i];
xinlei 108:2ec12f10ebf4 23 } else if (count < OPERATION_DICT_SIZE) {
xinlei 115:4eb3c7e945cf 24 i = count++;
xinlei 108:2ec12f10ebf4 25 opl[i].identifier = id;
xinlei 108:2ec12f10ebf4 26 opl[i].state = state;
xinlei 108:2ec12f10ebf4 27 return &opl[i];
xinlei 108:2ec12f10ebf4 28 } else
xinlei 108:2ec12f10ebf4 29 return NULL;
xinlei 108:2ec12f10ebf4 30 }
xinlei 108:2ec12f10ebf4 31 void clear() { count = 0; }
xinlei 108:2ec12f10ebf4 32 bool full() const { return count >= OPERATION_DICT_SIZE; }
xinlei 108:2ec12f10ebf4 33 unsigned short size() const { return count; }
xinlei 108:2ec12f10ebf4 34 virtual ~OperationDict() {}
xinlei 108:2ec12f10ebf4 35 private:
xinlei 108:2ec12f10ebf4 36 unsigned short count;
xinlei 108:2ec12f10ebf4 37 Operation opl[OPERATION_DICT_SIZE];
xinlei 108:2ec12f10ebf4 38 };
xinlei 93:61d44636f020 39
xinlei 93:61d44636f020 40 class ReportThread
xinlei 93:61d44636f020 41 {
xinlei 93:61d44636f020 42 public:
xinlei 108:2ec12f10ebf4 43 ReportThread(OperationPool& pool) : ipool(pool), dict(), sock(),
xinlei 93:61d44636f020 44 thread(ReportThread::threadWrapper, this) {
xinlei 93:61d44636f020 45 strncpy(uri, "/s", sizeof(uri));
xinlei 93:61d44636f020 46 }
xinlei 100:dbcd3bc51758 47 virtual ~ReportThread() { }
xinlei 93:61d44636f020 48 void threadFunc();
xinlei 93:61d44636f020 49 static void threadWrapper(const void *p) { ((ReportThread*)p)->threadFunc(); }
xinlei 93:61d44636f020 50 private:
xinlei 93:61d44636f020 51 char uri[4];
xinlei 93:61d44636f020 52 OperationPool& ipool;
xinlei 108:2ec12f10ebf4 53 OperationDict dict;
xinlei 93:61d44636f020 54 char buf[SMARTREST_SIZE];
xinlei 105:c61f0d62b625 55 char buf2[SMARTREST_BODY_SIZE];
xinlei 93:61d44636f020 56 SmartRestSocket sock;
xinlei 93:61d44636f020 57 Thread thread;
xinlei 93:61d44636f020 58 };
xinlei 93:61d44636f020 59
xinlei 93:61d44636f020 60 #endif /* REPORTTHREAD_H */