mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface

Revision:
1:16f0fb5b8d97
Parent:
0:1f1f55e73248
Child:
2:1a7a292555d1
--- a/source/ConnectorEndpoint.cpp	Fri Feb 19 17:32:14 2016 +0000
+++ b/source/ConnectorEndpoint.cpp	Sun Feb 21 05:06:13 2016 +0000
@@ -36,37 +36,42 @@
 #define DEBUG_OUT(...) /* nothing */
 #endif
 
-// our endpoint instance (Utils.cpp) 
-extern Connector::Endpoint *__endpoint;
+// our endpoint instance
+static Connector::Endpoint *__endpoint = NULL;
 
 // Connector namespace
 namespace Connector {
 
 // STATIC: Plumb the network
 void Endpoint::plumbNetwork(bool canActAsRouterNode) {
+	if (__endpoint == NULL) {
+		// initialize our endpoint instance
+		DEBUG_OUT("Endpoint::plumbNetwork: initializing endpoint instance...\r\n");
+		__endpoint = (Connector::Endpoint *)utils_init_endpoint(canActAsRouterNode);
+	}
+	
 	// plumb network
 	DEBUG_OUT("Endpoint::plumbNetwork: plumbing network...\r\n");
-	net_stubs_pre_plumb_network(canActAsRouterNode);
+	net_stubs_plumb_network((void *)__endpoint);
 
     // configure the endpoint now...
     DEBUG_OUT("Endpoint::plumbNetwork: configuring endpoint...\r\n");
-    utils_configure_endpoint();
+    utils_configure_endpoint((void *)__endpoint);
 }
 
 // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger)
-void Endpoint::start()
-{
-    // initialize our endpoint and register it
-    DEBUG_OUT("Endpoint::start: creating endpoint instance and registering with Connector...\r\n");
-    utils_init_and_register_endpoint();
+void Endpoint::start() {
+    // complete our registration setup...
+    DEBUG_OUT("Endpoint::start: registering endpoint with Connector...\r\n");
+    utils_register_endpoint((void *)__endpoint);
     
-    // complete our registration setup...
-   DEBUG_OUT("Endpoint::start: initializing main loop for endpoint...\r\n"); 
-    net_stubs_create_main_loop(__endpoint,__endpoint->getServer(),__endpoint->getObjectList());
+    // Initialize our main loop...
+    DEBUG_OUT("Endpoint::start: initializing main loop for endpoint...\r\n"); 
+    net_stubs_create_main_loop(__endpoint);
     
     // Begin the main loop
     DEBUG_OUT("Endpoint::start: entering main loop in endpoint...\r\n");
-    net_stubs_begin_main_loop(__endpoint,__endpoint->getOptions()->getRegUpdatePeriod());
+    net_stubs_begin_main_loop(__endpoint);
 }
 
 // Constructor
@@ -95,6 +100,16 @@
 		delete this->m_server_instance;
 }
 
+// router node behavior setting
+void Endpoint::asRouterNode(bool canActAsRouterNode) {
+	this->m_canActAsRouterNode = canActAsRouterNode;
+}
+
+// set our Options
+void Endpoint::setOptions(Options *options) {
+	this->m_options = options;
+}
+
 // get our Options
 Options *Endpoint::getOptions() {
 	return this->m_options;