Cumulocity Official / Mbed 2 deprecated MbedSmartRestMain Featured

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Revision:
91:423177e8a401
Parent:
82:ca7430f50b2b
Child:
93:0acd11870c6a
--- a/operation/OperationSupport.cpp	Mon Mar 16 12:12:04 2015 +0000
+++ b/operation/OperationSupport.cpp	Fri Mar 20 13:55:21 2015 +0000
@@ -89,6 +89,10 @@
         if (!operationFromRecord(received, op))
             continue;
         _store.enqueue(op);
+//        _store.takePending(op);
+//        updateOperation(op);
+//        bool b = _executor.executeOperation(op);
+//        _store.markAsDone(op, b);
     }
     _client.stop();
 
@@ -123,14 +127,14 @@
         op.state = OPERATION_PENDING;
     else
         return false;
-    
+
     return true;
 }
 
 bool OperationSupport::updateOperation(OperationStore::Operation& op)
 {
     ComposedRecord record;
-    ParsedRecord received;   
+    ParsedRecord received;
     IntegerValue msgId(111);
     IntegerValue operationId(op.identifier);
     if ((!record.add(msgId)) || (!record.add(operationId)) ||
@@ -141,10 +145,9 @@
         _client.stop();
         return false;
     }
-    
+    puts("UP: sent record!");
     bool found = false;
-    uint8_t ret;
-    while ((ret = _client.receive(received)) == SMARTREST_SUCCESS) {
+    while (_client.receive(received) == SMARTREST_SUCCESS) {
         if ((received.values() == 4) &&
             (received.value(0).valueType() == VALUE_INTEGER) &&
             (received.value(0).integerValue() == 211) &&
@@ -154,8 +157,8 @@
             break;
         }
     }
+    puts("UP: received record!");
     _client.stop();
-
     return found;
 }
 
@@ -185,11 +188,13 @@
         if (!_store.takePending(op)) {
             Thread::yield();
             continue;
-        }
-        
+        }        
 //        printf("Thread 1: %l, %s, %u\r\n", op.identifier, op.descriptor, op.state);
+        puts("Updating op");
         updateOperation(op);
+        puts("Updated op");
         ret = _executor.executeOperation(op);
+        puts("Executed op");
         _store.markAsDone(op, ret);
     }
 }
@@ -222,6 +227,7 @@
             continue;
         }
         
+        puts("Sending aggr");
         if (_client.send(aggr) != SMARTREST_SUCCESS) { }
         _client.stop();
         aggr.clear();        
@@ -297,11 +303,22 @@
             continue;
         }
 
+        puts("Receiving op");
         while (_client.receive(received) == SMARTREST_SUCCESS) {
             if (!operationFromRecord(received, op))
                 continue;
+            puts("Parsed record");
 //            printf("Thread 3: %l, %s, %u\r\n", op.identifier, op.descriptor, op.state);
             _store.enqueue(op);
+            puts("Enqueued op");
+//            _store.takePending(op);
+//            puts("Updating op");
+//            updateOperation(op);
+//            puts("Updated op");
+//            bool ret = _executor.executeOperation(op);
+//            puts("Executed op");
+//            _store.markAsDone(op, ret);
+//            puts("Marked");
         }
 
         //TODO: error checking