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

Committer:
ansond
Date:
Wed Feb 26 21:48:57 2014 +0000
Revision:
9:ff877db53cfd
Parent:
7:f570eb3f38cd
Child:
10:748fc7052e61
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:ae2a45502448 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:ae2a45502448 2 *
ansond 0:ae2a45502448 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:ae2a45502448 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:ae2a45502448 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:ae2a45502448 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:ae2a45502448 7 * furnished to do so, subject to the following conditions:
ansond 0:ae2a45502448 8 *
ansond 0:ae2a45502448 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:ae2a45502448 10 * substantial portions of the Software.
ansond 0:ae2a45502448 11 *
ansond 0:ae2a45502448 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:ae2a45502448 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:ae2a45502448 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:ae2a45502448 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:ae2a45502448 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:ae2a45502448 17 */
ansond 0:ae2a45502448 18
ansond 0:ae2a45502448 19 #include "HTTPTransport.h"
ansond 0:ae2a45502448 20
ansond 9:ff877db53cfd 21 // Endpoint Support
ansond 9:ff877db53cfd 22 #include "MBEDEndpoint.h"
ansond 9:ff877db53cfd 23
ansond 9:ff877db53cfd 24 // EmulatedResourceFactory support
ansond 9:ff877db53cfd 25 #include "EmulatedResourceFactory.h"
ansond 9:ff877db53cfd 26
ansond 0:ae2a45502448 27 // HTTP Client
ansond 0:ae2a45502448 28 HTTPClient _http;
ansond 0:ae2a45502448 29
ansond 0:ae2a45502448 30 // default constructor
ansond 7:f570eb3f38cd 31 HTTPTransport::HTTPTransport(ErrorHandler *error_handler,void *endpoint) : Transport(error_handler,endpoint) {
ansond 0:ae2a45502448 32 this->m_http = &_http;
ansond 0:ae2a45502448 33 this->m_connected = true;
ansond 0:ae2a45502448 34 }
ansond 0:ae2a45502448 35
ansond 0:ae2a45502448 36 // default destructor
ansond 0:ae2a45502448 37 HTTPTransport::~HTTPTransport() {
ansond 0:ae2a45502448 38 }
ansond 0:ae2a45502448 39
ansond 9:ff877db53cfd 40 // Load up our endpoint into the IOC
ansond 9:ff877db53cfd 41 bool HTTPTransport::loadEndpoint() {
ansond 9:ff877db53cfd 42 bool success = false;
ansond 9:ff877db53cfd 43
ansond 9:ff877db53cfd 44 return success;
ansond 9:ff877db53cfd 45 }
ansond 9:ff877db53cfd 46
ansond 9:ff877db53cfd 47 // update our endpoint with the IOC
ansond 9:ff877db53cfd 48 bool HTTPTransport::updateEndpoint() {
ansond 9:ff877db53cfd 49 bool success = false;
ansond 9:ff877db53cfd 50
ansond 9:ff877db53cfd 51 return success;
ansond 9:ff877db53cfd 52 }
ansond 9:ff877db53cfd 53
ansond 0:ae2a45502448 54 // connect up HTTP
ansond 0:ae2a45502448 55 bool HTTPTransport::connect() { return this->m_connected; }
ansond 0:ae2a45502448 56
ansond 0:ae2a45502448 57 // disconnect from HTTP
ansond 0:ae2a45502448 58 bool HTTPTransport::disconnect() { return true; }
ansond 0:ae2a45502448 59
ansond 0:ae2a45502448 60 // HTTP Get
ansond 0:ae2a45502448 61 bool HTTPTransport::httpGet(char *url,char *result,int result_length) {
ansond 0:ae2a45502448 62 return (this->m_http->get(url,result,result_length) == 0);
ansond 0:ae2a45502448 63 }
ansond 0:ae2a45502448 64
ansond 0:ae2a45502448 65 // HTTP Put
ansond 0:ae2a45502448 66 bool HTTPTransport::httpPut(char *url,char *data,int data_length,char *result,int result_length) {
ansond 0:ae2a45502448 67 HTTPText input(data,data_length);
ansond 0:ae2a45502448 68 HTTPText output(result,result_length);
ansond 0:ae2a45502448 69 return (this->m_http->put(url,output,&input) != 0);
ansond 0:ae2a45502448 70 }
ansond 0:ae2a45502448 71
ansond 0:ae2a45502448 72 // HTTP Post
ansond 0:ae2a45502448 73 bool HTTPTransport::httpPost(char *url,char *data,int data_length,char *result,int result_length) {
ansond 0:ae2a45502448 74 HTTPText input(data,data_length);
ansond 0:ae2a45502448 75 HTTPText output(result,result_length);
ansond 0:ae2a45502448 76 return (this->m_http->post(url,output,&input) != 0);
ansond 0:ae2a45502448 77 }
ansond 0:ae2a45502448 78
ansond 0:ae2a45502448 79 // HTTP Delete
ansond 0:ae2a45502448 80 bool HTTPTransport::httpDelete(char *url,char *data,int data_length) {
ansond 0:ae2a45502448 81 HTTPText input(data,data_length);
ansond 0:ae2a45502448 82 return (this->m_http->del(url,&input) != 0);
ansond 0:ae2a45502448 83 }