mbed Connector Interface simplification API on top of mbed-client

Fork of mbedConnectorInterfaceV3 by Doug Anson

NOTE:

This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!

Revision:
112:b7e348a3363c
Parent:
111:9407038559f7
Child:
113:2a54570db601
--- a/source/ConnectorEndpoint.cpp	Wed Apr 26 04:32:30 2017 +0000
+++ b/source/ConnectorEndpoint.cpp	Wed Apr 26 04:47:57 2017 +0000
@@ -63,7 +63,7 @@
 	}
 	
 	// make sure we have an endpoint...
-	if (__endpoint != NULL && __endpoint->getEndpointInterface() != NULL) {
+	if (__endpoint != NULL) {
 		// set the device manager
 		if (device_manager != NULL) {
 			// device manager has been supplied
@@ -84,18 +84,30 @@
 // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger)
 void Endpoint::start()
 {
-    if (__endpoint != NULL && __endpoint->getEndpointInterface() != NULL) {
+    if (__endpoint != NULL) {
 	    // build out the endpoint with its configuration...
 	    printf("Connector::Endpoint::start: building out endpoint...\r\n");
 	    utils_build_endpoint((void *)__endpoint);
 	    
-	    // finalize the endpoint and start its main loop
-	    printf("Endpoint::start: finalize and run the endpoint main loop..\r\n");
-		net_finalize_and_run_endpoint_main_loop((void *)__endpoint);
+	    // make sure we have an endpoint interface before continuing... 
+	    if (__endpoint != NULL && this->getEndpointInterface() != NULL) {
+		    // finalize the endpoint and start its main loop
+		    printf("Endpoint::start: finalize and run the endpoint main loop..\r\n");
+			net_finalize_and_run_endpoint_main_loop((void *)__endpoint);
+		}
+		else {
+			// not starting the endpoint due to errors
+			printf("Connector::Endpoint::start: Not starting endpoint due to errors (no endpoint interface)... exiting...\r\n");
+			
+			// end in error... 
+			while(true) {
+				Thread::wait(1000);
+			}
+		}
 	}
 	else {
 		// not starting the endpoint due to errors
-		printf("Connector::Endpoint::start: Not starting endpoint due to errors... exiting...\r\n");
+		printf("Connector::Endpoint::start: Not starting endpoint due to errors (no endpoint)... exiting...\r\n");
 		
 		// end in error... 
 		while(true) {
@@ -713,77 +725,84 @@
     // initialize as an mbed-client
     this->createEndpointInterface();
     
-    // Create our server instance
-    this->setSecurityInstance(this->createEndpointSecurityInstance());
-    
-    // We now have to bind our device resources
-    if (this->m_device_manager != NULL) {
-    	// DEBUG
-	    this->logger()->log("Connector::Endpoint::build(): plumbing the device management objects and resources...");
-	    	
-    	// bind the device manager
-	    ((DeviceManager *)this->m_device_manager)->bind();
+    // make sure we have an endpoint interface...
+    if (this->getEndpointInterface() != NULL) {
+	    // Create our server instance
+	    this->setSecurityInstance(this->createEndpointSecurityInstance());
 	    
-	    // push back the Device Resources Object 
-	    if (this->m_options->getDeviceResourcesObject() != NULL) {
+	    // We now have to bind our device resources
+	    if (this->m_device_manager != NULL) {
 	    	// DEBUG
-	    	this->logger()->log("Connector::Endpoint::build(): plumbing device resources object...");
-	    	
-	    	// push back the device resources object
-	    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject());
+		    this->logger()->log("Connector::Endpoint::build(): plumbing the device management objects and resources...");
+		    	
+	    	// bind the device manager
+		    ((DeviceManager *)this->m_device_manager)->bind();
+		    
+		    // push back the Device Resources Object 
+		    if (this->m_options->getDeviceResourcesObject() != NULL) {
+		    	// DEBUG
+		    	this->logger()->log("Connector::Endpoint::build(): plumbing device resources object...");
+		    	
+		    	// push back the device resources object
+		    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject());
+		    }
+		    else {
+		    	// unable to plumb device manager
+		    	this->logger()->log("Connector::Endpoint::build(): Unable to plumb device resources. Not installing device resource object...");
+		    }
+		    
+		    // push back the Firmware Resources Object 
+		    if (this->m_options->getFirmwareResourcesObject() != NULL) {
+		    	// DEBUG
+		    	this->logger()->log("Connector::Endpoint::build(): plumbing firmware resources object...");
+		    	
+		    	// push back the firmware resources object
+		    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject());
+		    }
+		    else {
+		    	// unable to plumb firmware manager
+		    	this->logger()->log("Connector::Endpoint::build(): Unable to plumb firmware resources. Not installing firmware resource object...");
+		    }
 	    }
 	    else {
-	    	// unable to plumb device manager
-	    	this->logger()->log("Connector::Endpoint::build(): Unable to plumb device resources. Not installing device resource object...");
+	    	// no device manager installed
+		    this->logger()->log("Connector::Endpoint::build(): No device manager installed.");
+	    }
+	        
+	    // Loop through Static Resources and bind each of them...
+	    this->logger()->log("Connector::Endpoint::build(): adding static resources...");
+	    const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
+	    for(int i=0; i<(int)static_resources->size(); ++i) {
+	        this->logger()->log("Connector::Endpoint::build(): binding static resource: [%s]...",static_resources->at(i)->getFullName().c_str());
+	        static_resources->at(i)->bind(this);
 	    }
+	
+	    // Loop through Dynamic Resources and bind each of them...
+	    this->logger()->log("Connector::Endpoint::build(): adding dynamic resources...");
+	    const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
+	    for(int i=0; i<(int)dynamic_resources->size(); ++i) {
+	        this->logger()->log("Connector::Endpoint::build(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getFullName().c_str());
+	        dynamic_resources->at(i)->bind(this);
+	    }
+	
+	    // Get the ObjectList from the ObjectInstanceManager...
+	    NamedPointerList list = this->getObjectInstanceManager()->getObjectList();
 	    
-	    // push back the Firmware Resources Object 
-	    if (this->m_options->getFirmwareResourcesObject() != NULL) {
+	    // DEBUG
+	    //this->logger()->log("Endpoint::build(): All Resources bound. Number of Objects in list: %d",list.size());
+	        
+	    // add all of the object instances we have created...
+	    for(int i=0;i<(int)list.size();++i) {
 	    	// DEBUG
-	    	this->logger()->log("Connector::Endpoint::build(): plumbing firmware resources object...");
+	    	//this->logger()->log("Endpoint::build(): adding Object Instance with ObjID: %s...",list.at(i).name().c_str());
 	    	
-	    	// push back the firmware resources object
-	    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject());
-	    }
-	    else {
-	    	// unable to plumb firmware manager
-	    	this->logger()->log("Connector::Endpoint::build(): Unable to plumb firmware resources. Not installing firmware resource object...");
+	    	// push back the object instance...
+	    	this->m_endpoint_object_list.push_back((M2MObject *)(list.at(i).ptr()));
 	    }
     }
     else {
-    	// no device manager installed
-	    this->logger()->log("Connector::Endpoint::build(): No device manager installed.");
-    }
-        
-    // Loop through Static Resources and bind each of them...
-    this->logger()->log("Connector::Endpoint::build(): adding static resources...");
-    const StaticResourcesList *static_resources = this->m_options->getStaticResourceList();
-    for(int i=0; i<(int)static_resources->size(); ++i) {
-        this->logger()->log("Connector::Endpoint::build(): binding static resource: [%s]...",static_resources->at(i)->getFullName().c_str());
-        static_resources->at(i)->bind(this);
-    }
-
-    // Loop through Dynamic Resources and bind each of them...
-    this->logger()->log("Connector::Endpoint::build(): adding dynamic resources...");
-    const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList();
-    for(int i=0; i<(int)dynamic_resources->size(); ++i) {
-        this->logger()->log("Connector::Endpoint::build(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getFullName().c_str());
-        dynamic_resources->at(i)->bind(this);
-    }
-
-    // Get the ObjectList from the ObjectInstanceManager...
-    NamedPointerList list = this->getObjectInstanceManager()->getObjectList();
-    
-    // DEBUG
-    //this->logger()->log("Endpoint::build(): All Resources bound. Number of Objects in list: %d",list.size());
-        
-    // add all of the object instances we have created...
-    for(int i=0;i<(int)list.size();++i) {
-    	// DEBUG
-    	//this->logger()->log("Endpoint::build(): adding Object Instance with ObjID: %s...",list.at(i).name().c_str());
-    	
-    	// push back the object instance...
-    	this->m_endpoint_object_list.push_back((M2MObject *)(list.at(i).ptr()));
+    	// no endpoint interface created
+    	this->logger()->log("Endpoint::build(): ERROR in creating the endpoint interface...");
     }
 }