mbed client

Fork of simple-mbed-client by sandbox

Revision:
2:0a015df677a4
Parent:
1:75015f627e89
Child:
3:ce2322965a27
--- a/simple-mbed-client.h	Sun May 15 20:28:07 2016 +0000
+++ b/simple-mbed-client.h	Tue May 17 00:15:11 2016 +0000
@@ -164,21 +164,27 @@
             output.printf("[SMC] [ERROR] No such route (%s)\r\n", route_str.c_str());
             return string();
         }
-    
-        uint8_t* buffIn;
+        
+        // otherwise ask mbed Client...
+        uint8_t* buffIn = NULL;
         uint32_t sizeIn;
         resources[route_str]->get_value(buffIn, sizeIn);
     
-        std::string s((char*)buffIn, sizeIn);
+        string s((char*)buffIn, sizeIn);
         return s;
     }
 
     bool set(string route_str, string v) {
+        // Potentially set() happens in InterruptContext. That's not good.
+        // so we put the set() in an updateQueue and then we'll see...
+        
         if (!resources.count(route_str)) {
             output.printf("[SMC] [ERROR] No such route (%s)\r\n", route_str.c_str());
             return false;
         }
+        
         resources[route_str]->set_value((uint8_t*)v.c_str(), v.length());
+
         return true;
     }
 
@@ -232,11 +238,15 @@
         res->set_value((uint8_t*)v.c_str(), v.length());
     
         string route_str(route);
-        resources.insert(std::pair<string, M2MResource*>(route_str, res));
-    
+        resources.insert(pair<string, M2MResource*>(route_str, res));
+        
         return true;
     }
-
+    
+    void keep_alive() {
+        client->test_update_register();
+    }
+    
 private:
     vector<string> parse_route(const char* route) {
         string s(route);
@@ -255,6 +265,7 @@
     map<string, M2MObject*> objects;
     map<string, M2MObjectInstance*> objectInstances;
     map<string, M2MResource*> resources;
+
     // @todo: write this
     // map<string, FunctionPointerArg1<void, void*> updateValues;
 };
@@ -283,14 +294,11 @@
         simpleClient(aSimpleClient), route(aRoute) {}
 
     int operator=(int newValue) {
-//        printf("newValue %s = %d\n", route.c_str(), newValue);
         simpleClient->set(route, newValue);
         return newValue;
     };
     operator int() const {
-//        printf("receiving a value for %s\n", route.c_str());
         string v = simpleClient->get(route);
-//        printf("string value is %s\n", v.c_str());
         if (v.empty()) return 0;
     
         return atoi((const char*)v.c_str());