added max-age and content-format
Fork of mbedConnectorInterface by
api/ConnectorEndpoint.cpp@13:b0b2f1ae4c30, 2015-02-02 (annotated)
- Committer:
- ansond
- Date:
- Mon Feb 02 06:45:37 2015 +0000
- Revision:
- 13:b0b2f1ae4c30
- Parent:
- 12:c068a2d3e8fe
- Child:
- 16:383ad1356963
updates
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 | 8:b518d1c01df1 | 31 | // Constructor |
ansond | 8:b518d1c01df1 | 32 | Endpoint::Endpoint(const Logger *logger, const Options *options) |
ansond | 8:b518d1c01df1 | 33 | { |
ansond | 8:b518d1c01df1 | 34 | this->m_logger = (Logger *)logger; |
ansond | 8:b518d1c01df1 | 35 | this->m_options = (Options *)options; |
ansond | 8:b518d1c01df1 | 36 | } |
ansond | 8:b518d1c01df1 | 37 | |
ansond | 8:b518d1c01df1 | 38 | // Copy Constructor |
ansond | 8:b518d1c01df1 | 39 | Endpoint::Endpoint(const Endpoint &ep) |
ansond | 8:b518d1c01df1 | 40 | { |
ansond | 8:b518d1c01df1 | 41 | this->m_logger = ep.m_logger; |
ansond | 8:b518d1c01df1 | 42 | this->m_options = ep.m_options; |
ansond | 8:b518d1c01df1 | 43 | } |
ansond | 8:b518d1c01df1 | 44 | |
ansond | 8:b518d1c01df1 | 45 | // Destructor |
ansond | 8:b518d1c01df1 | 46 | Endpoint::~Endpoint() |
ansond | 8:b518d1c01df1 | 47 | { |
ansond | 8:b518d1c01df1 | 48 | } |
ansond | 8:b518d1c01df1 | 49 | |
ansond | 8:b518d1c01df1 | 50 | // Plumb the network |
ansond | 8:b518d1c01df1 | 51 | void Endpoint::plumbNetwork(bool canActAsRouterNode) { |
ansond | 9:d094cfc650c3 | 52 | // call into our network stubs to plumb the network... |
ansond | 9:d094cfc650c3 | 53 | net_stubs_plumb_network(canActAsRouterNode); |
ansond | 8:b518d1c01df1 | 54 | } |
ansond | 8:b518d1c01df1 | 55 | |
ansond | 8:b518d1c01df1 | 56 | // initialize the endpoint |
ansond | 8:b518d1c01df1 | 57 | void Endpoint::initialize() |
ansond | 13:b0b2f1ae4c30 | 58 | { |
ansond | 8:b518d1c01df1 | 59 | // Create the NSDL Resource Pointer... |
ansond | 8:b518d1c01df1 | 60 | this->logger()->log("Endpoint::initialize(): initializing NSP resource pointer..."); |
ansond | 8:b518d1c01df1 | 61 | sn_nsdl_resource_info_s *resource_ptr = (sn_nsdl_resource_info_s*)nsdl_alloc(sizeof(sn_nsdl_resource_info_s)); |
ansond | 8:b518d1c01df1 | 62 | if(!resource_ptr) return; |
ansond | 8:b518d1c01df1 | 63 | memset(resource_ptr, 0, sizeof(sn_nsdl_resource_info_s)); |
ansond | 8:b518d1c01df1 | 64 | |
ansond | 8:b518d1c01df1 | 65 | resource_ptr->resource_parameters_ptr = (sn_nsdl_resource_parameters_s*)nsdl_alloc(sizeof(sn_nsdl_resource_parameters_s)); |
ansond | 8:b518d1c01df1 | 66 | if(!resource_ptr->resource_parameters_ptr) { |
ansond | 8:b518d1c01df1 | 67 | nsdl_free(resource_ptr); |
ansond | 8:b518d1c01df1 | 68 | return; |
ansond | 8:b518d1c01df1 | 69 | } |
ansond | 8:b518d1c01df1 | 70 | memset(resource_ptr->resource_parameters_ptr, 0, sizeof(sn_nsdl_resource_parameters_s)); |
ansond | 8:b518d1c01df1 | 71 | |
ansond | 8:b518d1c01df1 | 72 | // Loop through Static Resources and bind each of them... |
ansond | 8:b518d1c01df1 | 73 | this->logger()->log("Endpoint::initialize(): adding static resources..."); |
ansond | 8:b518d1c01df1 | 74 | const StaticResourcesList *static_resources = this->m_options->getStaticResourceList(); |
ansond | 8:b518d1c01df1 | 75 | for(int i=0; i<static_resources->size(); ++i) { |
ansond | 8:b518d1c01df1 | 76 | this->logger()->log("Endpoint::initialize(): binding static resource: [%s]...",static_resources->at(i)->getName().c_str()); |
ansond | 8:b518d1c01df1 | 77 | static_resources->at(i)->bind(resource_ptr); |
ansond | 8:b518d1c01df1 | 78 | } |
ansond | 8:b518d1c01df1 | 79 | |
ansond | 8:b518d1c01df1 | 80 | // Loop through Dynamic Resources and bind each of them... |
ansond | 8:b518d1c01df1 | 81 | this->logger()->log("Endpoint::initialize(): adding dynamic resources..."); |
ansond | 8:b518d1c01df1 | 82 | const DynamicResourcesList *dynamic_resources = this->m_options->getDynamicResourceList(); |
ansond | 8:b518d1c01df1 | 83 | for(int i=0; i<dynamic_resources->size(); ++i) { |
ansond | 8:b518d1c01df1 | 84 | this->logger()->log("Endpoint::initialize(): binding dynamic resource: [%s]...",dynamic_resources->at(i)->getName().c_str()); |
ansond | 8:b518d1c01df1 | 85 | dynamic_resources->at(i)->bind(resource_ptr); |
ansond | 8:b518d1c01df1 | 86 | } |
ansond | 8:b518d1c01df1 | 87 | |
ansond | 12:c068a2d3e8fe | 88 | // register the endpoint |
ansond | 12:c068a2d3e8fe | 89 | net_stubs_register_endpoint(); |
ansond | 8:b518d1c01df1 | 90 | |
ansond | 8:b518d1c01df1 | 91 | // clean up |
ansond | 8:b518d1c01df1 | 92 | nsdl_free(resource_ptr->resource_parameters_ptr); |
ansond | 8:b518d1c01df1 | 93 | nsdl_free(resource_ptr); |
ansond | 8:b518d1c01df1 | 94 | } |
ansond | 8:b518d1c01df1 | 95 | |
ansond | 8:b518d1c01df1 | 96 | // Finalize the endpoint's configuration and begin the endpoint's main even loop (static, not tied into Logger) |
ansond | 8:b518d1c01df1 | 97 | void Endpoint::start() |
ansond | 8:b518d1c01df1 | 98 | { |
ansond | 9:d094cfc650c3 | 99 | // create the main loop plumbing for our lower network stack |
ansond | 9:d094cfc650c3 | 100 | DBG("Endpoint::start(): creating main loop plumbing...\r\n"); |
ansond | 9:d094cfc650c3 | 101 | net_stubs_create_main_loop(); |
ansond | 9:d094cfc650c3 | 102 | |
ansond | 9:d094cfc650c3 | 103 | // call into the lower network stubs to start event processing |
ansond | 9:d094cfc650c3 | 104 | DBG("Endpoint::start(): beginning main event loop...\r\n"); |
ansond | 9:d094cfc650c3 | 105 | net_stubs_begin_main_loop(); |
ansond | 8:b518d1c01df1 | 106 | } |
ansond | 8:b518d1c01df1 | 107 | |
ansond | 8:b518d1c01df1 | 108 | // our logger |
ansond | 8:b518d1c01df1 | 109 | Logger *Endpoint::logger() |
ansond | 8:b518d1c01df1 | 110 | { |
ansond | 8:b518d1c01df1 | 111 | return this->m_logger; |
ansond | 8:b518d1c01df1 | 112 | } |
ansond | 8:b518d1c01df1 | 113 | |
ansond | 8:b518d1c01df1 | 114 | } // namespace Connector |