mbed OS5に対応したMilkcocoaライブラリのテストバージョンです。

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

Committer:
jksoft
Date:
Tue Jan 24 13:41:36 2017 +0000
Revision:
24:6ba1245bf049
??????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 24:6ba1245bf049 1 #ifndef _MCLIENT_H_
jksoft 24:6ba1245bf049 2 #define _MCLIENT_H_
jksoft 24:6ba1245bf049 3
jksoft 24:6ba1245bf049 4 #include "mbed.h"
jksoft 24:6ba1245bf049 5 #include "MQTTClient.h"
jksoft 24:6ba1245bf049 6 #include "MQTTInterface.h"
jksoft 24:6ba1245bf049 7 class MClient
jksoft 24:6ba1245bf049 8 {
jksoft 24:6ba1245bf049 9 public:
jksoft 24:6ba1245bf049 10 typedef void (*messageHandler)(MQTT::MessageData&);
jksoft 24:6ba1245bf049 11
jksoft 24:6ba1245bf049 12 MClient(MQTTInterface *ipstack) : client(MQTT::Client<MQTTInterface, Countdown>(*ipstack))
jksoft 24:6ba1245bf049 13 {
jksoft 24:6ba1245bf049 14 _ipstack = ipstack;
jksoft 24:6ba1245bf049 15 }
jksoft 24:6ba1245bf049 16 void setDefaultMessageHandler(messageHandler mh)
jksoft 24:6ba1245bf049 17 {
jksoft 24:6ba1245bf049 18 client.setDefaultMessageHandler(mh);
jksoft 24:6ba1245bf049 19 }
jksoft 24:6ba1245bf049 20 int connect(char* host,int port)
jksoft 24:6ba1245bf049 21 {
jksoft 24:6ba1245bf049 22 return _ipstack->connect(host, port);
jksoft 24:6ba1245bf049 23 }
jksoft 24:6ba1245bf049 24 int connect()
jksoft 24:6ba1245bf049 25 {
jksoft 24:6ba1245bf049 26 return client.connect();
jksoft 24:6ba1245bf049 27 }
jksoft 24:6ba1245bf049 28 int connect(MQTTPacket_connectData& options)
jksoft 24:6ba1245bf049 29 {
jksoft 24:6ba1245bf049 30 return client.connect(options);
jksoft 24:6ba1245bf049 31 }
jksoft 24:6ba1245bf049 32 int publish(const char* topicName, MQTT::Message& message)
jksoft 24:6ba1245bf049 33 {
jksoft 24:6ba1245bf049 34 return client.publish(topicName,message);
jksoft 24:6ba1245bf049 35 }
jksoft 24:6ba1245bf049 36 int publish(const char* topicName, void* payload, size_t payloadlen, enum MQTT::QoS qos = MQTT::QOS0, bool retained = false)
jksoft 24:6ba1245bf049 37 {
jksoft 24:6ba1245bf049 38 return client.publish(topicName,payload,payloadlen,qos,retained);
jksoft 24:6ba1245bf049 39 }
jksoft 24:6ba1245bf049 40 int publish(const char* topicName, void* payload, size_t payloadlen, unsigned short& id, enum MQTT::QoS qos = MQTT::QOS1, bool retained = false)
jksoft 24:6ba1245bf049 41 {
jksoft 24:6ba1245bf049 42 return client.publish(topicName,payload,payloadlen,id,qos,retained);
jksoft 24:6ba1245bf049 43 }
jksoft 24:6ba1245bf049 44 int subscribe(const char* topicFilter, enum MQTT::QoS qos, messageHandler mh)
jksoft 24:6ba1245bf049 45 {
jksoft 24:6ba1245bf049 46 return client.subscribe(topicFilter,qos,mh);
jksoft 24:6ba1245bf049 47 }
jksoft 24:6ba1245bf049 48 int unsubscribe(const char* topicFilter)
jksoft 24:6ba1245bf049 49 {
jksoft 24:6ba1245bf049 50 return client.unsubscribe(topicFilter);
jksoft 24:6ba1245bf049 51 }
jksoft 24:6ba1245bf049 52 int disconnect()
jksoft 24:6ba1245bf049 53 {
jksoft 24:6ba1245bf049 54 return client.disconnect();
jksoft 24:6ba1245bf049 55 }
jksoft 24:6ba1245bf049 56 int yield(unsigned long timeout_ms = 1000L)
jksoft 24:6ba1245bf049 57 {
jksoft 24:6ba1245bf049 58 return client.yield(timeout_ms);
jksoft 24:6ba1245bf049 59 }
jksoft 24:6ba1245bf049 60 bool isConnected()
jksoft 24:6ba1245bf049 61 {
jksoft 24:6ba1245bf049 62 return client.isConnected();
jksoft 24:6ba1245bf049 63 }
jksoft 24:6ba1245bf049 64 private:
jksoft 24:6ba1245bf049 65 MQTT::Client<MQTTInterface, Countdown> client;
jksoft 24:6ba1245bf049 66 MQTTInterface *_ipstack;
jksoft 24:6ba1245bf049 67 };
jksoft 24:6ba1245bf049 68
jksoft 24:6ba1245bf049 69 #endif