Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466

Dependencies:   ssd1331

Committer:
kadonotakashi
Date:
Thu Oct 11 02:27:46 2018 +0000
Revision:
3:f3764f852aa8
Parent:
0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kadonotakashi 0:8fdf9a60065b 1
kadonotakashi 0:8fdf9a60065b 2 /* SocketAddress
kadonotakashi 0:8fdf9a60065b 3 * Copyright (c) 2015 ARM Limited
kadonotakashi 0:8fdf9a60065b 4 *
kadonotakashi 0:8fdf9a60065b 5 * Licensed under the Apache License, Version 2.0 (the "License");
kadonotakashi 0:8fdf9a60065b 6 * you may not use this file except in compliance with the License.
kadonotakashi 0:8fdf9a60065b 7 * You may obtain a copy of the License at
kadonotakashi 0:8fdf9a60065b 8 *
kadonotakashi 0:8fdf9a60065b 9 * http://www.apache.org/licenses/LICENSE-2.0
kadonotakashi 0:8fdf9a60065b 10 *
kadonotakashi 0:8fdf9a60065b 11 * Unless required by applicable law or agreed to in writing, software
kadonotakashi 0:8fdf9a60065b 12 * distributed under the License is distributed on an "AS IS" BASIS,
kadonotakashi 0:8fdf9a60065b 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kadonotakashi 0:8fdf9a60065b 14 * See the License for the specific language governing permissions and
kadonotakashi 0:8fdf9a60065b 15 * limitations under the License.
kadonotakashi 0:8fdf9a60065b 16 */
kadonotakashi 0:8fdf9a60065b 17
kadonotakashi 0:8fdf9a60065b 18 #ifndef SOCKET_ADDRESS_H
kadonotakashi 0:8fdf9a60065b 19 #define SOCKET_ADDRESS_H
kadonotakashi 0:8fdf9a60065b 20
kadonotakashi 0:8fdf9a60065b 21 #include "nsapi_types.h"
kadonotakashi 0:8fdf9a60065b 22 #include "mbed_toolchain.h"
kadonotakashi 0:8fdf9a60065b 23
kadonotakashi 0:8fdf9a60065b 24 // Predeclared classes
kadonotakashi 0:8fdf9a60065b 25 class NetworkStack;
kadonotakashi 0:8fdf9a60065b 26 class NetworkInterface;
kadonotakashi 0:8fdf9a60065b 27
kadonotakashi 0:8fdf9a60065b 28
kadonotakashi 0:8fdf9a60065b 29 /** SocketAddress class
kadonotakashi 0:8fdf9a60065b 30 *
kadonotakashi 0:8fdf9a60065b 31 * Representation of an IP address and port pair.
kadonotakashi 0:8fdf9a60065b 32 * @addtogroup netsocket
kadonotakashi 0:8fdf9a60065b 33 */
kadonotakashi 0:8fdf9a60065b 34 class SocketAddress {
kadonotakashi 0:8fdf9a60065b 35 public:
kadonotakashi 0:8fdf9a60065b 36 /** Create a SocketAddress from a hostname and port
kadonotakashi 0:8fdf9a60065b 37 *
kadonotakashi 0:8fdf9a60065b 38 * The hostname may be either a domain name or an IP address. If the
kadonotakashi 0:8fdf9a60065b 39 * hostname is an IP address, no network transactions will be performed.
kadonotakashi 0:8fdf9a60065b 40 *
kadonotakashi 0:8fdf9a60065b 41 * On failure, the IP address and port will be set to zero
kadonotakashi 0:8fdf9a60065b 42 *
kadonotakashi 0:8fdf9a60065b 43 * @param stack Network stack to use for DNS resolution
kadonotakashi 0:8fdf9a60065b 44 * @param host Hostname to resolve
kadonotakashi 0:8fdf9a60065b 45 * @param port Optional 16-bit port
kadonotakashi 0:8fdf9a60065b 46 * @deprecated
kadonotakashi 0:8fdf9a60065b 47 * Constructors hide possible errors. Replaced by
kadonotakashi 0:8fdf9a60065b 48 * NetworkInterface::gethostbyname.
kadonotakashi 0:8fdf9a60065b 49 */
kadonotakashi 0:8fdf9a60065b 50 template <typename S>
kadonotakashi 0:8fdf9a60065b 51 MBED_DEPRECATED_SINCE("mbed-os-5.1.3",
kadonotakashi 0:8fdf9a60065b 52 "Constructors hide possible errors. Replaced by "
kadonotakashi 0:8fdf9a60065b 53 "NetworkInterface::gethostbyname.")
kadonotakashi 0:8fdf9a60065b 54 SocketAddress(S *stack, const char *host, uint16_t port = 0)
kadonotakashi 0:8fdf9a60065b 55 {
kadonotakashi 0:8fdf9a60065b 56 _SocketAddress(nsapi_create_stack(stack), host, port);
kadonotakashi 0:8fdf9a60065b 57 }
kadonotakashi 0:8fdf9a60065b 58
kadonotakashi 0:8fdf9a60065b 59 /** Create a SocketAddress from a raw IP address and port
kadonotakashi 0:8fdf9a60065b 60 *
kadonotakashi 0:8fdf9a60065b 61 * @param addr Raw IP address
kadonotakashi 0:8fdf9a60065b 62 * @param port Optional 16-bit port
kadonotakashi 0:8fdf9a60065b 63 */
kadonotakashi 0:8fdf9a60065b 64 SocketAddress(nsapi_addr_t addr = nsapi_addr_t(), uint16_t port = 0);
kadonotakashi 0:8fdf9a60065b 65
kadonotakashi 0:8fdf9a60065b 66 /** Create a SocketAddress from an IP address and port
kadonotakashi 0:8fdf9a60065b 67 *
kadonotakashi 0:8fdf9a60065b 68 * @param addr Null-terminated representation of the IP address
kadonotakashi 0:8fdf9a60065b 69 * @param port Optional 16-bit port
kadonotakashi 0:8fdf9a60065b 70 */
kadonotakashi 0:8fdf9a60065b 71 SocketAddress(const char *addr, uint16_t port = 0);
kadonotakashi 0:8fdf9a60065b 72
kadonotakashi 0:8fdf9a60065b 73 /** Create a SocketAddress from raw IP bytes, IP version, and port
kadonotakashi 0:8fdf9a60065b 74 *
kadonotakashi 0:8fdf9a60065b 75 * @param bytes Raw IP address in big-endian order
kadonotakashi 0:8fdf9a60065b 76 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6
kadonotakashi 0:8fdf9a60065b 77 * @param port Optional 16-bit port
kadonotakashi 0:8fdf9a60065b 78 */
kadonotakashi 0:8fdf9a60065b 79 SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port = 0);
kadonotakashi 0:8fdf9a60065b 80
kadonotakashi 0:8fdf9a60065b 81 /** Create a SocketAddress from another SocketAddress
kadonotakashi 0:8fdf9a60065b 82 *
kadonotakashi 0:8fdf9a60065b 83 * @param addr SocketAddress to copy
kadonotakashi 0:8fdf9a60065b 84 */
kadonotakashi 0:8fdf9a60065b 85 SocketAddress(const SocketAddress &addr);
kadonotakashi 0:8fdf9a60065b 86
kadonotakashi 0:8fdf9a60065b 87 /** Destructor */
kadonotakashi 0:8fdf9a60065b 88 ~SocketAddress();
kadonotakashi 0:8fdf9a60065b 89
kadonotakashi 0:8fdf9a60065b 90 /** Set the IP address
kadonotakashi 0:8fdf9a60065b 91 *
kadonotakashi 0:8fdf9a60065b 92 * @param addr Null-terminated represention of the IP address
kadonotakashi 0:8fdf9a60065b 93 * @return True if address is a valid representation of an IP address,
kadonotakashi 0:8fdf9a60065b 94 * otherwise False and SocketAddress is set to null
kadonotakashi 0:8fdf9a60065b 95 */
kadonotakashi 0:8fdf9a60065b 96 bool set_ip_address(const char *addr);
kadonotakashi 0:8fdf9a60065b 97
kadonotakashi 0:8fdf9a60065b 98 /** Set the raw IP bytes and IP version
kadonotakashi 0:8fdf9a60065b 99 *
kadonotakashi 0:8fdf9a60065b 100 * @param bytes Raw IP address in big-endian order
kadonotakashi 0:8fdf9a60065b 101 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6
kadonotakashi 0:8fdf9a60065b 102 */
kadonotakashi 0:8fdf9a60065b 103 void set_ip_bytes(const void *bytes, nsapi_version_t version);
kadonotakashi 0:8fdf9a60065b 104
kadonotakashi 0:8fdf9a60065b 105 /** Set the raw IP address
kadonotakashi 0:8fdf9a60065b 106 *
kadonotakashi 0:8fdf9a60065b 107 * @param addr Raw IP address
kadonotakashi 0:8fdf9a60065b 108 */
kadonotakashi 0:8fdf9a60065b 109 void set_addr(nsapi_addr_t addr);
kadonotakashi 0:8fdf9a60065b 110
kadonotakashi 0:8fdf9a60065b 111 /** Set the port
kadonotakashi 0:8fdf9a60065b 112 *
kadonotakashi 0:8fdf9a60065b 113 * @param port 16-bit port
kadonotakashi 0:8fdf9a60065b 114 */
kadonotakashi 0:8fdf9a60065b 115 void set_port(uint16_t port);
kadonotakashi 0:8fdf9a60065b 116
kadonotakashi 0:8fdf9a60065b 117 /** Get the human-readable IP address
kadonotakashi 0:8fdf9a60065b 118 *
kadonotakashi 0:8fdf9a60065b 119 * Allocates memory for a string and converts binary address to
kadonotakashi 0:8fdf9a60065b 120 * human-readable format. String is freed in the destructor.
kadonotakashi 0:8fdf9a60065b 121 *
kadonotakashi 0:8fdf9a60065b 122 * @return Null-terminated representation of the IP Address
kadonotakashi 0:8fdf9a60065b 123 */
kadonotakashi 0:8fdf9a60065b 124 const char *get_ip_address() const;
kadonotakashi 0:8fdf9a60065b 125
kadonotakashi 0:8fdf9a60065b 126 /* Get the raw IP bytes
kadonotakashi 0:8fdf9a60065b 127 *
kadonotakashi 0:8fdf9a60065b 128 * @return Raw IP address in big-endian order
kadonotakashi 0:8fdf9a60065b 129 */
kadonotakashi 0:8fdf9a60065b 130 const void *get_ip_bytes() const;
kadonotakashi 0:8fdf9a60065b 131
kadonotakashi 0:8fdf9a60065b 132 /** Get the IP address version
kadonotakashi 0:8fdf9a60065b 133 *
kadonotakashi 0:8fdf9a60065b 134 * @return IP address version, NSAPI_IPv4 or NSAPI_IPv6
kadonotakashi 0:8fdf9a60065b 135 */
kadonotakashi 0:8fdf9a60065b 136 nsapi_version_t get_ip_version() const;
kadonotakashi 0:8fdf9a60065b 137
kadonotakashi 0:8fdf9a60065b 138 /** Get the raw IP address
kadonotakashi 0:8fdf9a60065b 139 *
kadonotakashi 0:8fdf9a60065b 140 * @return Raw IP address
kadonotakashi 0:8fdf9a60065b 141 */
kadonotakashi 0:8fdf9a60065b 142 nsapi_addr_t get_addr() const;
kadonotakashi 0:8fdf9a60065b 143
kadonotakashi 0:8fdf9a60065b 144 /** Get the port
kadonotakashi 0:8fdf9a60065b 145 *
kadonotakashi 0:8fdf9a60065b 146 * @return The 16-bit port
kadonotakashi 0:8fdf9a60065b 147 */
kadonotakashi 0:8fdf9a60065b 148 uint16_t get_port() const;
kadonotakashi 0:8fdf9a60065b 149
kadonotakashi 0:8fdf9a60065b 150 /** Test if address is zero
kadonotakashi 0:8fdf9a60065b 151 *
kadonotakashi 0:8fdf9a60065b 152 * @return True if address is not zero
kadonotakashi 0:8fdf9a60065b 153 */
kadonotakashi 0:8fdf9a60065b 154 operator bool() const;
kadonotakashi 0:8fdf9a60065b 155
kadonotakashi 0:8fdf9a60065b 156 /** Copy address from another SocketAddress
kadonotakashi 0:8fdf9a60065b 157 *
kadonotakashi 0:8fdf9a60065b 158 * @param addr SocketAddress to copy
kadonotakashi 0:8fdf9a60065b 159 */
kadonotakashi 0:8fdf9a60065b 160 SocketAddress &operator=(const SocketAddress &addr);
kadonotakashi 0:8fdf9a60065b 161
kadonotakashi 0:8fdf9a60065b 162 /** Compare two addresses for equality
kadonotakashi 0:8fdf9a60065b 163 *
kadonotakashi 0:8fdf9a60065b 164 * @return True if both addresses are equal
kadonotakashi 0:8fdf9a60065b 165 */
kadonotakashi 0:8fdf9a60065b 166 friend bool operator==(const SocketAddress &a, const SocketAddress &b);
kadonotakashi 0:8fdf9a60065b 167
kadonotakashi 0:8fdf9a60065b 168 /** Compare two addresses for equality
kadonotakashi 0:8fdf9a60065b 169 *
kadonotakashi 0:8fdf9a60065b 170 * @return True if both addresses are not equal
kadonotakashi 0:8fdf9a60065b 171 */
kadonotakashi 0:8fdf9a60065b 172 friend bool operator!=(const SocketAddress &a, const SocketAddress &b);
kadonotakashi 0:8fdf9a60065b 173
kadonotakashi 0:8fdf9a60065b 174 private:
kadonotakashi 0:8fdf9a60065b 175 void _SocketAddress(NetworkStack *iface, const char *host, uint16_t port);
kadonotakashi 0:8fdf9a60065b 176
kadonotakashi 0:8fdf9a60065b 177 mutable char *_ip_address;
kadonotakashi 0:8fdf9a60065b 178 nsapi_addr_t _addr;
kadonotakashi 0:8fdf9a60065b 179 uint16_t _port;
kadonotakashi 0:8fdf9a60065b 180 };
kadonotakashi 0:8fdf9a60065b 181
kadonotakashi 0:8fdf9a60065b 182
kadonotakashi 0:8fdf9a60065b 183 #endif
kadonotakashi 0:8fdf9a60065b 184
kadonotakashi 0:8fdf9a60065b 185 /** @}*/