added max-age and content-format
Fork of mbedConnectorInterface by
api/OptionsBuilder.cpp@0:b438482ebbfc, 2015-01-27 (annotated)
- Committer:
- ansond
- Date:
- Tue Jan 27 22:23:51 2015 +0000
- Revision:
- 0:b438482ebbfc
- Child:
- 2:853f9ecc12df
initial check in
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:b438482ebbfc | 1 | /** |
ansond | 0:b438482ebbfc | 2 | * @file OptionsBuilder.cpp |
ansond | 0:b438482ebbfc | 3 | * @brief mbed CoAP OptionsBuilder class implementation |
ansond | 0:b438482ebbfc | 4 | * @author Doug Anson/Chris Paola |
ansond | 0:b438482ebbfc | 5 | * @version 1.0 |
ansond | 0:b438482ebbfc | 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 | */ |
ansond | 0:b438482ebbfc | 22 | |
ansond | 0:b438482ebbfc | 23 | #include "OptionsBuilder.h" |
ansond | 0:b438482ebbfc | 24 | |
ansond | 0:b438482ebbfc | 25 | // external included configuration file for the endpoint... |
ansond | 0:b438482ebbfc | 26 | #include "configuration.h" |
ansond | 0:b438482ebbfc | 27 | |
ansond | 0:b438482ebbfc | 28 | // Connector namespace |
ansond | 0:b438482ebbfc | 29 | namespace Connector { |
ansond | 0:b438482ebbfc | 30 | // Constructor |
ansond | 0:b438482ebbfc | 31 | OptionsBuilder::OptionsBuilder() { |
ansond | 0:b438482ebbfc | 32 | this->m_lifetime = NSP_LIFE_TIME; |
ansond | 0:b438482ebbfc | 33 | this->m_domain = NSP_DOMAIN; |
ansond | 0:b438482ebbfc | 34 | this->m_endpoint_type = NSP_ENDPOINT_TYPE; |
ansond | 0:b438482ebbfc | 35 | this->m_node_name = NODE_NAME; |
ansond | 0:b438482ebbfc | 36 | this->m_channel_list = NODE_CHANNEL_LIST; |
ansond | 0:b438482ebbfc | 37 | this->m_rd_update_period = NSP_RD_UPDATE_PERIOD; |
ansond | 0:b438482ebbfc | 38 | this->m_nsp_port = NSP_COAP_UDP_PORT; |
ansond | 0:b438482ebbfc | 39 | |
ansond | 0:b438482ebbfc | 40 | memset(this->m_nsp_address,0,NSP_IP_ADDRESS_LENGTH); |
ansond | 0:b438482ebbfc | 41 | memset(this->m_mac_address,0,NODE_MAC_ADDRESS_LENGTH); |
ansond | 0:b438482ebbfc | 42 | this->m_static_resources.clear(); |
ansond | 0:b438482ebbfc | 43 | this->m_dynamic_resources.clear(); |
ansond | 0:b438482ebbfc | 44 | } |
ansond | 0:b438482ebbfc | 45 | |
ansond | 0:b438482ebbfc | 46 | // Copy Constructor |
ansond | 0:b438482ebbfc | 47 | OptionsBuilder::OptionsBuilder(const OptionsBuilder &ob) { |
ansond | 0:b438482ebbfc | 48 | this->m_lifetime = ob.m_lifetime; |
ansond | 0:b438482ebbfc | 49 | this->m_domain = ob.m_domain; |
ansond | 0:b438482ebbfc | 50 | this->m_endpoint_type = ob.m_endpoint_type; |
ansond | 0:b438482ebbfc | 51 | this->m_static_resources = ob.m_static_resources; |
ansond | 0:b438482ebbfc | 52 | this->m_dynamic_resources = ob.m_dynamic_resources; |
ansond | 0:b438482ebbfc | 53 | } |
ansond | 0:b438482ebbfc | 54 | |
ansond | 0:b438482ebbfc | 55 | // Destructor |
ansond | 0:b438482ebbfc | 56 | OptionsBuilder::~OptionsBuilder() { |
ansond | 0:b438482ebbfc | 57 | this->m_static_resources.clear(); |
ansond | 0:b438482ebbfc | 58 | this->m_dynamic_resources.clear(); |
ansond | 0:b438482ebbfc | 59 | } |
ansond | 0:b438482ebbfc | 60 | |
ansond | 0:b438482ebbfc | 61 | // set lifetime |
ansond | 0:b438482ebbfc | 62 | OptionsBuilder &OptionsBuilder::setLifetime(const char *lifetime) { this->m_lifetime = (char *)lifetime; return *this; } |
ansond | 0:b438482ebbfc | 63 | |
ansond | 0:b438482ebbfc | 64 | // set domain |
ansond | 0:b438482ebbfc | 65 | OptionsBuilder &OptionsBuilder::setDomain(const char *domain) { this->m_domain = string(domain); return *this; } |
ansond | 0:b438482ebbfc | 66 | |
ansond | 0:b438482ebbfc | 67 | // set endpoint nodename |
ansond | 0:b438482ebbfc | 68 | OptionsBuilder &OptionsBuilder::setEndpointNodename(const char *node_name) { this->m_node_name = string(node_name); return *this; } |
ansond | 0:b438482ebbfc | 69 | |
ansond | 0:b438482ebbfc | 70 | // set lifetime |
ansond | 0:b438482ebbfc | 71 | OptionsBuilder &OptionsBuilder::setEndpointType(const char *endpoint_type) { this->m_endpoint_type = string(endpoint_type); return *this; } |
ansond | 0:b438482ebbfc | 72 | |
ansond | 0:b438482ebbfc | 73 | // set NSP port number |
ansond | 0:b438482ebbfc | 74 | OptionsBuilder &OptionsBuilder::setNSPPortNumber(const int port_num) { this->m_nsp_port = port_num; return *this; } |
ansond | 0:b438482ebbfc | 75 | |
ansond | 0:b438482ebbfc | 76 | // set low level radio channel list |
ansond | 0:b438482ebbfc | 77 | OptionsBuilder &OptionsBuilder::setRadioChannelList(const uint32_t channel_list) { this->m_channel_list = channel_list; return *this; } |
ansond | 0:b438482ebbfc | 78 | |
ansond | 0:b438482ebbfc | 79 | // set NSP read update period |
ansond | 0:b438482ebbfc | 80 | OptionsBuilder &OptionsBuilder::setReadUpdatePeriod(const int rd_update_period) { this->m_rd_update_period = rd_update_period; return *this; } |
ansond | 0:b438482ebbfc | 81 | |
ansond | 0:b438482ebbfc | 82 | // set NSP address |
ansond | 0:b438482ebbfc | 83 | OptionsBuilder &OptionsBuilder::setNSPAddress(const uint8_t *nsp_address,const int nsp_address_length) { |
ansond | 0:b438482ebbfc | 84 | if (nsp_address != NULL && nsp_address_length > 0) { |
ansond | 0:b438482ebbfc | 85 | int length = nsp_address_length; |
ansond | 0:b438482ebbfc | 86 | if (length > NSP_IP_ADDRESS_LENGTH) length = NSP_IP_ADDRESS_LENGTH; |
ansond | 0:b438482ebbfc | 87 | for(int i=0;i<length;++i) this->m_nsp_address[i] = nsp_address[i]; |
ansond | 0:b438482ebbfc | 88 | } |
ansond | 0:b438482ebbfc | 89 | return *this; |
ansond | 0:b438482ebbfc | 90 | } |
ansond | 0:b438482ebbfc | 91 | |
ansond | 0:b438482ebbfc | 92 | // set MAC address |
ansond | 0:b438482ebbfc | 93 | OptionsBuilder &OptionsBuilder::setMACAddress(const uint8_t *mac_address,const int mac_address_length) { |
ansond | 0:b438482ebbfc | 94 | if (mac_address != NULL && mac_address_length > 0) { |
ansond | 0:b438482ebbfc | 95 | int length = mac_address_length; |
ansond | 0:b438482ebbfc | 96 | if (length > NODE_MAC_ADDRESS_LENGTH) length = NODE_MAC_ADDRESS_LENGTH; |
ansond | 0:b438482ebbfc | 97 | for(int i=0;i<length;++i) this->m_mac_address[i] = mac_address[i]; |
ansond | 0:b438482ebbfc | 98 | } |
ansond | 0:b438482ebbfc | 99 | return *this; |
ansond | 0:b438482ebbfc | 100 | } |
ansond | 0:b438482ebbfc | 101 | |
ansond | 0:b438482ebbfc | 102 | // add static resource |
ansond | 0:b438482ebbfc | 103 | OptionsBuilder &OptionsBuilder::addResource(const StaticResource *resource) { this->m_static_resources.push_back((StaticResource *)resource); return *this; } |
ansond | 0:b438482ebbfc | 104 | |
ansond | 0:b438482ebbfc | 105 | // add dynamic resource |
ansond | 0:b438482ebbfc | 106 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource) { this->m_dynamic_resources.push_back((DynamicResource *)resource); return *this; } |
ansond | 0:b438482ebbfc | 107 | |
ansond | 0:b438482ebbfc | 108 | // build out our immutable self |
ansond | 0:b438482ebbfc | 109 | Options *OptionsBuilder::build() { return (Options *)this; } |
ansond | 0:b438482ebbfc | 110 | } |