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.
nsdlaccesshelper.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 "include/nsdlaccesshelper.h" 00017 #include "include/m2mnsdlinterface.h" 00018 00019 #include <stdlib.h> 00020 00021 M2MNsdlInterfaceList __nsdl_interface_list; 00022 00023 // callback function for NSDL library to call into 00024 00025 M2MConnectionHandler *__connection_handler = NULL; 00026 00027 00028 uint8_t __nsdl_c_callback(struct nsdl_s *nsdl_handle, 00029 sn_coap_hdr_s *received_coap_ptr, 00030 sn_nsdl_addr_s *address, 00031 sn_nsdl_capab_e nsdl_capab) 00032 { 00033 uint8_t status = 0; 00034 M2MNsdlInterface *interface = get_interface(nsdl_handle); 00035 if(interface) { 00036 status = interface->resource_callback(nsdl_handle,received_coap_ptr, 00037 address, nsdl_capab); 00038 // Payload freeing must be done in app level if blockwise message 00039 if (received_coap_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED) { 00040 free(received_coap_ptr->payload_ptr); 00041 received_coap_ptr->payload_ptr = NULL; 00042 } 00043 } 00044 return status; 00045 } 00046 00047 void* __nsdl_c_memory_alloc(uint16_t size) 00048 { 00049 if(size) 00050 return malloc(size); 00051 else 00052 return 0; 00053 } 00054 00055 void __nsdl_c_memory_free(void *ptr) 00056 { 00057 if(ptr) 00058 free(ptr); 00059 } 00060 00061 uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle, 00062 sn_nsdl_capab_e protocol, 00063 uint8_t *data_ptr, 00064 uint16_t data_len, 00065 sn_nsdl_addr_s *address_ptr) 00066 { 00067 uint8_t status = 0; 00068 M2MNsdlInterface *interface = get_interface(nsdl_handle); 00069 if(interface) { 00070 status = interface->send_to_server_callback(nsdl_handle, 00071 protocol, data_ptr, 00072 data_len, address_ptr); 00073 } 00074 return status; 00075 } 00076 00077 uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle, 00078 sn_coap_hdr_s *coap_header, 00079 sn_nsdl_addr_s *address_ptr) 00080 { 00081 uint8_t status = 0; 00082 M2MNsdlInterface *interface = get_interface(nsdl_handle); 00083 if(interface) { 00084 status = interface->received_from_server_callback(nsdl_handle, 00085 coap_header, 00086 address_ptr); 00087 // Payload freeing must be done in app level if blockwise message 00088 if (coap_header && 00089 coap_header->options_list_ptr && 00090 coap_header->options_list_ptr->block1 != -1) { 00091 free(coap_header->payload_ptr); 00092 coap_header->payload_ptr = NULL; 00093 } 00094 } 00095 return status; 00096 } 00097 00098 void* __socket_malloc( void * context, size_t size) 00099 { 00100 (void) context; 00101 return malloc(size); 00102 } 00103 00104 void __socket_free(void * context, void * ptr) 00105 { 00106 (void) context; 00107 free(ptr); 00108 } 00109 00110 M2MNsdlInterface* get_interface(struct nsdl_s* nsdl_handle) 00111 { 00112 M2MNsdlInterfaceList::const_iterator it; 00113 it = __nsdl_interface_list.begin(); 00114 M2MNsdlInterface* obj = NULL; 00115 if (nsdl_handle) { 00116 for (; it!=__nsdl_interface_list.end(); it++) { 00117 if ((*it)->get_nsdl_handle() == nsdl_handle) { 00118 obj = *it; 00119 break; 00120 } 00121 } 00122 } 00123 return obj; 00124 } 00125 00126 void __mutex_claim() 00127 { 00128 if(__connection_handler) { 00129 __connection_handler->claim_mutex(); 00130 } 00131 } 00132 00133 void __mutex_release() 00134 { 00135 if(__connection_handler) { 00136 __connection_handler->release_mutex(); 00137 } 00138 }
Generated on Tue Jul 12 2022 21:20:28 by
