added max-age and content-format

Fork of mbedConnectorInterface by Doug Anson

Committer:
michaeljkoster
Date:
Tue Apr 14 04:00:01 2015 +0000
Revision:
52:822611156e35
Parent:
2:853f9ecc12df
added interfaces for max-age and content-format

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:b438482ebbfc 1 /**
ansond 0:b438482ebbfc 2 * @file InstancePointerTableHelper.h
ansond 0:b438482ebbfc 3 * @brief instance pointer table helper functions for DynamicResource
ansond 0:b438482ebbfc 4 * @author Doug Anson
ansond 0:b438482ebbfc 5 * @version 1.0
sam_grove 2:853f9ecc12df 6 * @see
ansond 0:b438482ebbfc 7 *
ansond 0:b438482ebbfc 8 * Copyright (c) 2014
ansond 0:b438482ebbfc 9 *
ansond 0:b438482ebbfc 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:b438482ebbfc 11 * you may not use this file except in compliance with the License.
ansond 0:b438482ebbfc 12 * You may obtain a copy of the License at
ansond 0:b438482ebbfc 13 *
ansond 0:b438482ebbfc 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:b438482ebbfc 15 *
ansond 0:b438482ebbfc 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:b438482ebbfc 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:b438482ebbfc 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:b438482ebbfc 19 * See the License for the specific language governing permissions and
ansond 0:b438482ebbfc 20 * limitations under the License.
ansond 0:b438482ebbfc 21 */
sam_grove 2:853f9ecc12df 22
sam_grove 2:853f9ecc12df 23 #ifndef __INSTANCE_POINTER_TABLE_HELPER_H__
sam_grove 2:853f9ecc12df 24 #define __INSTANCE_POINTER_TABLE_HELPER_H__
ansond 0:b438482ebbfc 25
sam_grove 2:853f9ecc12df 26 // InstancePointerTable
sam_grove 2:853f9ecc12df 27 #include "InstancePointerTable.h"
sam_grove 2:853f9ecc12df 28 extern Logger logger;
sam_grove 2:853f9ecc12df 29 InstancePointerTable __nsdl_lookup_table(&logger); // Instance Pointer Table
sam_grove 2:853f9ecc12df 30
sam_grove 2:853f9ecc12df 31
sam_grove 2:853f9ecc12df 32 // lookup a DynamicResource instance indexed by our resource URI as the key
sam_grove 2:853f9ecc12df 33 extern "C" DynamicResource *__lookup_instance_pointer(const char *uri,const int uri_length)
sam_grove 2:853f9ecc12df 34 {
ansond 0:b438482ebbfc 35 if (uri != NULL && uri_length > 0) {
ansond 0:b438482ebbfc 36 string key(uri,uri_length);
ansond 0:b438482ebbfc 37 return (DynamicResource *)__nsdl_lookup_table.get(key);
ansond 0:b438482ebbfc 38 }
ansond 0:b438482ebbfc 39 return NULL;
sam_grove 2:853f9ecc12df 40 }
sam_grove 2:853f9ecc12df 41
sam_grove 2:853f9ecc12df 42 // callback function for NSDL library to call into... ASSUMPTION: 1 and only 1 DynamicResource<> instance per Resource URI...
sam_grove 2:853f9ecc12df 43 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)
sam_grove 2:853f9ecc12df 44 {
ansond 0:b438482ebbfc 45 uint8_t status = 1;
sam_grove 2:853f9ecc12df 46 if (received_coap_ptr != NULL) {
ansond 0:b438482ebbfc 47 // retrieve our resource instance via lookup/index by our resource URI
ansond 0:b438482ebbfc 48 DynamicResource *instance = __lookup_instance_pointer((const char *)received_coap_ptr->uri_path_ptr,received_coap_ptr->uri_path_len);
ansond 0:b438482ebbfc 49 if (instance != NULL) {
ansond 0:b438482ebbfc 50 std::printf("Instance retrieved.. processing callback...\r\n");
ansond 0:b438482ebbfc 51 status = instance->process(received_coap_ptr,address,proto);
sam_grove 2:853f9ecc12df 52 } else {
ansond 0:b438482ebbfc 53 std::printf("Unable to process callback: unable to lookup DynamicResource<> instance pointer... ignorning...\r\n");
ansond 0:b438482ebbfc 54 }
sam_grove 2:853f9ecc12df 55 } else {
ansond 0:b438482ebbfc 56 std::printf("Unable to process callback: received coap pointer is NULL... ignoring...\r\n");
ansond 0:b438482ebbfc 57 }
ansond 0:b438482ebbfc 58 return status;
sam_grove 2:853f9ecc12df 59 }
sam_grove 2:853f9ecc12df 60
sam_grove 2:853f9ecc12df 61 // add a instance pointer to our lookup table keyed by the key
sam_grove 2:853f9ecc12df 62 extern "C" void ipt_helper_add_instance_pointer(const string *key,DynamicResource *instance)
sam_grove 2:853f9ecc12df 63 {
sam_grove 2:853f9ecc12df 64 __nsdl_lookup_table.add(*key,instance);
sam_grove 2:853f9ecc12df 65 if (key != NULL) delete key;
sam_grove 2:853f9ecc12df 66 }
sam_grove 2:853f9ecc12df 67
sam_grove 2:853f9ecc12df 68 #endif // __INSTANCE_POINTER_TABLE_HELPER_H__