From 6768956d2bdbf81f1180caf137e246d877ef1992 Mon Sep 17 00:00:00 2001 From: "jaesick.shin" Date: Tue, 8 Mar 2016 12:09:48 +0900 Subject: [PATCH] RE ServerBuilder always included "oic.if.baseline" interface. If User don't setting "oic.if.baseline" interface. but, RE ServerBuilder always support "oic.if.baseline" interface. setDefaultInterface API(Modified comment of header) and Modified Initialize of Builder Constructor If it is not called, the interface passed to the constructor is the default. Added, Duplicate check the resource property of interface and resourcetype. Change-Id: Ie25f1135cc7c99fbf5fe1b04f3121b9e2707be21 Signed-off-by: jaesick.shin Reviewed-on: https://gerrit.iotivity.org/gerrit/5529 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- .../include/RCSResourceObject.h | 2 +- .../src/serverBuilder/src/RCSResourceObject.cpp | 25 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/service/resource-encapsulation/include/RCSResourceObject.h b/service/resource-encapsulation/include/RCSResourceObject.h index 00644cf..8a58b15 100644 --- a/service/resource-encapsulation/include/RCSResourceObject.h +++ b/service/resource-encapsulation/include/RCSResourceObject.h @@ -162,7 +162,7 @@ namespace OIC /** * Sets the default interface. - * If the default interface is not sepcified, "oic.if.baseline" + * If it is not called, the interface passed to the constructor is the default. * * @param interface default interface name * diff --git a/service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp b/service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp index db834f5..4d37f6f 100644 --- a/service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp +++ b/service/resource-encapsulation/src/serverBuilder/src/RCSResourceObject.cpp @@ -121,6 +121,16 @@ namespace return {}; } + void insertValue(std::vector& container, std::string value) + { + if (value.empty()) return; + + if (std::find(container.begin(), container.end(), value) == container.end()) + { + container.push_back(std::move(value)); + } + } + } // unnamed namespace namespace OIC @@ -132,22 +142,29 @@ namespace OIC std::string interface) : m_uri{ std::move(uri) }, m_types{ std::move(type) }, - m_interfaces{ std::move(interface) }, - m_defaultInterface { BASELINE_INTERFACE }, + m_interfaces{ }, + m_defaultInterface{ interface }, m_properties{ OC_DISCOVERABLE | OC_OBSERVABLE }, m_resourceAttributes{ } { + addInterface(interface); + addInterface(BASELINE_INTERFACE); + + if (m_defaultInterface.empty()) + { + m_defaultInterface = BASELINE_INTERFACE; + } } RCSResourceObject::Builder& RCSResourceObject::Builder::addInterface(std::string interface) { - m_interfaces.push_back(std::move(interface)); + insertValue(m_interfaces, std::move(interface)); return *this; } RCSResourceObject::Builder& RCSResourceObject::Builder::addType(std::string type) { - m_types.push_back(std::move(type)); + insertValue(m_types, std::move(type)); return *this; } -- 2.7.4