Andrew Reed / Mbed OS CITY1082-i2c_master_wifi_mqtt
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MQTTSNNetworkUDP.h Source File

MQTTSNNetworkUDP.h

00001 /*
00002  * Copyright (c) 2019, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef _MQTTNETWORKUDP_H_
00019 #define _MQTTNETWORKUDP_H_
00020 
00021 #include "UDPSocket.h"
00022 
00023 class MQTTSNNetworkUDP {
00024 public:
00025     MQTTSNNetworkUDP(NetworkInterface *net) :
00026         network(net)
00027     {
00028         socket = new UDPSocket();
00029     }
00030 
00031     ~MQTTSNNetworkUDP()
00032     {
00033         delete socket;
00034     }
00035 
00036     int read(unsigned char *buffer, int len, int timeout)
00037     {
00038         return socket->recv(buffer, len);
00039     }
00040 
00041     int write(unsigned char *buffer, int len, int timeout)
00042     {
00043         return socket->send(buffer, len);
00044     }
00045 
00046     int connect(const char *hostname, int port)
00047     {
00048         socket->open(network);
00049         SocketAddress addr(hostname, port);
00050         return socket->connect(addr);
00051     }
00052 
00053     int disconnect(void)
00054     {
00055         return 0;
00056     }
00057 
00058 private:
00059     NetworkInterface *network;
00060     UDPSocket *socket;
00061 };
00062 
00063 #endif // _MQTTNETWORKUDP_H_