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 Vincent Wochnik

Files at this revision

API Documentation at this revision

Comitter:
xinlei
Date:
Mon May 18 09:29:12 2015 +0000
Parent:
115:c54e9731b9de
Child:
117:5de54f09f754
Commit message:
Remove mutex for SmartRestSocket::cachedIP, reverse search for OperationDict::set

Changed in this revision

operation/ReportThread.h Show annotated file Show diff for this revision Revisions of this file
util/SmartRestSocket.cpp Show annotated file Show diff for this revision Revisions of this file
util/SmartRestSocket.h Show annotated file Show diff for this revision Revisions of this file
--- a/operation/ReportThread.h	Fri May 15 15:09:19 2015 +0000
+++ b/operation/ReportThread.h	Mon May 18 09:29:12 2015 +0000
@@ -11,23 +11,22 @@
         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) {
+                short i = count-1;
+                for (; i >= 0; --i) {
                         if (opl[i].identifier == id)
                                 break;
                 }
-                if (i < count) {
+                if (i >= 0) {
                         opl[i].identifier = id;
                         opl[i].state = state;
                         return &opl[i];
                 } else if (count < OPERATION_DICT_SIZE) {
+                        i = count++;
                         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; }
--- a/util/SmartRestSocket.cpp	Fri May 15 15:09:19 2015 +0000
+++ b/util/SmartRestSocket.cpp	Mon May 18 09:29:12 2015 +0000
@@ -2,13 +2,11 @@
 #include "SmartRestSocket.h"
 #include "SmartRestConf.h"
 
-char SmartRestSocket::cachedIP[16] = {0};
 
 int SmartRestSocket::connect()
 {
         extern MDMSerial *pMdm;
         int n = -1;
-        ipLock.lock();
         for (size_t i = 0; i < 3; ++i) {
                 if (cachedIP[0] == 0) {
                         MDMParser::IP ip = pMdm->gethostbyname(srHost);
@@ -28,7 +26,6 @@
                         cachedIP[0] = 0;
                 }
         }
-        ipLock.unlock();
         return n;
 }
 
--- a/util/SmartRestSocket.h	Fri May 15 15:09:19 2015 +0000
+++ b/util/SmartRestSocket.h	Mon May 18 09:29:12 2015 +0000
@@ -1,23 +1,26 @@
 #ifndef SMARTRESTSOCKET_H
 #define SMARTRESTSOCKET_H
 #include "TCPSocketConnection.h"
-#include "rtos.h"
 
 class SmartRestSocket : private TCPSocketConnection
 {
 public:
-        SmartRestSocket(): TCPSocketConnection(), timeout(-1) {}
+        SmartRestSocket(): TCPSocketConnection(), timeout(-1) {
+                memset(cachedIP, 0, sizeof(cachedIP));
+        }
         virtual ~SmartRestSocket() {}
         int sendOnly(char *buf, int size);
         int sendAndReceive(char *buf, int size, int maxSize);
-        void setBlocking(int _timeout = -1) { // timeout in milliseconds
+        /* Set the timeout for the socket.
+           \param _timeout in milliseconds, -1 for no timeout.
+         */
+        void setBlocking(int _timeout = -1) {
                 timeout = _timeout;
         }
 private:
         int connect();
-        static char cachedIP[16];
+        char cachedIP[16];
         int timeout;
-        Mutex ipLock;
 };
 
 #endif /* SMARTRESTSOCKET_H */
\ No newline at end of file