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.
Fork of mbed-os by
sn_grs_stub.c
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 00017 /** 00018 * 00019 * \file sn_grs.c 00020 * 00021 * \brief General resource server. 00022 * 00023 */ 00024 #include <string.h> 00025 #include <stdlib.h> 00026 00027 #include "ns_list.h" 00028 #include "ns_types.h" 00029 #include "sn_nsdl.h" 00030 #include "sn_coap_header.h" 00031 #include "sn_coap_protocol.h" 00032 #include "sn_nsdl_lib.h" 00033 #include "sn_grs.h" 00034 00035 #include "sn_grs_stub.h" 00036 00037 sn_grs_stub_def sn_grs_stub; 00038 00039 /* Extern function prototypes */ 00040 extern int8_t sn_nsdl_build_registration_body(struct nsdl_s *handle, sn_coap_hdr_s *message_ptr, uint8_t updating_registeration); 00041 00042 00043 extern int8_t sn_grs_destroy(struct grs_s *handle) 00044 { 00045 if( handle ){ 00046 free(handle); 00047 } 00048 return sn_grs_stub.expectedInt8; 00049 } 00050 00051 extern struct grs_s *sn_grs_init(uint8_t (*sn_grs_tx_callback_ptr)(struct nsdl_s *, sn_nsdl_capab_e , uint8_t *, uint16_t, 00052 sn_nsdl_addr_s *), int8_t (*sn_grs_rx_callback_ptr)(struct nsdl_s *, sn_coap_hdr_s *, sn_nsdl_addr_s *), 00053 void *(*sn_grs_alloc)(uint16_t), void (*sn_grs_free)(void *)) 00054 { 00055 if( sn_grs_stub.retNull ){ 00056 return NULL; 00057 } 00058 return sn_grs_stub.expectedGrs; 00059 } 00060 00061 00062 00063 extern sn_grs_resource_list_s *sn_grs_list_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) 00064 { 00065 if( sn_grs_stub.retNull ){ 00066 return NULL; 00067 } 00068 return sn_grs_stub.expectedList; 00069 } 00070 00071 00072 extern void sn_grs_free_resource_list(struct grs_s *handle, sn_grs_resource_list_s *list) 00073 { 00074 if( list ){ 00075 free(list); 00076 list = NULL; 00077 } 00078 } 00079 00080 00081 extern const sn_nsdl_resource_info_s *sn_grs_get_first_resource(struct grs_s *handle) 00082 { 00083 if( sn_grs_stub.retNull ){ 00084 return NULL; 00085 } 00086 if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ 00087 sn_grs_stub.info2ndRetCounter--; 00088 return sn_grs_stub.expectedInfo; 00089 } 00090 if( sn_grs_stub.infoRetCounter > 0){ 00091 sn_grs_stub.infoRetCounter--; 00092 return sn_grs_stub.expectedInfo; 00093 } 00094 sn_grs_stub.infoRetCounter = -1; 00095 return NULL; 00096 } 00097 00098 00099 extern const sn_nsdl_resource_info_s *sn_grs_get_next_resource(struct grs_s *handle, const sn_nsdl_resource_info_s *sn_grs_current_resource) 00100 { 00101 if( sn_grs_stub.retNull ){ 00102 return NULL; 00103 } 00104 if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ 00105 sn_grs_stub.info2ndRetCounter--; 00106 return sn_grs_stub.expectedInfo; 00107 } 00108 if( sn_grs_stub.infoRetCounter > 0){ 00109 sn_grs_stub.infoRetCounter--; 00110 return sn_grs_stub.expectedInfo; 00111 } 00112 sn_grs_stub.infoRetCounter = -1; 00113 return NULL; 00114 } 00115 00116 00117 extern int8_t sn_grs_delete_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path) 00118 { 00119 return sn_grs_stub.expectedInt8; 00120 } 00121 00122 00123 extern int8_t sn_grs_update_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) 00124 { 00125 return sn_grs_stub.expectedInt8; 00126 } 00127 00128 00129 extern int8_t sn_grs_create_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) 00130 { 00131 if( sn_grs_stub.int8SuccessCounter > 0 ){ 00132 sn_grs_stub.int8SuccessCounter--; 00133 return SN_NSDL_SUCCESS; 00134 } 00135 return sn_grs_stub.expectedInt8; 00136 } 00137 00138 int8_t sn_grs_put_resource(struct grs_s *handle, sn_nsdl_resource_info_s *res) 00139 { 00140 if( sn_grs_stub.int8SuccessCounter > 0 ){ 00141 sn_grs_stub.int8SuccessCounter--; 00142 return SN_NSDL_SUCCESS; 00143 } 00144 return sn_grs_stub.expectedInt8; 00145 } 00146 00147 extern int8_t sn_grs_process_coap(struct nsdl_s *nsdl_handle, sn_coap_hdr_s *coap_packet_ptr, sn_nsdl_addr_s *src_addr_ptr) 00148 { 00149 return sn_grs_stub.expectedInt8; 00150 } 00151 00152 extern int8_t sn_grs_send_coap_message(struct nsdl_s *handle, sn_nsdl_addr_s *address_ptr, sn_coap_hdr_s *coap_hdr_ptr) 00153 { 00154 return sn_grs_stub.expectedInt8; 00155 } 00156 00157 sn_nsdl_resource_info_s *sn_grs_search_resource(struct grs_s *handle, uint16_t pathlen, uint8_t *path, uint8_t search_method) 00158 { 00159 if(sn_grs_stub.useMockedPath){ 00160 memcpy(path, &sn_grs_stub.mockedPath, sn_grs_stub.mockedPathLen); 00161 } 00162 if( sn_grs_stub.retNull ){ 00163 return NULL; 00164 } 00165 if( sn_grs_stub.infoRetCounter == -1 && sn_grs_stub.info2ndRetCounter > 0 ){ 00166 sn_grs_stub.info2ndRetCounter--; 00167 return sn_grs_stub.expectedInfo; 00168 } 00169 if( sn_grs_stub.infoRetCounter > 0){ 00170 sn_grs_stub.infoRetCounter--; 00171 return sn_grs_stub.expectedInfo; 00172 } 00173 sn_grs_stub.infoRetCounter = -1; 00174 return NULL; 00175 } 00176 00177 void sn_grs_mark_resources_as_registered(struct nsdl_s *handle) 00178 { 00179 } 00180
Generated on Tue Jul 12 2022 13:16:06 by
