Simple interface for Mbed Cloud Client

Dependents:  

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nsdlaccesshelper.cpp Source File

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,
00031                                               received_coap_ptr,
00032                                               address, nsdl_capab);
00033     }
00034     return status;
00035 }
00036 
00037 void* __nsdl_c_memory_alloc(uint16_t size)
00038 {
00039     if(size)
00040         return malloc(size);
00041     else
00042         return 0;
00043 }
00044 
00045 void __nsdl_c_memory_free(void *ptr)
00046 {
00047     if(ptr)
00048         free(ptr);
00049 }
00050 
00051 uint8_t __nsdl_c_send_to_server(struct nsdl_s * nsdl_handle,
00052                                 sn_nsdl_capab_e protocol,
00053                                 uint8_t *data_ptr,
00054                                 uint16_t data_len,
00055                                 sn_nsdl_addr_s *address_ptr)
00056 {
00057     uint8_t status = 0;
00058     M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle);
00059     if(interface) {
00060         status = interface->send_to_server_callback(nsdl_handle,
00061                                                            protocol, data_ptr,
00062                                                            data_len, address_ptr);
00063     }
00064     return status;
00065 }
00066 
00067 uint8_t __nsdl_c_received_from_server(struct nsdl_s * nsdl_handle,
00068                                       sn_coap_hdr_s *coap_header,
00069                                       sn_nsdl_addr_s *address_ptr)
00070 {
00071     uint8_t status = 0;
00072     M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle);
00073     if(interface) {
00074         status = interface->received_from_server_callback(nsdl_handle,
00075                                                                  coap_header,
00076                                                                  address_ptr);
00077     }
00078     return status;
00079 }
00080 
00081 uint8_t __nsdl_c_auto_obs_token(struct nsdl_s *nsdl_handle, const char *path, uint8_t *token)
00082 {
00083     M2MNsdlInterface *interface = (M2MNsdlInterface*)sn_nsdl_get_context(nsdl_handle);
00084     if(interface) {
00085         return interface->find_auto_obs_token(path, token);
00086     }
00087     return 0;
00088 }
00089 
00090 void* __socket_malloc( void * context, size_t size)
00091 {
00092     (void) context;
00093     return malloc(size);
00094 }
00095 
00096 void __socket_free(void * context, void * ptr)
00097 {
00098     (void) context;
00099     free(ptr);
00100 }
00101