Junichi Katsu / Mbed OS mbed-os-example-milkcocoa

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MClient.h Source File

MClient.h

00001 #ifndef _MCLIENT_H_
00002 #define _MCLIENT_H_
00003 
00004 #include "mbed.h"
00005 #include "MQTTClient.h"
00006 #include "MQTTInterface.h"
00007 class MClient
00008 {
00009  public:
00010     typedef void (*messageHandler)(MQTT::MessageData&);
00011 
00012     MClient(MQTTInterface *ipstack) : client(MQTT::Client<MQTTInterface, Countdown>(*ipstack))
00013     {
00014         _ipstack = ipstack;
00015     }
00016     void setDefaultMessageHandler(messageHandler mh)
00017     {
00018         client.setDefaultMessageHandler(mh);
00019     }
00020     int connect(char* host,int port)
00021     {
00022         return _ipstack->connect(host, port);
00023     }
00024     int connect()
00025     {
00026         return client.connect();
00027     }
00028     int connect(MQTTPacket_connectData& options)
00029     {
00030         return client.connect(options);
00031     }
00032     int publish(const char* topicName, MQTT::Message& message)
00033     {
00034         return client.publish(topicName,message);
00035     }
00036     int publish(const char* topicName, void* payload, size_t payloadlen, enum MQTT::QoS qos = MQTT::QOS0, bool retained = false)
00037     {
00038         return client.publish(topicName,payload,payloadlen,qos,retained);
00039     }
00040     int publish(const char* topicName, void* payload, size_t payloadlen, unsigned short& id, enum MQTT::QoS qos = MQTT::QOS1, bool retained = false)
00041     {
00042         return client.publish(topicName,payload,payloadlen,id,qos,retained);
00043     }
00044     int subscribe(const char* topicFilter, enum MQTT::QoS qos, messageHandler mh)
00045     {
00046         return client.subscribe(topicFilter,qos,mh);
00047     }
00048     int unsubscribe(const char* topicFilter)
00049     {
00050         return client.unsubscribe(topicFilter);
00051     }
00052     int disconnect()
00053     {
00054         return client.disconnect();
00055     }
00056     int yield(unsigned long timeout_ms = 1000L)
00057     {
00058         return client.yield(timeout_ms);
00059     }
00060     bool isConnected()
00061     {
00062         return client.isConnected();
00063     }
00064 private:
00065     MQTT::Client<MQTTInterface, Countdown>  client;
00066     MQTTInterface *_ipstack;
00067 };
00068 
00069 #endif