added max-age and content-format
Fork of mbedConnectorInterface by
api/ConnectorEndpoint.cpp@16:383ad1356963, 2015-02-06 (annotated)
- Committer:
- ansond
- Date:
- Fri Feb 06 04:07:51 2015 +0000
- Revision:
- 16:383ad1356963
- Parent:
- 13:b0b2f1ae4c30
big updates for underlying re-org
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 8:b518d1c01df1 | 1 | /** |
ansond | 8:b518d1c01df1 | 2 | * @file ConnectorEndpoint.cpp |
ansond | 8:b518d1c01df1 | 3 | * @brief mbed CoAP Endpoint base class |
ansond | 8:b518d1c01df1 | 4 | * @author Doug Anson/Chris Paola |
ansond | 8:b518d1c01df1 | 5 | * @version 1.0 |
ansond | 8:b518d1c01df1 | 6 | * @see |
ansond | 8:b518d1c01df1 | 7 | * |
ansond | 8:b518d1c01df1 | 8 | * Copyright (c) 2014 |
ansond | 8:b518d1c01df1 | 9 | * |
ansond | 8:b518d1c01df1 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 8:b518d1c01df1 | 11 | * you may not use this file except in compliance with the License. |
ansond | 8:b518d1c01df1 | 12 | * You may obtain a copy of the License at |
ansond | 8:b518d1c01df1 | 13 | * |
ansond | 8:b518d1c01df1 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 8:b518d1c01df1 | 15 | * |
ansond | 8:b518d1c01df1 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 8:b518d1c01df1 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 8:b518d1c01df1 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 8:b518d1c01df1 | 19 | * See the License for the specific language governing permissions and |
ansond | 8:b518d1c01df1 | 20 | * limitations under the License. |
ansond | 8:b518d1c01df1 | 21 | */ |
ansond | 8:b518d1c01df1 | 22 | |
ansond | 8:b518d1c01df1 | 23 | #include "ConnectorEndpoint.h" |
ansond | 8:b518d1c01df1 | 24 | |
ansond | 9:d094cfc650c3 | 25 | // lower level network stubs integration |
ansond | 9:d094cfc650c3 | 26 | #include "mbedEndpointNetworkStubs.h" |
ansond | 8:b518d1c01df1 | 27 | |
ansond | 8:b518d1c01df1 | 28 | // Connector namespace |
ansond | 8:b518d1c01df1 | 29 | namespace Connector { |
ansond | 8:b518d1c01df1 | 30 | |
ansond | 16:383ad1356963 | 31 | // STATIC: Plumb the network |
ansond | 16:383ad1356963 | 32 | void Endpoint::plumbNetwork(bool canActAsRouterNode) { |
ansond | 16:383ad1356963 | 33 | // call into our network stubs to (pre-configure) plumb the network... |
ansond | 16:383ad1356963 | 34 | DBG("plumbNetwork: pre-configure plumb of network...\r\n"); |
ansond | 16:383ad1356963 | 35 | net_stubs_pre_plumb_network(canActAsRouterNode); |
ansond | 16:383ad1356963 | 36 | |
ansond | 16:383ad1356963 | 37 | // configure the endpoint now... |
ansond | 16:383ad1356963 | 38 | DBG("plumbNetwork: configuring endpoint...\r\n"); |
ansond | 16:383ad1356963 | 39 | utils_configure_endpoint(); |
ansond | 16:383ad1356963 | 40 | |
ansond | 16:383ad1356963 | 41 | // call into our network stubs to (pre-configure) plumb the network... |
ansond | 16:383ad1356963 | 42 | DBG("plumbNetwork: post-configure plumb of network...\r\n"); |
ansond | 16:383ad1356963 | 43 | net_stubs_post_plumb_network(); |
ansond | 16:383ad1356963 | 44 | } |
ansond | 16:383ad1356963 | 45 | |
ansond | 16:383ad1356963 | 46 | // STATIC: Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger) |
ansond | 16:383ad1356963 | 47 | void Endpoint::start() |
ansond | 16:383ad1356963 | 48 | { |
ansond | 16:383ad1356963 | 49 | // initialize our endpoint and register it |
ansond | 16:383ad1356963 | 50 | DBG("Endpoint::start(): creating endpoint instance and registering with mDS...\r\n"); |
ansond | 16:383ad1356963 | 51 | utils_init_and_register_endpoint(); |
ansond | 16:383ad1356963 | 52 | |
ansond | 16:383ad1356963 | 53 | // create the main loop plumbing for our lower network stack |
ansond | 16:383ad1356963 | 54 | DBG("Endpoint::start(): creating main loop plumbing...\r\n"); |
ansond | 16:383ad1356963 | 55 | net_stubs_create_main_loop(); |
ansond | 16:383ad1356963 | 56 | |
ansond | 16:383ad1356963 | 57 | // call into the lower network stubs to start event processing |
ansond | 16:383ad1356963 | 58 | DBG("Endpoint::start(): beginning main event loop...\r\n"); |
ansond | 16:383ad1356963 | 59 | net_stubs_begin_main_loop(); |
ansond | 16:383ad1356963 | 60 | } |
ansond | 16:383ad1356963 | 61 | |
ansond | 8:b518d1c01df1 | 62 | // Constructor |
ansond | 8:b518d1c01df1 | 63 | Endpoint::Endpoint(const Logger *logger, const Options *options) |
ansond | 8:b518d1c01df1 | 64 | { |
ansond | 8:b518d1c01df1 | 65 | this->m_logger = (Logger *)logger; |
ansond | 8:b518d1c01df1 | 66 | this->m_options = (Options *)options; |
ansond | 8:b518d1c01df1 | 67 | } |
ansond | 8:b518d1c01df1 | 68 | |
ansond | 8:b518d1c01df1 | 69 | // Copy Constructor |
ansond | 8:b518d1c01df1 | 70 | Endpoint::Endpoint(const Endpoint &ep) |
ansond | 8:b518d1c01df1 | 71 | { |
ansond | 8:b518d1c01df1 | 72 | this->m_logger = ep.m_logger; |
ansond | 8:b518d1c01df1 | 73 | this->m_options = ep.m_options; |
ansond | 8:b518d1c01df1 | 74 | } |
ansond | 8:b518d1c01df1 | 75 | |
ansond | 8:b518d1c01df1 | 76 | // Destructor |
ansond | 8:b518d1c01df1 | 77 | Endpoint::~Endpoint() |
ansond | 8:b518d1c01df1 | 78 | { |
ansond | 8:b518d1c01df1 | 79 | } |
ansond | 8:b518d1c01df1 | 80 | |
ansond | 16:383ad1356963 | 81 | // register the endpoint |
ansond | 16:383ad1356963 | 82 | void Endpoint::register_endpoint() |
ansond | 13:b0b2f1ae4c30 | 83 | { |
ansond | 8:b518d1c01df1 | 84 | // Create the NSDL Resource Pointer... |
ansond | 8:b518d1c01df1 | 85 | this->logger()->log("Endpoint::initialize(): initializing NSP resource pointer..."); |
ansond | 8:b518d1c01df1 | 86 | sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); |
ansond | 8:b518d1c01df1 | 87 | if(!resource_ptr) return; |
ansond | 8:b518d1c01df1 | 88 | memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); |
ansond | 8:b518d1c01df1 | 89 | |
ansond | 8:b518d1c01df1 | 90 | resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); |
ansond | 8:b518d1c01df1 | 91 | if(!resource_ptr->resource_parameters_ptr) { |
ansond | 8:b518d1c01df1 | 92 | nsdl_free(resource_ptr); |
ansond | 8:b518d1c01df1 | 93 | return; |
ansond | 8:b518d1c01df1 | 94 | } |
ansond | 8:b518d1c01df1 | 95 | memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); |
ansond | 8:b518d1c01df1 | 96 | |
ansond | 8:b518d1c01df1 | 97 | // Loop through Static Resources and bind each of them... |
ansond | 8:b518d1c01df1 | 98 | this->logger()->log("Endpoint::initialize(): adding static resources..."); |
ansond | 8:b518d1c01df1 | 99 | const StaticResourcesList *static_resources = this->m_options->getStaticResourceList(); |
ansond | 8:b518d1c01df1 | 100 | for(int i=0; i<static_resources->size(); ++i) { |
ansond | 8:b518d1c01df1 | 101 | this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",static_resources->at(i)->getName().c_str()); |
ansond | 8:b518d1c01df1 | 102 | static_resources->at(i)->bind(resource_ptr); |
ansond | 8:b518d1c01df1 | 103 | } |
ansond | 8:b518d1c01df1 | 104 | |
ansond | 8:b518d1c01df1 | 105 | // Loop through Dynamic Resources and bind each of them... |
ansond | 8:b518d1c01df1 | 106 | this->logger()->log("Endpoint::initialize(): adding dynamic resources..."); |
ansond | 8:b518d1c01df1 | 107 | const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList(); |
ansond | 8:b518d1c01df1 | 108 | for(int i=0; i<dynamic_resources->size(); ++i) { |
ansond | 8:b518d1c01df1 | 109 | this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getName().c_str()); |
ansond | 8:b518d1c01df1 | 110 | dynamic_resources->at(i)->bind(resource_ptr); |
ansond | 8:b518d1c01df1 | 111 | } |
ansond | 8:b518d1c01df1 | 112 | |
ansond | 12:c068a2d3e8fe | 113 | // register the endpoint |
ansond | 12:c068a2d3e8fe | 114 | net_stubs_register_endpoint(); |
ansond | 8:b518d1c01df1 | 115 | |
ansond | 8:b518d1c01df1 | 116 | // clean up |
ansond | 8:b518d1c01df1 | 117 | nsdl_free(resource_ptr->resource_parameters_ptr); |
ansond | 8:b518d1c01df1 | 118 | nsdl_free(resource_ptr); |
ansond | 8:b518d1c01df1 | 119 | } |
ansond | 8:b518d1c01df1 | 120 | |
ansond | 8:b518d1c01df1 | 121 | // our logger |
ansond | 8:b518d1c01df1 | 122 | Logger *Endpoint::logger() |
ansond | 8:b518d1c01df1 | 123 | { |
ansond | 8:b518d1c01df1 | 124 | return this->m_logger; |
ansond | 8:b518d1c01df1 | 125 | } |
ansond | 8:b518d1c01df1 | 126 | |
ansond | 8:b518d1c01df1 | 127 | } // namespace Connector |