MBED_DEMOS / Mbed 2 deprecated mbed_mqtt_endpoint_ublox_ethernet

Dependencies:   C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed

Revision:
39:bd5b2bcd2dcc
Parent:
36:210f3956038c
Child:
41:36c59c3cd6f2
diff -r 036c8e1026ef -r bd5b2bcd2dcc EmulatedResourceFactory.cpp
--- a/EmulatedResourceFactory.cpp	Sat Mar 01 06:15:30 2014 +0000
+++ b/EmulatedResourceFactory.cpp	Sat Mar 01 07:16:56 2014 +0000
@@ -19,6 +19,31 @@
  // class definition
  #include "EmulatedResourceFactory.h"
  
+ // MBEDEndpoint support
+ #include "MBEDEndpoint.h"
+ 
+ // MBED supports Battery Emulation
+ #include "MBEDBattery.h"
+ 
+ // MBED supports Current Emulation
+ #include "MBEDCurrent.h"
+ 
+ // MBED supports Temperature Sensing
+ #include "MBEDTemperature.h"
+ 
+ // MBED supports GPS Emulation
+ #include "MBEDgps.h"
+ 
+ // MBED supports Voltage Emulation
+ #include "MBEDVoltage.h"
+ 
+ // Initializers
+ void init_battery(Resource *resource) { new MBEDBattery(resource->logger(),resource); }
+ void init_current(Resource *resource) { new MBEDCurrent(resource->logger(),resource); }
+ void init_gps(Resource *resource) { new MBEDgps(resource->logger(),resource); }
+ void init_temperature(Resource *resource) { new MBEDTemperature(resource->logger(),resource); }
+ void init_voltage(Resource *resource) { new MBEDVoltage(resource->logger(),resource); }
+  
  // Ethernet
  #include "EthernetInterface.h"
  extern EthernetInterface ethernet;
@@ -30,7 +55,7 @@
  extern void emulated_light_switch_cb();
  
  // default constructor
- EmulatedResourceFactory::EmulatedResourceFactory(ErrorHandler *error_handler) : ResourceFactory(error_handler) {  
+ EmulatedResourceFactory::EmulatedResourceFactory(ErrorHandler *error_handler,void *endpoint) : ResourceFactory(error_handler,endpoint) {  
  }
  
  // default destructor
@@ -42,8 +67,8 @@
     // create all of the resources we expect for this endpoint
     this->createResource("/dev/addldata","AdditionalData");
     this->createResource("/dev/location",ENDPOINT_LOCATION);
-    this->createResource("/dev/bat","0.0");
-    this->createResource("/sen/I","0.0");
+    this->createResource("/dev/bat","0.0",(resourceInitializer *)&init_battery);
+    this->createResource("/sen/I","0.0",(resourceInitializer *)&init_current);
     this->createResource("/nw/ipaddr",ethernet.getIPAddress());
     this->createResource(endpoint_name,"/lt/0/dim","25",(void *)&emulated_light_dimming_cb);          // Action: dim/brighten light
     this->createResource("/nw/eripaddr","N/A");
@@ -53,13 +78,22 @@
     this->createResource("/gps/fix","1");
     this->createResource("/nw/pipaddr","N/A");
     this->createResource("/nw/prssi","N/A");
-    this->createResource("/sen/temp","0C");
-    this->createResource("/sen/V","5.0");
-    this->createResource("/gps/loc",ENDPOINT_GPS_COORDS);
+    this->createResource("/sen/temp","0.0",(resourceInitializer *)&init_temperature);
+    this->createResource("/sen/V","5.0",(resourceInitializer *)&init_voltage);
+    this->createResource("/gps/loc",ENDPOINT_GPS_COORDS,(resourceInitializer *)&init_gps);
  } 
  
+ void EmulatedResourceFactory::createResource(char *name,char *value) { ResourceFactory::createResource(name,value); }
+ void EmulatedResourceFactory::createResource(char *endpoint_name,char *name,char *value,void *cb) { ResourceFactory::createResource(endpoint_name,name,value,cb); }
+ void EmulatedResourceFactory::createResource(char *name,char *value,resourceInitializer *io) {
+     MBEDEndpoint *endpoint = (MBEDEndpoint *)this->m_endpoint;
+     this->m_list[this->m_count] = new Resource(this->logger(),endpoint->getEndpointName(),name,value,NULL);
+     if (io != NULL) (*io)(this->m_list[this->m_count]);
+     ++this->m_count;
+ }
+  
  // set a resource value (AND trigger the Emulated actions if registered)
- bool EmulatedResourceFactory::setResourceValue(char *name, char *value) {
+ bool EmulatedResourceFactory::setResourceValue3(char *name, char *value) {
      // set the resource value
      bool success = ResourceFactory::setResourceValue(name,value);
      if (success) {