observe updates
Fork of mbedConnectorInterface by
Embed:
(wiki syntax)
Show/hide line numbers
InstancePointerTableHelper.h
Go to the documentation of this file.
00001 /** 00002 * @file InstancePointerTableHelper.h 00003 * @brief instance pointer table helper functions for DynamicResource 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 #ifndef __INSTANCE_POINTER_TABLE_HELPER_H__ 00024 #define __INSTANCE_POINTER_TABLE_HELPER_H__ 00025 00026 // InstancePointerTable 00027 #include "InstancePointerTable.h" 00028 extern Logger logger; 00029 InstancePointerTable __nsdl_lookup_table(&logger); // Instance Pointer Table 00030 00031 00032 // lookup a DynamicResource instance indexed by our resource URI as the key 00033 extern "C" DynamicResource *__lookup_instance_pointer(const char *uri,const int uri_length) 00034 { 00035 if (uri != NULL && uri_length > 0) { 00036 string key(uri,uri_length); 00037 return (DynamicResource *)__nsdl_lookup_table.get(key); 00038 } 00039 return NULL; 00040 } 00041 00042 // callback function for NSDL library to call into... ASSUMPTION: 1 and only 1 DynamicResource<> instance per Resource URI... 00043 extern "C" uint8_t ipt_helper_nsdl_callback_stub(sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s * proto) 00044 { 00045 uint8_t status = 1; 00046 if (received_coap_ptr != NULL) { 00047 // retrieve our resource instance via lookup/index by our resource URI 00048 DynamicResource *instance = __lookup_instance_pointer((const char *)received_coap_ptr->uri_path_ptr,received_coap_ptr->uri_path_len); 00049 if (instance != NULL) { 00050 std::printf("Instance retrieved.. processing callback...\r\n"); 00051 status = instance->process(received_coap_ptr,address,proto); 00052 } else { 00053 std::printf("Unable to process callback: unable to lookup DynamicResource<> instance pointer... ignorning...\r\n"); 00054 } 00055 } else { 00056 std::printf("Unable to process callback: received coap pointer is NULL... ignoring...\r\n"); 00057 } 00058 return status; 00059 } 00060 00061 // add a instance pointer to our lookup table keyed by the key 00062 extern "C" void ipt_helper_add_instance_pointer(const string *key,DynamicResource *instance) 00063 { 00064 __nsdl_lookup_table.add(*key,instance); 00065 if (key != NULL) delete key; 00066 } 00067 00068 #endif // __INSTANCE_POINTER_TABLE_HELPER_H__
Generated on Wed Jul 13 2022 02:11:49 by 1.7.2