This patch is for apply offline code review comments by JungHo.
several method is made by duplicated code.
unnecessary valiable is removed.
lamda functions is used instead std::bind for reduce std::bind.
logic simplify for performance and readable.
Change-Id: Iefb0f4b3ee5ae99201127cd3343ea819f9f7fd3d
Signed-off-by: jyong2.kim <jyong2.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5335
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
if(RCSRemoteResourceObjectPtr == member->getRemoteResourceObject())
{
foundMember = member;
- for(const auto &it: member->getMappingInfo())
+ for(const auto &it: member->getMappingInfos())
{
isRegistered = (it.sceneName == m_name);
}
if(RCSRemoteResourceObjectPtr == member->getRemoteResourceObject())
{
foundMember = member;
- for(const auto &it: member->getMappingInfo())
+ for(const auto &it: member->getMappingInfos())
{
if(it.sceneName == m_name)
{
std::function<void(const SceneMemberResource::Ptr&)> buildActionParams =
[&](const SceneMemberResource::Ptr & member)
{
- for(const auto &it: member->getMappingInfo())
+ for(const auto &it: member->getMappingInfos())
{
if(it.sceneName == m_name)
{
const RCSResourceAttributes SceneAction::getExecutionParameter()
{
RCSResourceAttributes attr;
- for(const auto& it : m_sceneMemberResourceObj->getMappingInfo())
+ for(const auto& it : m_sceneMemberResourceObj->getMappingInfos())
{
if(it.sceneName == m_sceneName)
{
{
namespace
{
- std::atomic_int numOfSceneCollection(0);
+ std::atomic_int g_numOfSceneCollection(0);
}
- SceneCollectionResource::Ptr SceneCollectionResource::createSceneCollectionObject()
+ SceneCollectionResource::SceneCollectionResource()
+ : m_uri(PREFIX_SCENE_COLLECTION_URI + "/" + std::to_string(g_numOfSceneCollection++)),
+ m_address(), m_sceneCollectionResourceObject(), m_requestHandler()
{
- SceneCollectionResource::Ptr sceneCollectionResource(new SceneCollectionResource());
-
- sceneCollectionResource->m_uri
- = PREFIX_SCENE_COLLECTION_URI + "/" + std::to_string(numOfSceneCollection++);
+ m_sceneCollectionResourceObject = createResourceObject();
+ }
- sceneCollectionResource->createResourceObject();
+ SceneCollectionResource::Ptr SceneCollectionResource::create()
+ {
+ SceneCollectionResource::Ptr sceneCollectionResource(new SceneCollectionResource());
sceneCollectionResource->setDefaultAttributes();
return sceneCollectionResource;
}
- SceneCollectionResource::Ptr SceneCollectionResource::createSceneCollectionObject(
+ SceneCollectionResource::Ptr SceneCollectionResource::create(
const RCSResourceAttributes & inputAttr)
{
- auto sceneCollectionResource = SceneCollectionResource::createSceneCollectionObject();
+ auto sceneCollectionResource = SceneCollectionResource::create();
if (inputAttr.contains(SCENE_KEY_NAME))
{
sceneCollectionResource->setName(inputAttr.at(SCENE_KEY_NAME).get<std::string>());
return sceneCollectionResource;
}
- void SceneCollectionResource::createResourceObject()
+ RCSResourceObject::Ptr SceneCollectionResource::createResourceObject()
{
- m_sceneCollectionResourceObject
- = RCSResourceObject::Builder(
+ return RCSResourceObject::Builder(
m_uri, SCENE_COLLECTION_RT, OC_RSRVD_INTERFACE_DEFAULT).
addInterface(OC::BATCH_INTERFACE).
setDiscoverable(true).setObservable(false).build();
= std::find(sceneValues.begin(), sceneValues.end(), sceneName);
if (foundSceneValue == sceneValues.end() && executeCB && !m_sceneMembers.size())
{
- std::thread(executeCB, SCENE_CLIENT_BADREQUEST).detach();
+ std::thread(std::move(executeCB), SCENE_CLIENT_BADREQUEST).detach();
return;
}
- auto executeHandler
- = SceneExecuteResponseHandler::createExecuteHandler(
- shared_from_this(), std::move(executeCB));
-
- {
- std::lock_guard<std::mutex> handlerlock(m_executeHandlerLock);
- m_executeHandlers.push_back(executeHandler);
- }
+ m_sceneCollectionResourceObject->setAttribute(
+ SCENE_KEY_LAST_SCENE, std::move(sceneName));
{
std::lock_guard<std::mutex> memberlock(m_sceneMemberLock);
+ auto executeHandler
+ = SceneExecuteResponseHandler::createExecuteHandler(
+ shared_from_this(), std::move(executeCB));
for (auto & it : m_sceneMembers)
{
it->execute(sceneName, std::bind(
std::placeholders::_1, std::placeholders::_2));
}
}
-
- m_sceneCollectionResourceObject->setAttribute(SCENE_KEY_LAST_SCENE, sceneName);
- }
-
- void SceneCollectionResource::onExecute(
- int errorCode, SceneExecuteCallback cb, SceneExecuteResponseHandler::Ptr ptr)
- {
- {
- std::lock_guard<std::mutex> handlerlock(m_executeHandlerLock);
- m_executeHandlers.remove(ptr);
- }
-
- std::thread(cb, errorCode).detach();
}
std::string SceneCollectionResource::getId() const
std::vector<SceneMemberResource::Ptr> SceneCollectionResource::getSceneMembers() const
{
+ std::lock_guard<std::mutex> memberlock(m_sceneMemberLock);
return m_sceneMembers;
}
+ std::vector<SceneMemberResource::Ptr> SceneCollectionResource::findSceneMembers(
+ const std::string & sceneName) const
+ {
+ std::lock_guard<std::mutex> memberlock(m_sceneMemberLock);
+ std::vector<SceneMemberResource::Ptr> retMembers;
+ std::for_each(m_sceneMembers.begin(), m_sceneMembers.end(),
+ [& retMembers, & sceneName](SceneMemberResource::Ptr pMember)
+ {
+ if(pMember->hasSceneValue(sceneName))
+ {
+ retMembers.push_back(pMember);
+ }
+ });
+ return retMembers;
+ }
+
RCSResourceObject::Ptr SceneCollectionResource::getRCSResourceObject() const
{
return m_sceneCollectionResourceObject;
auto sizeofValues = values.size();
unsigned int sameSize = 0;
- std::for_each (values.begin(), values.end(),
- [& ptr, & sizeofValues, & sameSize](const std::string & value)
+ std::for_each(values.begin(), values.end(),
+ [& ptr, & sameSize](const std::string & value)
{
try
{
auto requestKey = attributes.at(SCENE_KEY_LAST_SCENE).get<std::string>();
RCSRequest req(request.getResourceObject().lock(), request.getOCRequest());
- ptr->execute(std::string(requestKey), std::bind(
- &SceneCollectionResource::SceneCollectionRequestHandler::onExecute, this,
- std::placeholders::_1, req, attributes));
+
+ ptr->execute(std::string(requestKey),
+ [& req](int /*eCode*/)
+ {
+ // TODO need to set error code.
+ // and need to set specific attr' but this attr not to be apply to RCSResourceObject.
+ RCSSeparateResponse(req).set();
+ });
return RCSSetResponse::separate();
}
RCSSetResponse SceneCollectionResource::SceneCollectionRequestHandler::
createSceneMemberRequest(const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
{
+ int eCode = SCENE_CLIENT_BADREQUEST;
SceneCollectionResource::Ptr ptr = m_owner.lock();
- if (ptr == nullptr || !attributes.contains(SCENE_KEY_PAYLOAD_LINK))
- {
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
- }
-
- auto linkAtt = attributes.at(SCENE_KEY_PAYLOAD_LINK).get<RCSResourceAttributes>();
- if (!linkAtt.contains(SCENE_KEY_HREF) ||
- !linkAtt.contains(SCENE_KEY_RT) || !linkAtt.contains(SCENE_KEY_IF))
+ if (!ptr)
{
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+ return RCSSetResponse::create(attributes, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
- auto memberObj = createSceneMemberFromRemote(linkAtt);
- if (memberObj == nullptr)
+ RCSResourceAttributes responseAtt(attributes);
+ if (attributes.contains(SCENE_KEY_PAYLOAD_LINK))
{
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
- }
+ auto linkAtt = attributes.at(SCENE_KEY_PAYLOAD_LINK).get<RCSResourceAttributes>();
+ if (linkAtt.contains(SCENE_KEY_HREF) &&
+ linkAtt.contains(SCENE_KEY_RT) && linkAtt.contains(SCENE_KEY_IF))
+ {
+ auto memberObj = SceneMemberResource::createSceneMemberResource(linkAtt);
+ try
+ {
+ ptr->addSceneMember(memberObj);
+ }
+ catch (...)
+ {
+ return RCSSetResponse::create(responseAtt, eCode).
+ setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ }
+ eCode = SCENE_RESPONSE_SUCCESS;
- if (attributes.contains(SCENE_KEY_SCENEMAPPINGS))
- {
- addMemberInfoFromRemote(memberObj, attributes.at(
- SCENE_KEY_SCENEMAPPINGS).get<std::vector<RCSResourceAttributes>>());
+ if (attributes.contains(SCENE_KEY_SCENEMAPPINGS))
+ {
+ addMemberInfoFromRemote(memberObj, attributes.at(
+ SCENE_KEY_SCENEMAPPINGS).get<std::vector<RCSResourceAttributes>>());
+ }
+ responseAtt[SCENE_KEY_ID] = RCSResourceAttributes::Value(memberObj->getId());
+ responseAtt[SCENE_KEY_CREATEDLINK]
+ = RCSResourceAttributes::Value(memberObj->getFullUri());
+ }
}
- RCSResourceAttributes responseAtt(attributes);
- responseAtt[SCENE_KEY_ID] = RCSResourceAttributes::Value(memberObj->getId());
- responseAtt[SCENE_KEY_CREATEDLINK]
- = RCSResourceAttributes::Value(memberObj->getFullUri());
-
- return RCSSetResponse::create(responseAtt).
+ return RCSSetResponse::create(responseAtt, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
SceneCollectionResource::SceneCollectionRequestHandler::setSceneCollectionName(
const RCSRequest & /*request*/, RCSResourceAttributes & attr)
{
+ int eCode = SCENE_CLIENT_BADREQUEST;
SceneCollectionResource::Ptr ptr = m_owner.lock();
- if (ptr == nullptr)
+ if (ptr != nullptr)
{
- return RCSSetResponse::create(attr, SCENE_CLIENT_BADREQUEST).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ eCode = SCENE_RESPONSE_SUCCESS;
+ ptr->setName(attr.at(SCENE_KEY_NAME).get<std::string>());
}
- ptr->setName(attr.at(SCENE_KEY_NAME).get<std::string>());
-
- return RCSSetResponse::create(attr).
+ return RCSSetResponse::create(attr, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
- SceneMemberResource::Ptr
- SceneCollectionResource::SceneCollectionRequestHandler::createSceneMemberFromRemote(
- RCSResourceAttributes & linkAtt)
- {
- auto memberObj = SceneMemberResource::createSceneMemberResource(linkAtt);
-
- try
- {
- SceneCollectionResource::Ptr ptr = m_owner.lock();
- ptr->addSceneMember(memberObj);
- } catch (...)
- {
- return nullptr;
- }
-
- return memberObj;
- }
-
void SceneCollectionResource::SceneCollectionRequestHandler::addMemberInfoFromRemote(
SceneMemberResource::Ptr memberObj, std::vector<RCSResourceAttributes> mInfo)
{
- std::for_each (mInfo.begin(), mInfo.end(),
+ std::for_each(mInfo.begin(), mInfo.end(),
[& memberObj](const RCSResourceAttributes & att)
{
- memberObj->addMappingInfo(SceneMemberResource::MappingInfo(
- att.at(SCENE_KEY_SCENE).get<std::string>(),
- att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
- att.at(SCENE_KEY_MEMBERVALUE)));
+ memberObj->addMappingInfo(SceneMemberResource::MappingInfo::create(att));
});
}
- void SceneCollectionResource::SceneCollectionRequestHandler::
- onExecute(int /*errorCode*/, const RCSRequest & request, RCSResourceAttributes & /*att*/)
- {
- // TODO need to set error code.
- // and need to set specific attr' but this attr not to be apply to RCSResourceObject.
- RCSSeparateResponse(request).set();
- }
-
void SceneCollectionResource::SceneExecuteResponseHandler::
onResponse(const RCSResourceAttributes & /*attributes*/, int errorCode)
{
executeHandler->m_numOfMembers = ptr->m_sceneMembers.size();
executeHandler->m_responseMembers = 0;
- executeHandler->m_cb = std::bind(
- &SceneCollectionResource::onExecute, ptr,
- std::placeholders::_1, std::move(executeCB), executeHandler);
+ executeHandler->m_cb =
+ [executeCB](int eCode)
+ {
+ std::thread(std::move(executeCB), eCode).detach();
+ };
executeHandler->m_owner
= std::weak_ptr<SceneCollectionResource>(ptr);
return executeHandler;
}
+
}
}
~SceneCollectionResource() = default;
- static SceneCollectionResource::Ptr createSceneCollectionObject();
- static SceneCollectionResource::Ptr createSceneCollectionObject(
- const RCSResourceAttributes &);
+ static SceneCollectionResource::Ptr create();
+ static SceneCollectionResource::Ptr create(const RCSResourceAttributes &);
void addScene(std::string &&);
void addScene(const std::string &);
std::vector<SceneMemberResource::Ptr> getSceneMembers() const;
+ std::vector<SceneMemberResource::Ptr> findSceneMembers(
+ const std::string & sceneName) const;
+
RCSResourceObject::Ptr getRCSResourceObject() const;
private:
RCSSetResponse onSetRequest(
const RCSRequest &, RCSResourceAttributes &);
- void onExecute(int, const RCSRequest &, RCSResourceAttributes &);
private:
RCSSetResponse addSceneRequest(
RCSSetResponse setSceneCollectionName(
const RCSRequest &, RCSResourceAttributes &);
- SceneMemberResource::Ptr createSceneMemberFromRemote(RCSResourceAttributes &);
void addMemberInfoFromRemote(SceneMemberResource::Ptr,
std::vector<RCSResourceAttributes>);
};
std::string m_address;
RCSResourceObject::Ptr m_sceneCollectionResourceObject;
- std::mutex m_sceneMemberLock;
+ mutable std::mutex m_sceneMemberLock;
std::vector<SceneMemberResource::Ptr> m_sceneMembers;
SceneCollectionRequestHandler m_requestHandler;
- std::mutex m_executeHandlerLock;
- std::list<SceneExecuteResponseHandler::Ptr> m_executeHandlers;
- SceneCollectionResource() = default;
+ SceneCollectionResource();
SceneCollectionResource(const SceneCollectionResource &) = delete;
SceneCollectionResource & operator = (
SceneCollectionResource & operator = (
SceneCollectionResource &&) = delete;
- void createResourceObject();
+ RCSResourceObject::Ptr createResourceObject();
void setDefaultAttributes();
void initSetRequestHandler();
-
- void onExecute(int, SceneExecuteCallback, SceneExecuteResponseHandler::Ptr);
};
}
}
SceneCollection::Ptr SceneList::addNewSceneCollection()
{
auto sceneCollectionResObj =
- SceneCollectionResource::createSceneCollectionObject();
+ SceneCollectionResource::create();
SceneListResource::getInstance()->addSceneCollectionResource(sceneCollectionResObj);
return SceneCollection::Ptr(new SceneCollection(sceneCollectionResObj));
namespace Service
{
SceneListResource::SceneListResource()
- : m_sceneListName(), m_sceneListObj()
+ : m_sceneListObj(createResourceObject())
{
- m_sceneListObj = RCSResourceObject::Builder(
- SCENE_LIST_URI, SCENE_LIST_RT, OC_RSRVD_INTERFACE_DEFAULT).
- addInterface(OC::BATCH_INTERFACE).
- setDiscoverable(true).setObservable(false).build();
-
m_sceneListObj->setAttribute(SCENE_KEY_NAME, SCENE_LIST_DEFAULT_NAME);
m_sceneListObj->setAttribute(SCENE_KEY_RTS, SCENE_LIST_RT);
return & instance;
}
+ RCSResourceObject::Ptr SceneListResource::createResourceObject()
+ {
+ return RCSResourceObject::Builder(
+ SCENE_LIST_URI, SCENE_LIST_RT, OC_RSRVD_INTERFACE_DEFAULT).
+ addInterface(OC::BATCH_INTERFACE).
+ setDiscoverable(true).setObservable(false).build();
+ }
+
void SceneListResource::addSceneCollectionResource(
SceneCollectionResource::Ptr newObject)
{
std::string SceneListResource::getName() const
{
- return m_sceneListName;
+ return m_sceneListObj->getAttributeValue(SCENE_KEY_NAME).get<std::string>();
}
void SceneListResource::setName(std::string && newName)
{
- m_sceneListName = std::move(newName);
-
- RCSResourceObject::LockGuard guard(m_sceneListObj);
- m_sceneListObj->setAttribute(SCENE_KEY_NAME, m_sceneListName);
+ m_sceneListObj->setAttribute(SCENE_KEY_NAME, std::move(newName));
}
void SceneListResource::setName(const std::string & newName)
std::vector<SceneCollectionResource::Ptr> SceneListResource::getSceneCollections() const
{
+ std::lock_guard<std::mutex> collectionlock(m_sceneCollectionLock);
return m_sceneCollections;
}
+ RCSResourceObject::Ptr SceneListResource::getResourceObject() const
+ {
+ return m_sceneListObj;
+ }
+
std::vector<RCSResourceAttributes> SceneListResource::getChildrenAttributes() const
{
std::vector<RCSResourceAttributes> childrenAttrs;
RCSSetResponse SceneListResource::SceneListRequestHandler::onSetRequest(
const RCSRequest & request, RCSResourceAttributes & attributes)
{
+ RCSResourceAttributes responseAttr;
+ int eCode = SCENE_CLIENT_BADREQUEST;
+
if(request.getInterface() == LINK_BATCH)
{
auto newObject
- = SceneCollectionResource::createSceneCollectionObject(attributes);
+ = SceneCollectionResource::create(attributes);
SceneListResource::getInstance()->addSceneCollectionResource(newObject);
responseAtt[SCENE_KEY_PAYLOAD_LINK]
= RCSResourceAttributes::Value(uri);
- return RCSSetResponse::create(responseAtt, SCENE_RESPONSE_SUCCESS).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ responseAttr = responseAtt;
+ eCode = SCENE_RESPONSE_SUCCESS;
}
- if (attributes.contains(SCENE_KEY_NAME))
+ else if (attributes.contains(SCENE_KEY_NAME))
{
SceneListResource::getInstance()->setName(
attributes.at(SCENE_KEY_NAME).get<std::string>());
- return RCSSetResponse::create(attributes, SCENE_RESPONSE_SUCCESS).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+
+ responseAttr = attributes;
+ eCode = SCENE_RESPONSE_SUCCESS;
+ }
+ else
+ {
+ responseAttr = attributes;
+ eCode = SCENE_CLIENT_BADREQUEST;
}
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
+ return RCSSetResponse::create(responseAttr, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
RCSGetResponse SceneListResource::SceneListRequestHandler::onGetRequest(
- const RCSRequest & request, RCSResourceAttributes & attributes)
+ const RCSRequest & request, RCSResourceAttributes & /*attributes*/)
{
if(request.getInterface() != OC::DEFAULT_INTERFACE)
auto childrenAttrs = SceneListResource::getInstance()->getChildrenAttributes();
- RCSResourceAttributes retAttr = attributes;
+ RCSResourceAttributes retAttr;
+
+ {
+ RCSResourceObject::LockGuard lock(
+ SceneListResource::getInstance()->getResourceObject());
+ retAttr = SceneListResource::getInstance()->getResourceObject()->getAttributes();
+ }
+
if (childrenAttrs.size())
{
retAttr[SCENE_KEY_CHILD] = childrenAttrs;
return RCSGetResponse::create(retAttr);
}
+
}
}
std::vector<RCSResourceAttributes> getChildrenAttributes() const;
+ RCSResourceObject::Ptr getResourceObject() const;
+
private:
class SceneListRequestHandler
{
static RCSGetResponse onGetRequest(const RCSRequest &, RCSResourceAttributes &);
};
- std::string m_sceneListName;
RCSResourceObject::Ptr m_sceneListObj;
- std::mutex m_sceneCollectionLock;
+ mutable std::mutex m_sceneCollectionLock;
std::vector<SceneCollectionResource::Ptr> m_sceneCollections;
SceneListResource();
SceneListResource(SceneListResource &&) = delete;
SceneListResource & operator = (SceneListResource &&) = delete;
+
+ RCSResourceObject::Ptr createResourceObject();
};
}
}
{
namespace
{
- std::atomic_int numOfSceneMember(0);
+ std::atomic_int g_numOfSceneMember(0);
}
SceneMemberResource::Ptr
SceneMemberResource::Ptr sceneMemberResource(new SceneMemberResource());
sceneMemberResource->m_uri = PREFIX_SCENE_MEMBER_URI + "/" +
- std::to_string(numOfSceneMember++);
+ std::to_string(g_numOfSceneMember++);
sceneMemberResource->m_remoteMemberObj = remoteObject;
mappingInfo.erase(foundMInfo);
}
RCSResourceAttributes newMapInfo;
- newMapInfo[SCENE_KEY_SCENE] = RCSResourceAttributes::Value(mInfo.sceneName);
- newMapInfo[SCENE_KEY_MEMBERPROPERTY] = RCSResourceAttributes::Value(mInfo.key);
- newMapInfo[SCENE_KEY_MEMBERVALUE] = mInfo.value;
+ newMapInfo[SCENE_KEY_SCENE] = RCSResourceAttributes::Value(std::move(mInfo.sceneName));
+ newMapInfo[SCENE_KEY_MEMBERPROPERTY] = RCSResourceAttributes::Value(std::move(mInfo.key));
+ newMapInfo[SCENE_KEY_MEMBERVALUE] = std::move(mInfo.value);
mappingInfo.push_back(newMapInfo);
m_sceneMemberResourceObj->setAttribute(SCENE_KEY_SCENEMAPPINGS, mappingInfo);
addMappingInfo(MappingInfo(mInfo));
}
- std::vector<SceneMemberResource::MappingInfo> SceneMemberResource::getMappingInfo()
+ std::vector<SceneMemberResource::MappingInfo> SceneMemberResource::getMappingInfos() const
{
std::vector<MappingInfo> retMInfo;
std::for_each(mInfo.begin(), mInfo.end(),
[& retMInfo](const RCSResourceAttributes & att)
{
- MappingInfo info(att.at(SCENE_KEY_SCENE).get<std::string>(),
- att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
- att.at(SCENE_KEY_MEMBERVALUE));
- retMInfo.push_back(info);
+ retMInfo.push_back(MappingInfo::create(att));
});
return retMInfo;
{
RCSResourceAttributes setAtt;
- auto mInfo = getMappingInfo();
- std::for_each (mInfo.begin(), mInfo.end(),
+ auto mInfo = getMappingInfos();
+ std::for_each(mInfo.begin(), mInfo.end(),
[& setAtt, & sceneName](const MappingInfo & info)
{
if(info.sceneName == sceneName)
return m_sceneMemberResourceObj->getAttributeValue(SCENE_KEY_NAME).toString();
}
+ std::vector<SceneMemberResource::MappingInfo> SceneMemberResource::findMappingInfos(
+ const std::string & sceneValue) const
+ {
+ auto mInfo = getMappingInfos();
+ std::vector<MappingInfo> retMInfo;
+
+ std::for_each(mInfo.begin(), mInfo.end(),
+ [& retMInfo, & sceneValue](const MappingInfo & info)
+ {
+ if(info.sceneName == sceneValue)
+ {
+ retMInfo.push_back(MappingInfo(info));
+ }
+ });
+ return retMInfo;
+ }
+
+ bool SceneMemberResource::hasSceneValue(const std::string & sceneValue) const
+ {
+ auto mInfo = getMappingInfos();
+ if (std::find_if(mInfo.begin(), mInfo.end(),
+ [& sceneValue](const MappingInfo & info) -> bool
+ {
+ return info.sceneName == sceneValue;
+ }) != mInfo.end())
+ {
+ return true;
+ }
+ return false;
+ }
+
+ SceneMemberResource::MappingInfo
+ SceneMemberResource::MappingInfo::create(const RCSResourceAttributes & att)
+ {
+ return MappingInfo(att.at(SCENE_KEY_SCENE).get<std::string>(),
+ att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
+ att.at(SCENE_KEY_MEMBERVALUE));
+ }
+
RCSSetResponse SceneMemberResource::SceneMemberRequestHandler::
onSetRequest(const RCSRequest & request, RCSResourceAttributes & attributes)
{
SceneMemberResource::SceneMemberRequestHandler::addMappingInfos(
const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
{
+ int eCode = SCENE_RESPONSE_SUCCESS;
auto ptr = m_owner.lock();
if (!ptr)
{
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ eCode = SCENE_CLIENT_BADREQUEST;
+ }
+ else
+ {
+ auto mInfo = attributes.at(SCENE_KEY_SCENEMAPPINGS).
+ get<std::vector<RCSResourceAttributes>>();
+ std::for_each(mInfo.begin(), mInfo.end(),
+ [& ptr](const RCSResourceAttributes & att)
+ {
+ ptr->addMappingInfo(SceneMemberResource::MappingInfo::create(att));
+ });
}
- auto mInfo = attributes.at(SCENE_KEY_SCENEMAPPINGS).
- get<std::vector<RCSResourceAttributes>>();
- std::for_each (mInfo.begin(), mInfo.end(),
- [& ptr](const RCSResourceAttributes & att)
- {
- ptr->addMappingInfo(SceneMemberResource::MappingInfo(
- att.at(SCENE_KEY_SCENE).get<std::string>(),
- att.at(SCENE_KEY_MEMBERPROPERTY).get<std::string>(),
- att.at(SCENE_KEY_MEMBERVALUE)));
- });
-
- return RCSSetResponse::create(attributes).
+ return RCSSetResponse::create(attributes, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
SceneMemberResource::SceneMemberRequestHandler::setSceneMemberName(
const RCSRequest & /*request*/, RCSResourceAttributes & attributes)
{
+ int eCode = SCENE_RESPONSE_SUCCESS;
auto ptr = m_owner.lock();
if (!ptr)
{
- return RCSSetResponse::create(attributes, SCENE_CLIENT_BADREQUEST).
- setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
+ eCode = SCENE_CLIENT_BADREQUEST;
+ }
+ else
+ {
+ ptr->setName(attributes.at(SCENE_KEY_NAME).get<std::string>());
}
- ptr->setName(attributes.at(SCENE_KEY_NAME).get<std::string>());
-
- return RCSSetResponse::create(attributes).
+ return RCSSetResponse::create(attributes, eCode).
setAcceptanceMethod(RCSSetResponse::AcceptanceMethod::IGNORE);
}
}
MappingInfo(MappingInfo &&) = default;
MappingInfo(const MappingInfo &) = default;
+ static MappingInfo create(const RCSResourceAttributes &);
+
std::string sceneName; ///< name of scene value
std::string key; ///< key to set at attributes of remote resource
RCSResourceAttributes::Value value; ///< val to set at attributes of remote resource
/**
* Returns all Mapping information of a scene member resource.
*/
- std::vector<MappingInfo> getMappingInfo();
+ std::vector<MappingInfo> getMappingInfos() const;
+
+ std::vector<MappingInfo> findMappingInfos(const std::string & sceneValue) const;
+
+ bool hasSceneValue(const std::string &) const;
/**
* Returns ID of a Scene member resource.