mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Files at this revision

API Documentation at this revision

Comitter:
ansond
Date:
Sun Sep 06 03:16:02 2015 +0000
Parent:
60:167e8f021e30
Commit message:
fixes to observation configuration/toggle switch issues.

Changed in this revision

api/OptionsBuilder.cpp Show annotated file Show diff for this revision Revisions of this file
api/ThreadedResourceObserver.cpp Show annotated file Show diff for this revision Revisions of this file
api/TickerResourceObserver.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/api/OptionsBuilder.cpp	Sat Sep 05 20:14:22 2015 +0000
+++ b/api/OptionsBuilder.cpp	Sun Sep 06 03:16:02 2015 +0000
@@ -150,14 +150,14 @@
 OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource)
 {
     // ensure that the boolean isn't mistaken by the compiler for the obs period...
-    return this->addResource(resource,NSP_DEFAULT_OBS_PERIOD,!(((DynamicResource *)resource)->implementsObservation()));
+    return this->addResource(resource,NSP_DEFAULT_OBS_PERIOD,((DynamicResource *)resource)->isObservable());
 }
 
 // add dynamic resource
 OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource,const int sleep_time)
 {
     // ensure that the boolean isn't mistaken by the compiler for the obs period...
-    return this->addResource(resource,sleep_time,!(((DynamicResource *)resource)->implementsObservation()));
+    return this->addResource(resource,sleep_time,((DynamicResource *)resource)->isObservable());
 }
 
 // add dynamic resource
--- a/api/ThreadedResourceObserver.cpp	Sat Sep 05 20:14:22 2015 +0000
+++ b/api/ThreadedResourceObserver.cpp	Sun Sep 06 03:16:02 2015 +0000
@@ -54,7 +54,16 @@
      while(true) {
          Thread::wait(me->getSleepTime());
          if (me->isObserving() == true && me->getResource() != NULL && nsdl_endpoint_is_registered() == true) {
-             me->getResource()->observe(me->getResource()->implementsObservation());
+             //
+             // implementsObservation(): This switch denotes whether this threaded resource generates its own observations or relies on the heartbeat (time-based) mechanism.
+             //   -- if resource itself doesn't implement it, then we can call notify() with the get() on each heartbeat of the threaded resource (see note below)
+             //   -- otherwise, we let the resource itself call observe() as part of its observation implementation
+             //
+             // note: this is independent of whether the resource, when declared, is defined as an observable resource or not.  If not, then notify() wont be called 
+             //       as there will be no observations for this resource regardless of this switch value. 
+             //
+             bool do_notify = !(me->getResource()->implementsObservation());
+             me->getResource()->observe(do_notify);
              //__threaded_led = !__threaded_led;
          }
      }
--- a/api/TickerResourceObserver.cpp	Sat Sep 05 20:14:22 2015 +0000
+++ b/api/TickerResourceObserver.cpp	Sun Sep 06 03:16:02 2015 +0000
@@ -44,7 +44,16 @@
  // notifier
  void TickerResourceObserver::observationNotifier() {
      if (this->isObserving() == true && this->getResource() != NULL && nsdl_endpoint_is_registered() == true) {
-         this->getResource()->observe();
+         //
+         // implementsObservation(): This switch denotes whether this ticker resource generates its own observations or relies on the ticker (time-based) mechanism.
+         //   -- if resource itself doesn't implement it, then we can call notify() with the get() on each heartbeat of the tickered resource (see note below)
+         //   -- otherwise, we let the resource itself call observe() as part of its observation implementation
+         //
+         // note: this is independent of whether the resource, when declared, is defined as an observable resource or not.  If not, then notify() wont be called 
+         //       as there will be no observations for this resource regardless of this switch value. 
+         //
+         bool do_notify = !(this->getResource()->implementsObservation());
+         this->getResource()->observe(do_notify);
          //__ticker_led = !__ticker_led;
      }
  }