mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 17 23:23:45 2019 +0000
Revision:
0:5b88d5760320
mbed-os5 only for TYBLE16

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /*
kenjiArai 0:5b88d5760320 2 * Copyright (c) 2018 ARM Limited
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * Licensed under the Apache License, Version 2.0 (the "License");
kenjiArai 0:5b88d5760320 5 * you may not use this file except in compliance with the License.
kenjiArai 0:5b88d5760320 6 * You may obtain a copy of the License at
kenjiArai 0:5b88d5760320 7 *
kenjiArai 0:5b88d5760320 8 * http://www.apache.org/licenses/LICENSE-2.0
kenjiArai 0:5b88d5760320 9 *
kenjiArai 0:5b88d5760320 10 * Unless required by applicable law or agreed to in writing, software
kenjiArai 0:5b88d5760320 11 * distributed under the License is distributed on an "AS IS" BASIS,
kenjiArai 0:5b88d5760320 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kenjiArai 0:5b88d5760320 13 * See the License for the specific language governing permissions and
kenjiArai 0:5b88d5760320 14 * limitations under the License.
kenjiArai 0:5b88d5760320 15 */
kenjiArai 0:5b88d5760320 16
kenjiArai 0:5b88d5760320 17 /** @file DNS.h Domain Name Service */
kenjiArai 0:5b88d5760320 18 /** @addtogroup netsocket
kenjiArai 0:5b88d5760320 19 * @{ */
kenjiArai 0:5b88d5760320 20
kenjiArai 0:5b88d5760320 21 #ifndef DNS_H
kenjiArai 0:5b88d5760320 22 #define DNS_H
kenjiArai 0:5b88d5760320 23
kenjiArai 0:5b88d5760320 24 /** Base class for DNS provider */
kenjiArai 0:5b88d5760320 25 class DNS {
kenjiArai 0:5b88d5760320 26 public:
kenjiArai 0:5b88d5760320 27
kenjiArai 0:5b88d5760320 28 /** Translate a hostname to an IP address with specific version using network interface name.
kenjiArai 0:5b88d5760320 29 *
kenjiArai 0:5b88d5760320 30 * The hostname may be either a domain name or an IP address. If the
kenjiArai 0:5b88d5760320 31 * hostname is an IP address, no network transactions will be performed.
kenjiArai 0:5b88d5760320 32 *
kenjiArai 0:5b88d5760320 33 * If no stack-specific DNS resolution is provided, the hostname
kenjiArai 0:5b88d5760320 34 * will be resolve using a UDP socket on the stack.
kenjiArai 0:5b88d5760320 35 *
kenjiArai 0:5b88d5760320 36 * @param host Hostname to resolve.
kenjiArai 0:5b88d5760320 37 * @param address Pointer to a SocketAddress to store the result.
kenjiArai 0:5b88d5760320 38 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates
kenjiArai 0:5b88d5760320 39 * version is chosen by the stack (defaults to NSAPI_UNSPEC).
kenjiArai 0:5b88d5760320 40 * @param interface_name Network interface name
kenjiArai 0:5b88d5760320 41 * @return NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 42 */
kenjiArai 0:5b88d5760320 43 virtual nsapi_error_t gethostbyname(const char *host,
kenjiArai 0:5b88d5760320 44 SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC, const char *interface_name = NULL) = 0;
kenjiArai 0:5b88d5760320 45 /** Hostname translation callback for gethostbyname_async.
kenjiArai 0:5b88d5760320 46 *
kenjiArai 0:5b88d5760320 47 * The callback is called after DNS resolution completes, or a failure occurs.
kenjiArai 0:5b88d5760320 48 *
kenjiArai 0:5b88d5760320 49 * Callback should not take more than 10ms to execute, otherwise it might
kenjiArai 0:5b88d5760320 50 * prevent underlying thread processing. A portable user of the callback
kenjiArai 0:5b88d5760320 51 * should not make calls to network operations due to stack size limitations.
kenjiArai 0:5b88d5760320 52 * The callback should not perform expensive operations such as socket recv/send
kenjiArai 0:5b88d5760320 53 * calls or blocking operations.
kenjiArai 0:5b88d5760320 54 *
kenjiArai 0:5b88d5760320 55 * @param result NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 56 * @param address On success, destination for the host SocketAddress.
kenjiArai 0:5b88d5760320 57 */
kenjiArai 0:5b88d5760320 58 typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t;
kenjiArai 0:5b88d5760320 59
kenjiArai 0:5b88d5760320 60 /** Translate a hostname to an IP address (asynchronous)
kenjiArai 0:5b88d5760320 61 *
kenjiArai 0:5b88d5760320 62 * The hostname may be either a domain name or an IP address. If the
kenjiArai 0:5b88d5760320 63 * hostname is an IP address, no network transactions will be performed.
kenjiArai 0:5b88d5760320 64 *
kenjiArai 0:5b88d5760320 65 * If no stack-specific DNS resolution is provided, the hostname
kenjiArai 0:5b88d5760320 66 * will be resolved using a UDP socket on the stack.
kenjiArai 0:5b88d5760320 67 *
kenjiArai 0:5b88d5760320 68 * The call is non-blocking. The result of the DNS operation is returned by the callback.
kenjiArai 0:5b88d5760320 69 * If this function returns failure, the callback will not be called. If it is successful,
kenjiArai 0:5b88d5760320 70 * (the IP address was found from the DNS cache), the callback will be called
kenjiArai 0:5b88d5760320 71 * before the function returns.
kenjiArai 0:5b88d5760320 72 *
kenjiArai 0:5b88d5760320 73 * @param host Hostname to resolve.
kenjiArai 0:5b88d5760320 74 * @param callback Callback that is called to return the result.
kenjiArai 0:5b88d5760320 75 * @param version IP version of address to resolve. NSAPI_UNSPEC indicates that the
kenjiArai 0:5b88d5760320 76 * version is chosen by the stack (defaults to NSAPI_UNSPEC).
kenjiArai 0:5b88d5760320 77 * @param interface_name Network interface name
kenjiArai 0:5b88d5760320 78 * @return NSAPI_ERROR_OK on immediate success,
kenjiArai 0:5b88d5760320 79 * negative error code on immediate failure or
kenjiArai 0:5b88d5760320 80 * a positive unique ID that represents the hostname translation operation
kenjiArai 0:5b88d5760320 81 * and can be passed to cancel.
kenjiArai 0:5b88d5760320 82 */
kenjiArai 0:5b88d5760320 83 virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC,
kenjiArai 0:5b88d5760320 84 const char *interface_name = NULL) = 0;
kenjiArai 0:5b88d5760320 85
kenjiArai 0:5b88d5760320 86 /** Cancel asynchronous hostname translation.
kenjiArai 0:5b88d5760320 87 *
kenjiArai 0:5b88d5760320 88 * When translation is canceled, callback is not called.
kenjiArai 0:5b88d5760320 89 *
kenjiArai 0:5b88d5760320 90 * @param id Unique ID of the hostname translation operation returned by gethostbyname_async.
kenjiArai 0:5b88d5760320 91 * @return NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 92 */
kenjiArai 0:5b88d5760320 93 virtual nsapi_error_t gethostbyname_async_cancel(int id) = 0;
kenjiArai 0:5b88d5760320 94
kenjiArai 0:5b88d5760320 95 /** Add a domain name server to list of servers to query.
kenjiArai 0:5b88d5760320 96 *
kenjiArai 0:5b88d5760320 97 * @param address DNS server host address.
kenjiArai 0:5b88d5760320 98 * @param interface_name Network interface name
kenjiArai 0:5b88d5760320 99 * @return NSAPI_ERROR_OK on success, negative error code on failure.
kenjiArai 0:5b88d5760320 100 */
kenjiArai 0:5b88d5760320 101 virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name = NULL) = 0;
kenjiArai 0:5b88d5760320 102 };
kenjiArai 0:5b88d5760320 103
kenjiArai 0:5b88d5760320 104 #endif
kenjiArai 0:5b88d5760320 105
kenjiArai 0:5b88d5760320 106 /** @} */