X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=service%2Fresource-encapsulation%2Fsrc%2FresourceClient%2FRCSRemoteResourceObject.cpp;h=54e7ce815dfc8d0f83fa2f5e1095c21786dfe45c;hb=390866079e285d2c74918432c0d597d5da52f8a0;hp=369ef511786c1ddc4e2782a45169a03e7f76d2d7;hpb=8c01dff2c5bc5496f7dc1632c498943ec6ecb015;p=platform%2Fupstream%2Fiotivity.git diff --git a/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp b/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp index 369ef51..54e7ce8 100644 --- a/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp +++ b/service/resource-encapsulation/src/resourceClient/RCSRemoteResourceObject.cpp @@ -99,20 +99,20 @@ namespace return OC_STACK_OK; } - void setCallback(const HeaderOptions&, const ResponseStatement& response, int, + void setRemoteAttributesCb(const HeaderOptions&, const ResponseStatement& response, int eCode, RCSRemoteResourceObject::RemoteAttributesSetCallback onRemoteAttributesSet) { SCOPE_LOG_F(DEBUG, TAG); - onRemoteAttributesSet(response.getAttributes()); + onRemoteAttributesSet(response.getAttributes(), eCode); } - void getCallback(const HeaderOptions&, const ResponseStatement& response, int, + void getRemoteAttributesCb(const HeaderOptions&, const ResponseStatement& response, int eCode, RCSRemoteResourceObject::RemoteAttributesGetCallback onRemoteAttributesReceived) { SCOPE_LOG_F(DEBUG, TAG); - onRemoteAttributesReceived(response.getAttributes()); + onRemoteAttributesReceived(response.getAttributes(), eCode); } } @@ -120,9 +120,56 @@ namespace OIC { namespace Service { + + RCSQueryParams& RCSQueryParams::setResourceInterface(std::string resourceInterface) + { + m_resourceInterface = std::move(resourceInterface); + return *this; + } + + RCSQueryParams& RCSQueryParams::setResourceType(std::string resourceType) + { + m_resourceType = std::move(resourceType); + return *this; + } + + RCSQueryParams& RCSQueryParams::put(std::string key, std::string value) + { + m_map[std::move(key)] = std::move(value); + return *this; + } + + std::string RCSQueryParams::getResourceInterface() const + { + return m_resourceInterface; + } + + std::string RCSQueryParams::getResourceType() const + { + return m_resourceType; + } + + std::string RCSQueryParams::get(const std::string& key) const + { + try + { + return m_map.at(key); + } + catch (const std::out_of_range&) + { + throw RCSInvalidKeyException(key + " is an invalid key"); + } + } + + const RCSQueryParams::Map& RCSQueryParams::getAll() const + { + return m_map; + } + + RCSRemoteResourceObject::RCSRemoteResourceObject( - std::shared_ptr< PrimitiveResource > pResource) : - m_primitiveResource{ pResource }, + std::shared_ptr< PrimitiveResource > primtiveResource) : + m_primitiveResource{ primtiveResource }, m_cacheId{ }, m_brokerId{ } { @@ -132,8 +179,26 @@ namespace OIC { SCOPE_LOG_F(DEBUG, TAG); - stopCaching(); - stopMonitoring(); + try{ + stopCaching(); + stopMonitoring(); + } + catch(std::exception &e){ + OIC_LOG_V(ERROR, TAG, "%s", e.what()); + } + + } + + RCSRemoteResourceObject::Ptr RCSRemoteResourceObject::fromOCResource( + std::shared_ptr< OC::OCResource > ocResource) + { + if (!ocResource) + { + throw RCSInvalidParameterException("the oc resource must not be nullptr."); + } + + return std::make_shared< RCSRemoteResourceObject >( + PrimitiveResource::create(ocResource)); } bool RCSRemoteResourceObject::isMonitoring() const @@ -157,13 +222,13 @@ namespace OIC if (!cb) { - throw InvalidParameterException{ "startMonitoring : Callback is NULL" }; + throw RCSInvalidParameterException{ "startMonitoring : Callback is NULL" }; } if (isMonitoring()) { - OC_LOG(DEBUG, TAG, "startMonitoring : already started"); - throw BadRequestException{ "Monitoring already started." }; + OIC_LOG(DEBUG, TAG, "startMonitoring : already started"); + throw RCSBadRequestException{ "Monitoring already started." }; } m_brokerId = ResourceBroker::getInstance()->hostResource(m_primitiveResource, @@ -176,7 +241,7 @@ namespace OIC if (!isMonitoring()) { - OC_LOG(DEBUG, TAG, "stopMonitoring : Not started"); + OIC_LOG(DEBUG, TAG, "stopMonitoring : Not started"); return; } @@ -208,8 +273,8 @@ namespace OIC if (isCaching()) { - OC_LOG(DEBUG, TAG, "startCaching : already Started"); - throw BadRequestException{ "Caching already started." }; + OIC_LOG(DEBUG, TAG, "startCaching : already Started"); + throw RCSBadRequestException{ "Caching already started." }; } if (cb) @@ -225,7 +290,7 @@ namespace OIC m_primitiveResource, { }, REPORT_FREQUENCY::NONE, 0); } - OC_LOG_V(DEBUG, TAG, "startCaching CACHE ID %d", m_cacheId); + OIC_LOG_V(DEBUG, TAG, "startCaching CACHE ID %d", m_cacheId); } void RCSRemoteResourceObject::stopCaching() @@ -234,7 +299,7 @@ namespace OIC if (!isCaching()) { - OC_LOG(DEBUG, TAG, "Caching already terminated"); + OIC_LOG(DEBUG, TAG, "Caching already terminated"); return; } @@ -271,12 +336,12 @@ namespace OIC if (!isCaching()) { - throw BadRequestException{ "Caching not started." }; + throw RCSBadRequestException{ "Caching not started." }; } if (!isCachedAvailable()) { - throw BadRequestException{ "Cache data is not available." }; + throw RCSBadRequestException{ "Cache data is not available." }; } return ResourceCacheManager::getInstance()->getCachedData(m_primitiveResource); @@ -316,14 +381,43 @@ namespace OIC if (!cb) { - throw InvalidParameterException{ "getRemoteAttributes : Callback is empty" }; + throw RCSInvalidParameterException{ "getRemoteAttributes : Callback is empty" }; } m_primitiveResource->requestGet( - std::bind(getCallback, std::placeholders::_1, std::placeholders::_2, + std::bind(getRemoteAttributesCb, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::move(cb))); } + void RCSRemoteResourceObject::get(GetCallback cb) + { + SCOPE_LOG_F(DEBUG, TAG); + + if (!cb) + { + throw RCSInvalidParameterException{ "get : Callback is empty" }; + } + + m_primitiveResource->requestGet(std::move(cb)); + } + + void RCSRemoteResourceObject::get(const RCSQueryParams& queryParams, GetCallback cb) + { + SCOPE_LOG_F(DEBUG, TAG); + + if (!cb) + { + throw RCSInvalidParameterException{ "get : Callback is empty" }; + } + + const auto& paramMap = queryParams.getAll(); + + m_primitiveResource->requestGetWith( + queryParams.getResourceType(), queryParams.getResourceInterface(), + OC::QueryParamsMap{ paramMap.begin(), paramMap.end() }, + std::move(cb)); + } + void RCSRemoteResourceObject::setRemoteAttributes(const RCSResourceAttributes& attribute, RemoteAttributesSetCallback cb) { @@ -331,12 +425,43 @@ namespace OIC if (!cb) { - throw InvalidParameterException{ "setRemoteAttributes : Callback is empty" }; + throw RCSInvalidParameterException{ "setRemoteAttributes : Callback is empty" }; } m_primitiveResource->requestSet(attribute, - std::bind(setCallback, std::placeholders::_1, std::placeholders::_2, + std::bind(setRemoteAttributesCb, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, cb)); } + + void RCSRemoteResourceObject::set(const RCSResourceAttributes& attributes, SetCallback cb) + { + SCOPE_LOG_F(DEBUG, TAG); + + if (!cb) + { + throw RCSInvalidParameterException{ "set : Callback is empty" }; + } + + m_primitiveResource->requestSet(attributes, std::move(cb)); + } + + void RCSRemoteResourceObject::set(const RCSQueryParams& queryParams, + const RCSResourceAttributes& attributes, SetCallback cb) + { + SCOPE_LOG_F(DEBUG, TAG); + + if (!cb) + { + throw RCSInvalidParameterException{ "set : Callback is empty" }; + } + + const auto& paramMap = queryParams.getAll(); + + m_primitiveResource->requestSetWith( + queryParams.getResourceType(), queryParams.getResourceInterface(), + OC::QueryParamsMap{ paramMap.begin(), paramMap.end() }, attributes, + std::move(cb)); + } + } }