added max-age and content-format
Fork of mbedConnectorInterface by
api/OptionsBuilder.cpp@2:853f9ecc12df, 2015-01-27 (annotated)
- Committer:
- sam_grove
- Date:
- Tue Jan 27 23:41:34 2015 +0000
- Revision:
- 2:853f9ecc12df
- Parent:
- 0:b438482ebbfc
- Child:
- 15:8ada80242804
Use auto-format on code and add markup to render class documentation
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 |
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 | #include "OptionsBuilder.h" |
sam_grove | 2:853f9ecc12df | 24 | |
sam_grove | 2:853f9ecc12df | 25 | // external included configuration file for the endpoint... |
sam_grove | 2:853f9ecc12df | 26 | #include "configuration.h" |
sam_grove | 2:853f9ecc12df | 27 | |
sam_grove | 2:853f9ecc12df | 28 | // Connector namespace |
sam_grove | 2:853f9ecc12df | 29 | namespace Connector { |
sam_grove | 2:853f9ecc12df | 30 | |
sam_grove | 2:853f9ecc12df | 31 | // Constructor |
sam_grove | 2:853f9ecc12df | 32 | OptionsBuilder::OptionsBuilder() |
sam_grove | 2:853f9ecc12df | 33 | { |
sam_grove | 2:853f9ecc12df | 34 | this->m_lifetime = NSP_LIFE_TIME; |
sam_grove | 2:853f9ecc12df | 35 | this->m_domain = NSP_DOMAIN; |
sam_grove | 2:853f9ecc12df | 36 | this->m_endpoint_type = NSP_ENDPOINT_TYPE; |
sam_grove | 2:853f9ecc12df | 37 | this->m_node_name = NODE_NAME; |
sam_grove | 2:853f9ecc12df | 38 | this->m_channel_list = NODE_CHANNEL_LIST; |
sam_grove | 2:853f9ecc12df | 39 | this->m_rd_update_period = NSP_RD_UPDATE_PERIOD; |
sam_grove | 2:853f9ecc12df | 40 | this->m_nsp_port = NSP_COAP_UDP_PORT; |
sam_grove | 2:853f9ecc12df | 41 | |
sam_grove | 2:853f9ecc12df | 42 | memset(this->m_nsp_address,0,NSP_IP_ADDRESS_LENGTH); |
sam_grove | 2:853f9ecc12df | 43 | memset(this->m_mac_address,0,NODE_MAC_ADDRESS_LENGTH); |
sam_grove | 2:853f9ecc12df | 44 | this->m_static_resources.clear(); |
sam_grove | 2:853f9ecc12df | 45 | this->m_dynamic_resources.clear(); |
sam_grove | 2:853f9ecc12df | 46 | } |
sam_grove | 2:853f9ecc12df | 47 | |
sam_grove | 2:853f9ecc12df | 48 | // Copy Constructor |
sam_grove | 2:853f9ecc12df | 49 | OptionsBuilder::OptionsBuilder(const OptionsBuilder &ob) |
sam_grove | 2:853f9ecc12df | 50 | { |
sam_grove | 2:853f9ecc12df | 51 | this->m_lifetime = ob.m_lifetime; |
sam_grove | 2:853f9ecc12df | 52 | this->m_domain = ob.m_domain; |
sam_grove | 2:853f9ecc12df | 53 | this->m_endpoint_type = ob.m_endpoint_type; |
sam_grove | 2:853f9ecc12df | 54 | this->m_static_resources = ob.m_static_resources; |
sam_grove | 2:853f9ecc12df | 55 | this->m_dynamic_resources = ob.m_dynamic_resources; |
sam_grove | 2:853f9ecc12df | 56 | } |
sam_grove | 2:853f9ecc12df | 57 | |
sam_grove | 2:853f9ecc12df | 58 | // Destructor |
sam_grove | 2:853f9ecc12df | 59 | OptionsBuilder::~OptionsBuilder() |
sam_grove | 2:853f9ecc12df | 60 | { |
sam_grove | 2:853f9ecc12df | 61 | this->m_static_resources.clear(); |
sam_grove | 2:853f9ecc12df | 62 | this->m_dynamic_resources.clear(); |
sam_grove | 2:853f9ecc12df | 63 | } |
sam_grove | 2:853f9ecc12df | 64 | |
sam_grove | 2:853f9ecc12df | 65 | // set lifetime |
sam_grove | 2:853f9ecc12df | 66 | OptionsBuilder &OptionsBuilder::setLifetime(const char *lifetime) |
sam_grove | 2:853f9ecc12df | 67 | { |
sam_grove | 2:853f9ecc12df | 68 | this->m_lifetime = (char *)lifetime; |
sam_grove | 2:853f9ecc12df | 69 | return *this; |
sam_grove | 2:853f9ecc12df | 70 | } |
sam_grove | 2:853f9ecc12df | 71 | |
sam_grove | 2:853f9ecc12df | 72 | // set domain |
sam_grove | 2:853f9ecc12df | 73 | OptionsBuilder &OptionsBuilder::setDomain(const char *domain) |
sam_grove | 2:853f9ecc12df | 74 | { |
sam_grove | 2:853f9ecc12df | 75 | this->m_domain = string(domain); |
sam_grove | 2:853f9ecc12df | 76 | return *this; |
sam_grove | 2:853f9ecc12df | 77 | } |
sam_grove | 2:853f9ecc12df | 78 | |
sam_grove | 2:853f9ecc12df | 79 | // set endpoint nodename |
sam_grove | 2:853f9ecc12df | 80 | OptionsBuilder &OptionsBuilder::setEndpointNodename(const char *node_name) |
sam_grove | 2:853f9ecc12df | 81 | { |
sam_grove | 2:853f9ecc12df | 82 | this->m_node_name = string(node_name); |
sam_grove | 2:853f9ecc12df | 83 | return *this; |
sam_grove | 2:853f9ecc12df | 84 | } |
sam_grove | 2:853f9ecc12df | 85 | |
sam_grove | 2:853f9ecc12df | 86 | // set lifetime |
sam_grove | 2:853f9ecc12df | 87 | OptionsBuilder &OptionsBuilder::setEndpointType(const char *endpoint_type) |
sam_grove | 2:853f9ecc12df | 88 | { |
sam_grove | 2:853f9ecc12df | 89 | this->m_endpoint_type = string(endpoint_type); |
sam_grove | 2:853f9ecc12df | 90 | return *this; |
sam_grove | 2:853f9ecc12df | 91 | } |
sam_grove | 2:853f9ecc12df | 92 | |
sam_grove | 2:853f9ecc12df | 93 | // set NSP port number |
sam_grove | 2:853f9ecc12df | 94 | OptionsBuilder &OptionsBuilder::setNSPPortNumber(const int port_num) |
sam_grove | 2:853f9ecc12df | 95 | { |
sam_grove | 2:853f9ecc12df | 96 | this->m_nsp_port = port_num; |
sam_grove | 2:853f9ecc12df | 97 | return *this; |
sam_grove | 2:853f9ecc12df | 98 | } |
sam_grove | 2:853f9ecc12df | 99 | |
sam_grove | 2:853f9ecc12df | 100 | // set low level radio channel list |
sam_grove | 2:853f9ecc12df | 101 | OptionsBuilder &OptionsBuilder::setRadioChannelList(const uint32_t channel_list) |
sam_grove | 2:853f9ecc12df | 102 | { |
sam_grove | 2:853f9ecc12df | 103 | this->m_channel_list = channel_list; |
sam_grove | 2:853f9ecc12df | 104 | return *this; |
sam_grove | 2:853f9ecc12df | 105 | } |
sam_grove | 2:853f9ecc12df | 106 | |
sam_grove | 2:853f9ecc12df | 107 | // set NSP read update period |
sam_grove | 2:853f9ecc12df | 108 | OptionsBuilder &OptionsBuilder::setReadUpdatePeriod(const int rd_update_period) |
sam_grove | 2:853f9ecc12df | 109 | { |
sam_grove | 2:853f9ecc12df | 110 | this->m_rd_update_period = rd_update_period; |
sam_grove | 2:853f9ecc12df | 111 | return *this; |
sam_grove | 2:853f9ecc12df | 112 | } |
sam_grove | 2:853f9ecc12df | 113 | |
sam_grove | 2:853f9ecc12df | 114 | // set NSP address |
sam_grove | 2:853f9ecc12df | 115 | OptionsBuilder &OptionsBuilder::setNSPAddress(const uint8_t *nsp_address,const int nsp_address_length) |
sam_grove | 2:853f9ecc12df | 116 | { |
sam_grove | 2:853f9ecc12df | 117 | if (nsp_address != NULL && nsp_address_length > 0) { |
sam_grove | 2:853f9ecc12df | 118 | int length = nsp_address_length; |
sam_grove | 2:853f9ecc12df | 119 | if (length > NSP_IP_ADDRESS_LENGTH) length = NSP_IP_ADDRESS_LENGTH; |
sam_grove | 2:853f9ecc12df | 120 | for(int i=0; i<length; ++i) this->m_nsp_address[i] = nsp_address[i]; |
sam_grove | 2:853f9ecc12df | 121 | } |
sam_grove | 2:853f9ecc12df | 122 | return *this; |
sam_grove | 2:853f9ecc12df | 123 | } |
sam_grove | 2:853f9ecc12df | 124 | |
sam_grove | 2:853f9ecc12df | 125 | // set MAC address |
sam_grove | 2:853f9ecc12df | 126 | OptionsBuilder &OptionsBuilder::setMACAddress(const uint8_t *mac_address,const int mac_address_length) |
sam_grove | 2:853f9ecc12df | 127 | { |
sam_grove | 2:853f9ecc12df | 128 | if (mac_address != NULL && mac_address_length > 0) { |
sam_grove | 2:853f9ecc12df | 129 | int length = mac_address_length; |
sam_grove | 2:853f9ecc12df | 130 | if (length > NODE_MAC_ADDRESS_LENGTH) length = NODE_MAC_ADDRESS_LENGTH; |
sam_grove | 2:853f9ecc12df | 131 | for(int i=0; i<length; ++i) this->m_mac_address[i] = mac_address[i]; |
sam_grove | 2:853f9ecc12df | 132 | } |
sam_grove | 2:853f9ecc12df | 133 | return *this; |
sam_grove | 2:853f9ecc12df | 134 | } |
sam_grove | 2:853f9ecc12df | 135 | |
sam_grove | 2:853f9ecc12df | 136 | // add static resource |
sam_grove | 2:853f9ecc12df | 137 | OptionsBuilder &OptionsBuilder::addResource(const StaticResource *resource) |
sam_grove | 2:853f9ecc12df | 138 | { |
sam_grove | 2:853f9ecc12df | 139 | this->m_static_resources.push_back((StaticResource *)resource); |
sam_grove | 2:853f9ecc12df | 140 | return *this; |
sam_grove | 2:853f9ecc12df | 141 | } |
sam_grove | 2:853f9ecc12df | 142 | |
sam_grove | 2:853f9ecc12df | 143 | // add dynamic resource |
sam_grove | 2:853f9ecc12df | 144 | OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource) |
sam_grove | 2:853f9ecc12df | 145 | { |
sam_grove | 2:853f9ecc12df | 146 | this->m_dynamic_resources.push_back((DynamicResource *)resource); |
sam_grove | 2:853f9ecc12df | 147 | return *this; |
sam_grove | 2:853f9ecc12df | 148 | } |
sam_grove | 2:853f9ecc12df | 149 | |
sam_grove | 2:853f9ecc12df | 150 | // build out our immutable self |
sam_grove | 2:853f9ecc12df | 151 | Options *OptionsBuilder::build() |
sam_grove | 2:853f9ecc12df | 152 | { |
sam_grove | 2:853f9ecc12df | 153 | return (Options *)this; |
sam_grove | 2:853f9ecc12df | 154 | } |
sam_grove | 2:853f9ecc12df | 155 | |
sam_grove | 2:853f9ecc12df | 156 | } // namespace Connector |