use TCP to connect to mbed connector

Fork of mbedConnectorInterfaceWithDM by Doug Anson

Revision:
46:62da4ce20276
Parent:
45:db754b994deb
Child:
54:dfee8691c83a
--- a/source/ConnectorEndpoint.cpp	Wed Jun 15 20:51:13 2016 +0000
+++ b/source/ConnectorEndpoint.cpp	Wed Jun 15 22:40:29 2016 +0000
@@ -114,10 +114,9 @@
 {
     this->m_logger = ep.m_logger;
     this->m_options = ep.m_options;
-    this->m_interface = ep.m_interface;
-    this->m_server_instance = ep.m_server_instance;
-    this->m_object_list = ep.m_object_list;
-    this->m_device_object = ep.m_device_object;
+    this->m_endpoint_interface = ep.m_endpoint_interface;
+    this->m_endpoint_security = ep.m_endpoint_security;
+    this->m_endpoint_object_list = ep.m_endpoint_object_list;
     this->m_device_manager = ep.m_device_manager;
     this->m_connected = ep.m_connected;
     this->m_registered = ep.m_registered;
@@ -127,10 +126,10 @@
 
 // Destructor
 Endpoint::~Endpoint() {
-	if (this->m_interface != NULL)
-		delete this->m_interface;
-	if (this->m_server_instance != NULL)
-		delete this->m_server_instance;
+	if (this->m_endpoint_interface != NULL)
+		delete this->m_endpoint_interface;
+	if (this->m_endpoint_security != NULL)
+		delete this->m_endpoint_security;
 }
 
 // set the device manager
@@ -159,17 +158,22 @@
 }
 
 // get our Server
-M2MSecurity *Endpoint::getServer() {
-	return this->m_server_instance;
+M2MSecurity *Endpoint::getEndpointSecurity() {
+	return this->m_endpoint_security;
 }
 
 // get our ObjectList
-M2MObjectList Endpoint::getObjectList() {
-	return this->m_object_list;
+M2MObjectList Endpoint::getEndpointObjectList() {
+	return this->m_endpoint_object_list;
+}
+
+// get our endpoint interface
+M2MInterface *Endpoint::getEndpointInterface() {
+	return this->m_endpoint_interface;
 }
 
 // mbed-client: create our interface
-void Endpoint::create_interface() {
+void Endpoint::createEndpointInterface() {
 	// get the CoAP listening port
     uint16_t listening_port = (uint16_t)this->m_options->getConnectorPort();
     
@@ -195,7 +199,7 @@
 	if (ip_address_type == M2MInterface::LwIP_IPv6) this->logger()->log("Endpoint: IP Address Type: IPv6");
 	
 	// Create the  M2M Interface instance
-    this->m_interface = M2MInterfaceFactory::create_interface(*this,
+    this->m_endpoint_interface = M2MInterfaceFactory::create_interface(*this,
                                               (char *)this->m_options->getEndpointNodename().c_str(),
                                               (char *)this->m_options->getEndpointType().c_str(),
                                               (int32_t)this->m_options->getLifetime(),
@@ -205,15 +209,15 @@
                                               ip_address_type);									// IPv4 addressing or IPv6 addressing
                                               
 #if defined (MCI_LWIP_INTERFACE)
-	if (__network_interface != NULL && this->m_interface != NULL) {
+	if (__network_interface != NULL && this->m_endpoint_interface != NULL) {
 		this->logger()->log("Endpoint: Morpheus: binding network...");
-		this->m_interface->set_platform_network_handler(__network_interface);
+		this->m_endpoint_interface->set_platform_network_handler(__network_interface);
 	}
 #endif
 }
 
-// mbed-client: create_server_instance()
-M2MSecurity *Endpoint::create_server_instance()  {
+// mbed-client: createEndpointInstance()
+M2MSecurity *Endpoint::createEndpointInstance()  {
         // Creates register server object with mbed device server address and other parameters
         M2MSecurity *server = M2MInterfaceFactory::create_security(M2MSecurity::M2MServer);
         if (server != NULL)  {
@@ -267,27 +271,30 @@
 }
 
 // register the endpoint
-void Endpoint::register_endpoint(M2MSecurity *server_instance, M2MObjectList resources) {
-    if (this->m_interface != NULL && server_instance != NULL && resources.size() > 0)  {
+void Endpoint::register_endpoint(M2MSecurity *endpoint_security, M2MObjectList endpoint_objects) {
+    if (this->m_endpoint_interface != NULL && endpoint_security != NULL && endpoint_objects.size() > 0)  {
     	// register  endpoint
     	this->logger()->log("Registering endpoint...");
-        this->m_interface->register_object(server_instance, resources);
+        this->m_endpoint_interface->register_object(endpoint_security, endpoint_objects);
     }
 }
 
 // re-register the endpoint
 void Endpoint::re_register_endpoint() {
-	if (this->m_interface != NULL)  {
-		this->m_interface->update_registration(this->m_server_instance, this->m_options->getLifetime());
+	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_interface != NULL) {
+	if (this->m_endpoint_interface != NULL) {
 		// de-register endpoint
 		this->logger()->log("De-registering endpoint...");
-		this->m_interface->unregister_object(NULL);		
+		this->m_endpoint_interface->unregister_object(NULL);
+		if (this->m_csi != NULL) {
+			this->m_csi->begin_object_unregistering((void *)this);
+		}		
 	}
 }
 
@@ -374,13 +381,13 @@
 }
 
 // build out the endpoint
-void Endpoint::build_endpoint()
+void Endpoint::buildEndpoint()
 {	
     // initialize as an mbed-client
-    this->create_interface();
+    this->createEndpointInterface();
    
     // Create our server instance
-    this->m_server_instance = this->create_server_instance();
+    this->m_endpoint_security = this->createEndpointInstance();
     
     // We now have to bind our device resources
     if (this->m_device_manager != NULL) {
@@ -396,7 +403,7 @@
 	    	this->logger()->log("Endpoint::build(): plumbing device resources object...");
 	    	
 	    	// push back the device resources object
-	    	this->m_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject());
+	    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getDeviceResourcesObject());
 	    }
 	    else {
 	    	// unable to plumb device manager
@@ -409,7 +416,7 @@
 	    	this->logger()->log("Endpoint::build(): plumbing firmware resources object...");
 	    	
 	    	// push back the firmware resources object
-	    	this->m_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject());
+	    	this->m_endpoint_object_list.push_back((M2MObject *)this->m_options->getFirmwareResourcesObject());
 	    }
 	    else {
 	    	// unable to plumb firmware manager
@@ -449,7 +456,7 @@
     	//this->logger()->log("Endpoint::build(): adding Object Instance with ObjID: %s...",list.at(i).name().c_str());
     	
     	// push back the object instance...
-    	this->m_object_list.push_back((M2MObject *)(list.at(i).ptr()));
+    	this->m_endpoint_object_list.push_back((M2MObject *)(list.at(i).ptr()));
     }
 }