Ram Gandikota / Mbed OS ABCD
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common_stub.cpp Source File

common_stub.cpp

00001 /*
00002  * Copyright (c) 2015 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "common_stub.h"
00017 #include "sn_grs.h"
00018 #include <sys/socket.h>
00019 
00020 socket_error_t common_stub::error;
00021 socket_event_t * common_stub::event;
00022 socket_addr * common_stub::addr;
00023 void * common_stub::void_value;
00024 bool common_stub::visited;
00025 bool common_stub::bool_value;
00026 int common_stub::int_value;
00027 int common_stub::int2_value;
00028 addrinfo* common_stub::addrinfo;
00029 uint16_t common_stub::uint_value;
00030 sn_coap_hdr_s *common_stub::coap_header;
00031 sn_nsdl_dynamic_resource_parameters_s *common_stub::resource;
00032 pthread_t common_stub::thread;
00033 const char* common_stub::char_value;
00034 
00035 using namespace mbed;
00036 using namespace mbed::Sockets::v0;
00037 
00038 void common_stub::clear()
00039 {
00040     int_value = -1;
00041     int2_value = -1;
00042     uint_value = 0;
00043     error = SOCKET_ERROR_NONE;
00044     event = NULL;
00045     addr = NULL;
00046     void_value = NULL;
00047     visited = false;
00048     bool_value= false;
00049     coap_header = NULL;
00050     resource = NULL;
00051     addrinfo = NULL;
00052     char_value = NULL;
00053 }
00054 
00055 UDPSocket::UDPSocket(socket_stack_t stack) :Socket(stack)
00056 {
00057 }
00058 
00059 UDPSocket::~UDPSocket()
00060 {
00061 }
00062 
00063 socket_error_t UDPSocket::connect(const SocketAddr *, const uint16_t )
00064 {
00065     return common_stub::error;
00066 }
00067 
00068 //SocketAddr
00069 
00070 void SocketAddr::setAddr(const struct socket_addr *)
00071 {
00072 }
00073 
00074 void SocketAddr::setAddr(const SocketAddr *)
00075 {
00076 }
00077 
00078 bool SocketAddr::SocketAddr::is_v4()
00079 {
00080     return common_stub::bool_value;
00081 }
00082 
00083 void mbed::Ticker::detach()
00084 {
00085     common_stub::visited = true;
00086 }
00087 
00088 
00089 // SN_NSDL_LIB
00090 
00091 struct nsdl_s *sn_nsdl_init (uint8_t (*sn_nsdl_tx_cb)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, sn_nsdl_addr_s *),
00092                              uint8_t (*sn_nsdl_rx_cb)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *),
00093                              void *(*sn_nsdl_alloc)(uint16_t),void (*sn_nsdl_free)(void *))
00094 {
00095     return NULL;
00096 }
00097 
00098 uint16_t sn_nsdl_register_endpoint(struct nsdl_s *, sn_nsdl_ep_parameters_s *)
00099 {
00100     return common_stub::uint_value;
00101 }
00102 
00103 uint16_t sn_nsdl_unregister_endpoint(struct nsdl_s *)
00104 {
00105     return common_stub::uint_value;
00106 }
00107 
00108 uint16_t sn_nsdl_update_registration(struct nsdl_s *,uint8_t *, uint8_t)
00109 {
00110     return common_stub::uint_value;
00111 }
00112 
00113 uint16_t sn_nsdl_send_observation_notification_with_uri_path(struct nsdl_s *, uint8_t *, uint8_t,
00114                                                     uint8_t *, uint16_t,
00115                                                     uint8_t *, uint8_t,
00116                                                     sn_coap_msg_type_e , uint8_t,
00117                                                     uint8_t *, uint16_t)
00118 {
00119     return common_stub::uint_value;
00120 }
00121 uint16_t sn_nsdl_send_observation_notification(struct nsdl_s *, uint8_t *, uint8_t,
00122                                                     uint8_t *, uint16_t,
00123                                                     uint8_t *, uint8_t,
00124                                                     sn_coap_msg_type_e , uint8_t)
00125 {
00126     return common_stub::uint_value;
00127 }
00128 
00129 int8_t sn_nsdl_set_endpoint_location(struct nsdl_s *, uint8_t *, uint8_t)
00130 {
00131     return common_stub::int_value;
00132 }
00133 
00134 int8_t sn_nsdl_destroy(struct nsdl_s *handle)
00135 {
00136     return common_stub::int_value;
00137 }
00138 
00139 sn_coap_hdr_s *sn_nsdl_build_response(struct nsdl_s *, sn_coap_hdr_s *, uint8_t )
00140 {
00141     return common_stub::coap_header;
00142 }
00143 
00144 sn_nsdl_dynamic_resource_parameters_s *sn_nsdl_get_resource(struct nsdl_s *, uint16_t, uint8_t *)
00145 {
00146     return common_stub::resource;
00147 }
00148 
00149 int8_t sn_nsdl_process_coap(struct nsdl_s *, uint8_t *, uint16_t , sn_nsdl_addr_s *)
00150 {
00151     return common_stub::int_value;
00152 }
00153 
00154 int8_t sn_nsdl_exec(struct nsdl_s *, uint32_t)
00155 {
00156     return common_stub::int_value;
00157 }
00158 
00159 int8_t sn_nsdl_set_retransmission_parameters(struct nsdl_s *, uint8_t, uint8_t)
00160 {
00161     return common_stub::int_value;
00162 }
00163 
00164 void sn_nsdl_release_allocated_coap_msg_mem(struct nsdl_s *, sn_coap_hdr_s *header)
00165 {
00166     if(header && header != common_stub::coap_header){
00167         if( header->options_list_ptr){
00168             free(header->options_list_ptr);
00169             header->options_list_ptr = NULL;
00170         }
00171         free(header);
00172         header = NULL;
00173     }
00174 }
00175 
00176 sn_coap_options_list_s *sn_nsdl_alloc_options_list(struct nsdl_s *handle, sn_coap_hdr_s *coap_msg_ptr)
00177 {
00178     if( common_stub::coap_header ) {
00179         return common_stub::coap_header->options_list_ptr;
00180     }
00181     return NULL;
00182 }
00183 
00184 int8_t sn_nsdl_create_resource(struct nsdl_s *, sn_nsdl_dynamic_resource_parameters_s *)
00185 {
00186     return common_stub::int_value;
00187 }
00188 
00189 int8_t sn_nsdl_delete_resource(struct nsdl_s *, uint16_t , uint8_t *)
00190 {
00191     return common_stub::int_value;
00192 }
00193 
00194 int8_t sn_nsdl_put_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res)
00195 {
00196     return common_stub::int_value;
00197 }
00198 
00199 int8_t sn_nsdl_pop_resource(struct nsdl_s *handle, sn_nsdl_dynamic_resource_parameters_s *res)
00200 {
00201     return common_stub::int_value;
00202 }
00203 
00204 int8_t sn_nsdl_send_coap_message(struct nsdl_s *, sn_nsdl_addr_s *, sn_coap_hdr_s *)
00205 {
00206     return common_stub::int_value;
00207 }
00208 
00209 int8_t sn_nsdl_update_resource(struct nsdl_s *, sn_nsdl_dynamic_resource_parameters_s *)
00210 {
00211     return common_stub::int_value;
00212 }
00213 
00214 int8_t set_NSP_address(struct nsdl_s *, uint8_t *, uint8_t, uint16_t, sn_nsdl_addr_type_e)
00215 {
00216     return common_stub::int_value;
00217 }
00218 
00219 uint16_t sn_nsdl_oma_bootstrap(struct nsdl_s *, sn_nsdl_addr_s *,
00220                              sn_nsdl_ep_parameters_s *,
00221                              sn_nsdl_bs_ep_info_t *)
00222 {
00223     return common_stub::uint_value;
00224 }
00225 
00226 //Coap Headers
00227 
00228 sn_coap_hdr_s *sn_coap_build_response(struct coap_s *, sn_coap_hdr_s *, uint8_t )
00229 {
00230     return common_stub::coap_header;
00231 }
00232 
00233 void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *, sn_coap_hdr_s *)
00234 {
00235 }
00236 
00237 int8_t sn_coap_protocol_set_retransmission_parameters(uint8_t, uint8_t)
00238 {
00239     return common_stub::int_value;
00240 }
00241 
00242 // IP6String.h
00243 uint_fast8_t ip6tos(const void *ip6addr, char *p)
00244 {
00245     // Just set at least something there, or the valgrind will scream when
00246     // client tries to use the result string.
00247     p[0] = '\0';
00248     return 0;
00249 }
00250 
00251 //Socket
00252 Socket::Socket(const socket_stack_t ) : _irq(this)
00253 {
00254     _socket.api = NULL;
00255 }
00256 
00257 Socket::~Socket()
00258 {
00259 }
00260 
00261 socket_error_t Socket::open(const socket_address_family_t , const socket_proto_family_t )
00262 {
00263     return common_stub::error;
00264 }
00265 
00266 bool Socket::error_check(socket_error_t )
00267 {
00268     return common_stub::bool_value;
00269 }
00270 
00271 void Socket::_eventHandler(struct socket_event *)
00272 {
00273 }
00274 
00275 void Socket::setOnError(const ErrorHandler_t &)
00276 {
00277 }
00278 
00279 void Socket::setOnReadable(const ReadableHandler_t &)
00280 {
00281 }
00282 
00283 void Socket::setOnSent(const SentHandler_t & )
00284 {
00285 }
00286 
00287 void Socket::_nvEventHandler(void * )
00288 {
00289 }
00290 
00291 socket_error_t Socket::getLocalAddr(SocketAddr *) const
00292 {
00293     return common_stub::error;
00294 }
00295 
00296 socket_error_t Socket::getLocalPort(uint16_t *) const
00297 {
00298     return common_stub::error;
00299 }
00300 
00301 socket_error_t Socket::getRemoteAddr(SocketAddr *) const
00302 {
00303     return common_stub::error;
00304 }
00305 
00306 socket_error_t Socket::getRemotePort(uint16_t *) const
00307 {
00308     return common_stub::error;
00309 }
00310 
00311 socket_error_t Socket::resolve(const char* , const DNSHandler_t & )
00312 {
00313     return common_stub::error;
00314 }
00315 
00316 socket_error_t Socket::bind(const char * , const uint16_t )
00317 {
00318     return common_stub::error;
00319 }
00320 socket_error_t Socket::bind(const SocketAddr * , const uint16_t )
00321 {
00322     return common_stub::error;
00323 }
00324 
00325 socket_error_t Socket::close()
00326 {
00327     return common_stub::error;
00328 }
00329 
00330 socket_error_t Socket::recv(void * , size_t *)
00331 {
00332     return common_stub::error;
00333 }
00334 socket_error_t Socket::recv_from(void * , size_t *, SocketAddr *, uint16_t *)
00335 {
00336     return common_stub::error;
00337 }
00338 
00339 socket_error_t Socket::send(const void * , const size_t )
00340 {
00341     return common_stub::error;
00342 }
00343 socket_error_t Socket::send_to(const void * , const size_t , const SocketAddr *, uint16_t )
00344 {
00345     return common_stub::error;
00346 }
00347 
00348 bool Socket::isConnected() const {
00349     return common_stub::error;
00350 }
00351 
00352 // pthread
00353 int pthread_equal (pthread_t , pthread_t ) __THROW
00354 {
00355     return common_stub::int2_value;
00356 }
00357 
00358 pthread_t pthread_self (void) __THROW
00359 {
00360     return common_stub::thread;
00361 }
00362 
00363 int pthread_detach (pthread_t) __THROW
00364 {
00365     return common_stub::int_value;
00366 }
00367 
00368 int pthread_create (pthread_t * ,
00369                     const pthread_attr_t *,
00370                     void *(*__start_routine) (void *),
00371                     void *) __THROWNL
00372 {
00373     __start_routine(NULL);
00374     return common_stub::int_value;
00375 }
00376 
00377 int pthread_cancel (pthread_t)
00378 {
00379     return common_stub::int_value;
00380 }
00381 
00382 int pthread_join (pthread_t , void **)
00383 {
00384     return common_stub::int_value;
00385 }
00386 
00387 void pthread_exit (void *__retval)/* __attribute__ ((__noreturn__))*/
00388 {
00389 
00390 }
00391 
00392 // sys/socket
00393 #ifndef __SOCKADDR_ARG
00394 # define __SOCKADDR_ARG     struct sockaddr *__restrict
00395 #endif
00396 
00397 #ifndef __CONST_SOCKADDR_ARG
00398 # define __CONST_SOCKADDR_ARG   const struct sockaddr *
00399 #endif
00400 
00401 #ifndef __socklen_t_defined
00402 typedef __socklen_t socklen_t;
00403 # define __socklen_t_defined
00404 #endif
00405 
00406 int bind (int , __CONST_SOCKADDR_ARG , socklen_t )
00407      __THROW
00408 {
00409     return common_stub::int_value;
00410 }
00411 
00412 ssize_t sendto (int , const void *, size_t ,
00413                                int , __CONST_SOCKADDR_ARG ,
00414                                socklen_t )
00415 {
00416     return common_stub::int_value;
00417 }
00418 
00419 ssize_t recvfrom (int , void * , size_t ,
00420              int , __SOCKADDR_ARG ,
00421              socklen_t * )
00422 {
00423     return common_stub::int_value;
00424 }
00425 
00426 int getaddrinfo (const char *__restrict,
00427             const char *__restrict,
00428             const struct addrinfo *__restrict,
00429             struct addrinfo **__restrict addr)
00430 {
00431     //*addr = (addrinfo*)malloc(sizeof(addrinfo));
00432     //(*addr)->ai_addr = (sockaddr*)malloc(sizeof(sockaddr));
00433     *addr = common_stub::addrinfo;
00434     return common_stub::int_value;
00435 }
00436 
00437 void freeaddrinfo (struct addrinfo * addr)
00438 __THROW
00439 {
00440 //    free(addr->ai_addr);
00441 //    free(addr);
00442 }
00443 
00444 const char *inet_ntop (int, const void *__restrict,
00445                   char *__restrict, socklen_t)
00446      __THROW
00447 {
00448     return common_stub::char_value;
00449 }
00450 
00451 int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len)
00452 {
00453     return common_stub::int_value;
00454 }
00455