MBED_DEMOS / nsp_resources

Dependencies:   nsdl_lib

Dependents:   mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nsp_get.cpp Source File

nsp_get.cpp

00001 #include "nsp_get.h"
00002 
00003 extern char *strdup(char *str);
00004 
00005 // NSP Get Method
00006 uint8_t nsp_get(char *tag,MBEDio *io,sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto) { return nsp_get(tag,io,received_coap_ptr,address,proto,NULL); }
00007 uint8_t nsp_get(char *tag,MBEDio *io,sn_coap_hdr_s *received_coap_ptr, sn_nsdl_addr_s *address, sn_proto_info_s *proto,sn_update_observation_t observer) {
00008 if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(begin)");
00009 #ifdef NSP_ENABLE_GET
00010     //if (m_logger != NULL) m_logger->log("NSP: %s requested",tag);
00011     sn_coap_hdr_s *coap_res_ptr = NULL;
00012     coap_res_ptr = sn_coap_build_response(received_coap_ptr,COAP_MSG_CODE_RESPONSE_CONTENT);
00013     if (coap_res_ptr != NULL && io != NULL && io->stringValue() != NULL) {      // io->stringValue() refreshes the value
00014         coap_res_ptr->msg_type = COAP_MSG_TYPE_CONFIRMABLE;
00015         coap_res_ptr->payload_len = strlen(io->resource()->getValuePointer());
00016         coap_res_ptr->payload_ptr = (uint8_t*)io->resource()->getValuePointer();
00017         //if (m_logger != NULL) m_logger->log("NSP: Sending %s = %s...",tag,io->resource()->getValuePointer());
00018         if (observer != NULL) (observer)(received_coap_ptr,coap_res_ptr);
00019         sn_nsdl_send_coap_message(address, coap_res_ptr);
00020         if (m_logger != NULL) m_logger->log("NSP: Sent %s = %s...",tag,io->resource()->getValuePointer());
00021     }
00022     else if (coap_res_ptr == NULL) {
00023         if (m_logger != NULL) m_logger->log("NSP: %s request: coap_res_ptr is NULL!",tag);
00024     }
00025     else {
00026         if (m_logger != NULL) m_logger->log("NSP: %s request: MBEDio is NULL!",tag);
00027     }
00028     if (coap_res_ptr != NULL && coap_res_ptr->options_list_ptr != NULL) coap_res_ptr->options_list_ptr->observe_ptr = NULL;
00029     if (coap_res_ptr != NULL) sn_coap_parser_release_allocated_coap_msg_mem(coap_res_ptr);
00030     if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(done)");
00031     return 0;
00032 #else
00033     if (m_logger != NULL) m_logger->log("NSP Get() functions disabled for %s",tag);
00034     if (m_logger != NULL) m_logger->log_memory("NSP GET MEMORY CHECK(off)");
00035     return 0;
00036 #endif
00037 }