use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Revision:
45:db754b994deb
Parent:
38:bb6d2be4d54c
--- a/source/ObjectInstanceManager.cpp	Wed Jun 15 19:40:08 2016 +0000
+++ b/source/ObjectInstanceManager.cpp	Wed Jun 15 20:51:13 2016 +0000
@@ -40,6 +40,7 @@
      this->m_logger = (Logger *)logger;
      this->m_ep = (void *)ep;
      this->m_object_list.clear();
+     this->m_instance_number = 0;
 }
 
 // copy constructor
@@ -47,6 +48,7 @@
     this->m_logger = oim.m_logger;
     this->m_ep = oim.m_ep;
     this->m_object_list = oim.m_object_list;
+    this->m_instance_number = oim.m_instance_number;
 }
 
 // destructor
@@ -60,7 +62,7 @@
     M2MObjectInstance *instance = (M2MObjectInstance *)this->getOrCreateInstance(objID,resID);
     if (instance != NULL) {
         // DEBUG
-        this->logger()->log("ObjectInstanceManager: Creating Dynamic Resource: ObjID:%s ResID:%s ResName:%s Type:%d Observable: %d",objID,resID,resName,resType,observable);
+        //this->logger()->log("ObjectInstanceManager: Creating Dynamic Resource: ObjID:%s ResID:%s ResName:%s Type:%d Observable: %d",objID,resID,resName,resType,observable);
     
         // create the resource
         res = (void *)instance->create_dynamic_resource(resID,resName,(M2MResourceInstance::ResourceType)resType,observable);
@@ -74,7 +76,7 @@
     M2MObjectInstance *instance = (M2MObjectInstance *)this->getOrCreateInstance(objID,resID);
     if (instance != NULL) {
         // DEBUG
-        this->logger()->log("ObjectInstanceManager: Creating Static Resource: ObjID:%s ResID:%s ResName:%s Type:%d DataLength: %d",objID,resID,resName,resType,data_length);
+        //this->logger()->log("ObjectInstanceManager: Creating Static Resource: ObjID:%s ResID:%s ResName:%s Type:%d DataLength: %d",objID,resID,resName,resType,data_length);
     
         // create the resource
         res = (void *)instance->create_static_resource(resID,resName,(M2MResourceInstance::ResourceType)resType,(uint8_t *)data,(uint8_t)data_length);
@@ -82,6 +84,11 @@
     return res;  
 }
 
+// Get the instance number of the resource just created
+int ObjectInstanceManager::getLastCreatedInstanceNumber() {
+    return this->m_instance_number;
+}
+
 // create and/or retrieve a given instance
 void *ObjectInstanceManager::getOrCreateInstance(char *objID,char *resID) {
     void *instance = NULL;
@@ -94,12 +101,14 @@
             M2MObject *obj = (M2MObject *)(obj_np->ptr());
             if (obj != NULL) {
                 instance = (void *)obj->create_object_instance();
-                NamedPointer new_inst_np(string(resID),instance);
+                this->m_instance_number = inst_np->index()+1;
+                NamedPointer new_inst_np(string(resID),instance,this->m_instance_number);
                 list->push_back(new_inst_np); 
             }
         }
         else if (list->size() > 0) {
             // 0th instance exists... parent the resource to it...
+            this->m_instance_number = 0;
             instance = (void *)(list->at(0).ptr());
         }
         else {            
@@ -107,7 +116,8 @@
             M2MObject *obj = (M2MObject *)(obj_np->ptr());
             if (obj != NULL) {
                 instance = (void *)obj->create_object_instance();
-                NamedPointer new_inst_np(string(resID),instance);
+                this->m_instance_number = 0;
+                NamedPointer new_inst_np(string(resID),instance,this->m_instance_number);
                 list->push_back(new_inst_np);
             }
         }
@@ -127,7 +137,7 @@
     }
     if (result == NULL) {            
         void *obj = (void *)M2MInterfaceFactory::create_object(objID);
-        NamedPointer new_np(string(objID),obj);
+        NamedPointer new_np(string(objID),obj,0);
         this->m_object_list.push_back(new_np);
         result = this->getNamedPointer(objID,&(this->m_object_list));
     }