use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Revision:
76:7f55e1c0635d
Parent:
75:9152ea6b4c59
Child:
77:cee832ba6dd0
diff -r 9152ea6b4c59 -r 7f55e1c0635d source/ConnectorEndpoint.cpp
--- a/source/ConnectorEndpoint.cpp	Fri Nov 04 22:09:00 2016 +0000
+++ b/source/ConnectorEndpoint.cpp	Fri Nov 04 22:28:13 2016 +0000
@@ -320,6 +320,92 @@
                 break;
         }
 }
+// re-register the endpoint
+void Endpoint::re_register_endpoint() {
+	if (this->m_endpoint_interface != NULL)  {
+#ifdef ENABLE_MBED_CLOUD_SUPPORT
+#else
+		this->m_endpoint_interface->update_registration(this->m_endpoint_security,this->m_options->getLifetime());
+#endif
+  	}  
+}
+
+// de-register endpoint 
+void Endpoint::de_register_endpoint(void) {
+	if (this->m_endpoint_interface != NULL) {
+#ifdef ENABLE_MBED_CLOUD_SUPPORT
+		this->m_endpoint_interface->close();
+#else
+		// de-register endpoint
+		this->logger()->log("Connector::Endpoint: de-registering endpoint...");
+		if (this->m_csi != NULL) {
+			this->m_csi->begin_object_unregistering((void *)this);
+		}
+		else {
+			this->m_endpoint_interface->unregister_object(NULL);
+		}
+#endif		
+	}
+}
+
+#ifdef ENABLE_MBED_CLOUD_SUPPORT
+// register the endpoint
+void Endpoint::register_endpoint(M2MObjectList endpoint_objects) {
+	if (this->m_endpoint_interface != NULL) {
+		this->m_endpoint_interface->add_objects(endpoint_objects);
+	}
+}
+
+// object registered
+void Endpoint::object_registered()  {
+	this->logger()->log("Connector::Endpoint: endpoint registered.");
+	this->m_connected = true;
+	this->m_registered = true;
+	if (this->m_csi != NULL) {
+		this->m_csi->object_registered((void *)this);
+	}
+}
+
+// registration updated
+void Endpoint::registration_updated()  {
+	this->logger()->log("Connector::Endpoint: endpoint re-registered.");
+	this->m_connected = true;
+	this->m_registered = true;
+	if (this->m_csi != NULL) {
+		this->m_csi->registration_updated((void *)this);
+	}
+}
+
+// object unregistered
+void Endpoint::object_unregistered()  {
+	// DEBUG
+	this->logger()->log("Connector::Endpoint: endpoint de-registered.");
+	
+	// no longer connected/registered
+	this->m_registered = false;
+	this->m_connected = false;
+	
+	// stop all observers...
+	this->stopObservations();
+	
+	// invoke ConnectionHandler if we have one...
+	if (this->m_csi != NULL) {
+		this->m_csi->object_unregistered((void *)this); 
+	}
+	
+	// halt the main event loop... we are done. 
+	net_shutdown_endpoint();
+}
+
+// bootstrap done
+void Endpoint::bootstrap_done() {
+	this->logger()->log("Connector::Endpoint: endpoint bootstrapped.");
+	if (this->m_csi != NULL) {
+		this->m_csi->bootstrapped((void *)this);
+	}
+}
+	
+#else
 
 // register the endpoint
 void Endpoint::register_endpoint(M2MSecurity *endpoint_security, M2MObjectList endpoint_objects) {
@@ -330,25 +416,6 @@
     }
 }
 
-// re-register the endpoint
-void Endpoint::re_register_endpoint() {
-	if (this->m_endpoint_interface != NULL)  {
-		this->m_endpoint_interface->update_registration(this->m_endpoint_security,this->m_options->getLifetime());
-  	}  
-}
-
-// de-register endpoint 
-void Endpoint::de_register_endpoint(void) {
-	if (this->m_endpoint_interface != NULL) {
-		// de-register endpoint
-		this->logger()->log("Connector::Endpoint: de-registering endpoint...");
-		this->m_endpoint_interface->unregister_object(NULL);
-		if (this->m_csi != NULL) {
-			this->m_csi->begin_object_unregistering((void *)this);
-		}		
-	}
-}
-
 // object registered
 void Endpoint::object_registered(M2MSecurity *security, const M2MServer &server)  {	    	           
 	this->logger()->log("Connector::Endpoint: endpoint registered.");
@@ -397,6 +464,7 @@
 		this->m_csi->bootstrapped((void *)this,(void *)server);
 	}
 }
+#endif 
 
 // resource value updated
 void Endpoint::value_updated(M2MBase *base, M2MBase::BaseType type) {