Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NetworkStack_stub.h
00001 /* 00002 * Copyright (c) 2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may 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, 00013 * WITHOUT 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 NETWORKSTACKSTUB_H 00019 #define NETWORKSTACKSTUB_H 00020 00021 #include "netsocket/NetworkStack.h" 00022 #include <list> 00023 00024 class NetworkStackstub : public NetworkStack { 00025 public: 00026 std::list<nsapi_error_t> return_values; 00027 nsapi_error_t return_value = 0; 00028 virtual const char *get_ip_address() 00029 { 00030 return "127.0.0.1"; 00031 } 00032 virtual nsapi_error_t gethostbyname(const char *host, 00033 SocketAddress *address, nsapi_version_t version) 00034 { 00035 return return_value; 00036 } 00037 virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, 00038 nsapi_version_t version) 00039 { 00040 return return_value; 00041 } 00042 virtual nsapi_error_t gethostbyname_async_cancel(int id) 00043 { 00044 return return_value; 00045 } 00046 00047 protected: 00048 virtual nsapi_error_t socket_open(nsapi_socket_t *handle, nsapi_protocol_t proto) 00049 { 00050 if (return_value == NSAPI_ERROR_OK && return_values.front() == NSAPI_ERROR_OK ) 00051 { 00052 // Make sure a non-NULL value is returned if error is not expected 00053 *handle = reinterpret_cast<nsapi_socket_t*>(1234); 00054 } 00055 return return_value; 00056 }; 00057 virtual nsapi_error_t socket_close(nsapi_socket_t handle) 00058 { 00059 return return_value; 00060 }; 00061 virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address) 00062 { 00063 return return_value; 00064 }; 00065 virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog) 00066 { 00067 return return_value; 00068 }; 00069 virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address) 00070 { 00071 if (!return_values.empty()) 00072 { 00073 nsapi_error_t ret = return_values.front(); 00074 return_values.pop_front(); 00075 return ret; 00076 } 00077 return return_value; 00078 }; 00079 virtual nsapi_error_t socket_accept(nsapi_socket_t server, 00080 nsapi_socket_t *handle, SocketAddress *address = 0) 00081 { 00082 return return_value; 00083 }; 00084 virtual nsapi_size_or_error_t socket_send(nsapi_socket_t handle, 00085 const void *data, nsapi_size_t size) 00086 { 00087 if (!return_values.empty()) 00088 { 00089 nsapi_error_t ret = return_values.front(); 00090 return_values.pop_front(); 00091 return ret; 00092 } 00093 return return_value; 00094 }; 00095 virtual nsapi_size_or_error_t socket_recv(nsapi_socket_t handle, 00096 void *data, nsapi_size_t size) 00097 { 00098 if (!return_values.empty()) 00099 { 00100 nsapi_error_t ret = return_values.front(); 00101 return_values.pop_front(); 00102 return ret; 00103 } 00104 return return_value; 00105 }; 00106 virtual nsapi_size_or_error_t socket_sendto(nsapi_socket_t handle, const SocketAddress &address, 00107 const void *data, nsapi_size_t size) 00108 { 00109 return return_value; 00110 }; 00111 virtual nsapi_size_or_error_t socket_recvfrom(nsapi_socket_t handle, SocketAddress *address, 00112 void *buffer, nsapi_size_t size) 00113 { 00114 if (!return_values.empty()) 00115 { 00116 nsapi_error_t ret = return_values.front(); 00117 return_values.pop_front(); 00118 return ret; 00119 } 00120 return return_value; 00121 }; 00122 virtual void socket_attach(nsapi_socket_t handle, void (*callback)(void *), void *data) {}; 00123 00124 private: 00125 virtual nsapi_error_t call_in(int delay, mbed::Callback<void()> func) 00126 { 00127 return return_value; 00128 } 00129 }; 00130 00131 #endif // NETWORKSTACKSTUB_H
Generated on Tue Aug 9 2022 00:37:16 by
1.7.2