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:
27:b8aaf7dc7023
Parent:
22:68fcdc40b397
Child:
33:1d0b855df5a5
--- a/source/OptionsBuilder.cpp	Sun Jun 12 03:18:25 2016 +0000
+++ b/source/OptionsBuilder.cpp	Tue Jun 14 04:01:34 2016 +0000
@@ -28,6 +28,7 @@
 // ResourceObserver support
 #include "mbed-connector-interface/ThreadedResourceObserver.h"
 #include "mbed-connector-interface/TickerResourceObserver.h"
+#include "mbed-connector-interface/MinarResourceObserver.h"
 
 // DEBUG
 #ifndef NDEBUG
@@ -42,13 +43,14 @@
 // Constructor
 OptionsBuilder::OptionsBuilder()
 {
-    this->m_domain           		 = NSP_DOMAIN;
-    this->m_endpoint_type    	 = NSP_ENDPOINT_TYPE;
-    this->m_node_name        	 = NODE_NAME;
-    this->m_reg_update_period = REG_UPDATE_PERIOD_MS;
-    this->m_lifetime  					 = REG_LIFETIME_SEC;
-    this->m_connector_url  		 = string(CONNECTOR_URL);
-    this->m_device_resources.clear();
+    this->m_domain           		= NSP_DOMAIN;
+    this->m_endpoint_type    	 	= NSP_ENDPOINT_TYPE;
+    this->m_node_name        	 	= NODE_NAME;
+    this->m_reg_update_period 		= REG_UPDATE_PERIOD_MS;
+    this->m_lifetime  				= REG_LIFETIME_SEC;
+    this->m_connector_url  		 	= string(CONNECTOR_URL);
+    this->m_device_resources_object = NULL;
+    this->m_firmware_resources_object = NULL;
     this->m_static_resources.clear();
     this->m_dynamic_resources.clear();
     this->m_resource_observers.clear();
@@ -63,7 +65,8 @@
     this->m_reg_update_period = ob.m_reg_update_period;
 	this->m_lifetime = ob.m_lifetime; 
 	this->m_connector_url  = ob.m_connector_url;  
-    this->m_device_resources = ob.m_device_resources;
+    this->m_device_resources_object = ob.m_device_resources_object;
+    this->m_firmware_resources_object = ob.m_firmware_resources_object;
     this->m_static_resources = ob.m_static_resources;
     this->m_dynamic_resources = ob.m_dynamic_resources;
     this->m_resource_observers = ob.m_resource_observers;
@@ -72,7 +75,12 @@
 // Destructor
 OptionsBuilder::~OptionsBuilder()
 {
-	this->m_device_resources.clear();
+	if (this->m_device_resources_object != NULL) {
+		delete this->m_device_resources_object;
+	}
+	if (this->m_firmware_resources_object != NULL) {
+		delete this->m_firmware_resources_object;
+	}
     this->m_static_resources.clear();
     this->m_dynamic_resources.clear();
     this->m_resource_observers.clear();
@@ -122,11 +130,20 @@
     return *this;
 }
 
-// add a device resource
-OptionsBuilder &OptionsBuilder::addResource(const DeviceResource *resource) {
-	if (resource != NULL) {
-        ((DeviceResource *)resource)->setOptions(this);
-        this->m_device_resources.push_back((DeviceResource *)resource);
+// add the device resources object
+OptionsBuilder &OptionsBuilder::setDeviceResourcesObject(const void *device_resources_object) 
+{
+	if (device_resources_object != NULL) {
+        this->m_device_resources_object = (void *)device_resources_object;
+    }
+    return *this;
+}
+
+// add the firmware resources object
+OptionsBuilder &OptionsBuilder::setFirmwareResourcesObject(const void *firmware_resources_object) 
+{
+	if (firmware_resources_object != NULL) {
+        this->m_firmware_resources_object = (void *)firmware_resources_object;
     }
     return *this;
 }
@@ -170,10 +187,14 @@
         ((DynamicResource *)resource)->setOptions(this);
         ((DynamicResource *)resource)->setEndpoint((const void *)this->getEndpoint());
         if (((DynamicResource *)resource)->isObservable() == true && use_observer == true) {
-#ifdef CONNECTOR_USING_THREADS
+#if defined (MCI_MINAR_SCHEDULER) 
+			MinarResourceObserver *observer = new MinarResourceObserver((DynamicResource *)resource,(int)sleep_time);
+#else
+	#ifdef CONNECTOR_USING_THREADS
             ThreadedResourceObserver *observer = new ThreadedResourceObserver((DynamicResource *)resource,(int)sleep_time);
-#else
+	#else
             TickerResourceObserver *observer = new TickerResourceObserver((DynamicResource *)resource,(int)sleep_time);
+	#endif
 #endif
             this->m_resource_observers.push_back(observer);