custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Revision:
42:20c375e74e8e
Parent:
19:e2cbaeeea509
Child:
45:65351ebb7c42
--- a/api/OptionsBuilder.cpp	Sat Apr 11 18:42:51 2015 +0000
+++ b/api/OptionsBuilder.cpp	Sat Apr 11 21:14:28 2015 +0000
@@ -43,6 +43,7 @@
     memset(this->m_mac_address,0,NODE_MAC_ADDRESS_LENGTH);
     this->m_static_resources.clear();
     this->m_dynamic_resources.clear();
+    this->m_resource_observers.clear();
 }
 
 // Copy Constructor
@@ -53,6 +54,7 @@
     this->m_endpoint_type = ob.m_endpoint_type;
     this->m_static_resources = ob.m_static_resources;
     this->m_dynamic_resources = ob.m_dynamic_resources;
+    this->m_resource_observers = ob.m_resource_observers;
 }
 
 // Destructor
@@ -60,6 +62,7 @@
 {
     this->m_static_resources.clear();
     this->m_dynamic_resources.clear();
+    this->m_resource_observers.clear();
 }
 
 // set lifetime
@@ -136,14 +139,27 @@
 // add static resource
 OptionsBuilder &OptionsBuilder::addResource(const StaticResource *resource)
 {
-    this->m_static_resources.push_back((StaticResource *)resource);
+    if (resource != NULL) {
+        this->m_static_resources.push_back((StaticResource *)resource);
+    }
     return *this;
 }
 
 // add dynamic resource
-OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource)
+OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource,const int sleep_time,const bool use_observer)
 {
-    this->m_dynamic_resources.push_back((DynamicResource *)resource);
+    if (resource != NULL) {
+        this->m_dynamic_resources.push_back((DynamicResource *)resource);
+        if (((DynamicResource *)resource)->isObservable() == true && use_observer == true) {
+#ifdef CONNECTOR_USING_THREADS
+            ThreadedResourceObserver *observer = new ThreadedResourceObserver((DynamicResource *)resource,(int)sleep_time);
+#else
+            TickerResourceObserver *observer = new TickerResourceObserver((DynamicResource *)resource,(int)sleep_time);
+#endif
+            this->m_resource_observers.push_back(observer);
+            observer->beginObservation();
+        }
+    }
     return *this;
 }
 
@@ -188,4 +204,4 @@
     return (Options *)this;
 }
 
-} // namespace Connector
+} // namespace Connector
\ No newline at end of file