Toyomasa Watarai
/
Mbed-example-WS-W27
Mbed Cloud example program for workshop in W27 2018.
Embed:
(wiki syntax)
Show/hide line numbers
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 // callback function for NSDL library to call into 00022 uint8_t __nsdl_c_callback(struct nsdl_s *nsdl_handle, 00023 sn_coap_hdr_s *received_coap_ptr, 00024 sn_nsdl_addr_s *address, 00025 sn_nsdl_capab_e nsdl_capab) 00026 { 00027 uint8_t status = 0; 00028 M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); 00029 if(interface) { 00030 status = interface->resource_callback(nsdl_handle,received_coap_ptr, 00031 address, nsdl_capab); 00032 // Payload freeing must be done in app level if blockwise message 00033 if (received_coap_ptr->coap_status == COAP_STATUS_PARSER_BLOCKWISE_MSG_RECEIVED) { 00034 free(received_coap_ptr->payload_ptr); 00035 received_coap_ptr->payload_ptr = NULL; 00036 } 00037 } 00038 return status; 00039 } 00040 00041 void* __nsdl_c_memory_alloc(uint16_t size) 00042 { 00043 if(size) 00044 return malloc(size); 00045 else 00046 return 0; 00047 } 00048 00049 void __nsdl_c_memory_free(void *ptr) 00050 { 00051 if(ptr) 00052 free(ptr); 00053 } 00054 00055 uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle, 00056 sn_nsdl_capab_e protocol, 00057 uint8_t *data_ptr, 00058 uint16_t data_len, 00059 sn_nsdl_addr_s *address_ptr) 00060 { 00061 uint8_t status = 0; 00062 M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); 00063 if(interface) { 00064 status = interface->send_to_server_callback(nsdl_handle, 00065 protocol, data_ptr, 00066 data_len, address_ptr); 00067 } 00068 return status; 00069 } 00070 00071 uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle, 00072 sn_coap_hdr_s *coap_header, 00073 sn_nsdl_addr_s *address_ptr) 00074 { 00075 uint8_t status = 0; 00076 M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); 00077 if(interface) { 00078 status = interface->received_from_server_callback(nsdl_handle, 00079 coap_header, 00080 address_ptr); 00081 } 00082 return status; 00083 } 00084 00085 uint8_t __nsdl_c_auto_obs_token(struct nsdl_s *nsdl_handle, const char *path, uint8_t *token) 00086 { 00087 M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle); 00088 if(interface) { 00089 return interface->find_auto_obs_token(path, token); 00090 } 00091 return 0; 00092 } 00093 00094 void* __socket_malloc( void * context, size_t size) 00095 { 00096 (void) context; 00097 return malloc(size); 00098 } 00099 00100 void __socket_free(void * context, void * ptr) 00101 { 00102 (void) context; 00103 free(ptr); 00104 } 00105
Generated on Tue Jul 12 2022 16:22:08 by 1.7.2