added max-age and content-format
Fork of mbedConnectorInterface by
Diff: api/OptionsBuilder.cpp
- Revision:
- 0:b438482ebbfc
- Child:
- 2:853f9ecc12df
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/api/OptionsBuilder.cpp Tue Jan 27 22:23:51 2015 +0000 @@ -0,0 +1,110 @@ +/** + * @file OptionsBuilder.cpp + * @brief mbed CoAP OptionsBuilder class implementation + * @author Doug Anson/Chris Paola + * @version 1.0 + * @see + * + * Copyright (c) 2014 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + #include "OptionsBuilder.h" + + // external included configuration file for the endpoint... + #include "configuration.h" + + // Connector namespace + namespace Connector { + // Constructor + OptionsBuilder::OptionsBuilder() { + this->m_lifetime = NSP_LIFE_TIME; + this->m_domain = NSP_DOMAIN; + this->m_endpoint_type = NSP_ENDPOINT_TYPE; + this->m_node_name = NODE_NAME; + this->m_channel_list = NODE_CHANNEL_LIST; + this->m_rd_update_period = NSP_RD_UPDATE_PERIOD; + this->m_nsp_port = NSP_COAP_UDP_PORT; + + memset(this->m_nsp_address,0,NSP_IP_ADDRESS_LENGTH); + memset(this->m_mac_address,0,NODE_MAC_ADDRESS_LENGTH); + this->m_static_resources.clear(); + this->m_dynamic_resources.clear(); + } + + // Copy Constructor + OptionsBuilder::OptionsBuilder(const OptionsBuilder &ob) { + this->m_lifetime = ob.m_lifetime; + this->m_domain = ob.m_domain; + this->m_endpoint_type = ob.m_endpoint_type; + this->m_static_resources = ob.m_static_resources; + this->m_dynamic_resources = ob.m_dynamic_resources; + } + + // Destructor + OptionsBuilder::~OptionsBuilder() { + this->m_static_resources.clear(); + this->m_dynamic_resources.clear(); + } + + // set lifetime + OptionsBuilder &OptionsBuilder::setLifetime(const char *lifetime) { this->m_lifetime = (char *)lifetime; return *this; } + + // set domain + OptionsBuilder &OptionsBuilder::setDomain(const char *domain) { this->m_domain = string(domain); return *this; } + + // set endpoint nodename + OptionsBuilder &OptionsBuilder::setEndpointNodename(const char *node_name) { this->m_node_name = string(node_name); return *this; } + + // set lifetime + OptionsBuilder &OptionsBuilder::setEndpointType(const char *endpoint_type) { this->m_endpoint_type = string(endpoint_type); return *this; } + + // set NSP port number + OptionsBuilder &OptionsBuilder::setNSPPortNumber(const int port_num) { this->m_nsp_port = port_num; return *this; } + + // set low level radio channel list + OptionsBuilder &OptionsBuilder::setRadioChannelList(const uint32_t channel_list) { this->m_channel_list = channel_list; return *this; } + + // set NSP read update period + OptionsBuilder &OptionsBuilder::setReadUpdatePeriod(const int rd_update_period) { this->m_rd_update_period = rd_update_period; return *this; } + + // set NSP address + OptionsBuilder &OptionsBuilder::setNSPAddress(const uint8_t *nsp_address,const int nsp_address_length) { + if (nsp_address != NULL && nsp_address_length > 0) { + int length = nsp_address_length; + if (length > NSP_IP_ADDRESS_LENGTH) length = NSP_IP_ADDRESS_LENGTH; + for(int i=0;i<length;++i) this->m_nsp_address[i] = nsp_address[i]; + } + return *this; + } + + // set MAC address + OptionsBuilder &OptionsBuilder::setMACAddress(const uint8_t *mac_address,const int mac_address_length) { + if (mac_address != NULL && mac_address_length > 0) { + int length = mac_address_length; + if (length > NODE_MAC_ADDRESS_LENGTH) length = NODE_MAC_ADDRESS_LENGTH; + for(int i=0;i<length;++i) this->m_mac_address[i] = mac_address[i]; + } + return *this; + } + + // add static resource + OptionsBuilder &OptionsBuilder::addResource(const StaticResource *resource) { this->m_static_resources.push_back((StaticResource *)resource); return *this; } + + // add dynamic resource + OptionsBuilder &OptionsBuilder::addResource(const DynamicResource *resource) { this->m_dynamic_resources.push_back((DynamicResource *)resource); return *this; } + + // build out our immutable self + Options *OptionsBuilder::build() { return (Options *)this; } + } \ No newline at end of file