Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Revision:
96:686ec39400dc
Parent:
95:ee602f51c677
Child:
97:d631edbc157b
diff -r ee602f51c677 -r 686ec39400dc PhilipsLight.cpp
--- a/PhilipsLight.cpp	Fri Mar 14 20:03:00 2014 +0000
+++ b/PhilipsLight.cpp	Fri Mar 14 20:20:32 2014 +0000
@@ -19,20 +19,33 @@
  #include "PhilipsLight.h"
  #include "HTTPTransport.h"
  
+ // HTTP Client
+ HTTPClient _philips_http;
+ 
  // default constructor
  PhilipsLight::PhilipsLight(int id,void *transport,ErrorHandler *error_handler) {
      this->m_id = id;
      this->m_state = PL_DEFAULT_STATE;
      this->m_dim = PL_DEFAULT_DIM;
-     this->m_transport = transport;
      this->m_error_handler = error_handler;
      memset(this->m_url,0,PL_URL_BUFFER_LEN+1);
      memset(this->m_payload,0,PL_PAYLOAD_BUFFER_LEN+1);
      memset(this->m_response,0,PL_RESPONSE_BUFFER_LEN+1);
+     this->initHttpTransport(transport);
  }
  
  // destructor
  PhilipsLight::~PhilipsLight() {
+     HTTPTransport *transport = (HTTPTransport *)this->m_transport;
+     if (transport != NULL) delete transport;
+ }
+ 
+ // initialize the transport
+ void PhilipsLight::initHttpTransport(void *transport) {
+     if (transport != NULL && this->m_transport == NULL) {
+         HTTPTransport *http = (HTTPTransport *)transport;
+         this->m_transport = new HTTPTransport(&_philips_http,this->m_error_handler,http->getEndpoint());
+     }
  }
  
  // turn the light on