};
}
+ inline void expectOCStackResult(OCStackResult actual,
+ std::initializer_list<OCStackResult> allowed)
+ {
+ for (auto r : allowed)
+ {
+ if (actual == r) return;
+ }
+
+ throw PlatformException(actual);
+ }
+
inline void expectOCStackResult(OCStackResult actual, OCStackResult expected)
{
if (actual != expected)
template< typename FUNC, typename ...PARAMS >
typename Detail::EnableIfTypeIs< typename Detail::ResultType< FUNC, PARAMS... >::type,
OCStackResult >::type
+ invokeOCFuncWithResultExpect(std::initializer_list<OCStackResult> allowed,
+ FUNC&& fn, PARAMS&& ...params)
+ {
+ try
+ {
+ expectOCStackResult(fn(std::forward< PARAMS >(params)...), std::move(allowed));
+ }
+ catch (const OC::OCException& e)
+ {
+ throw PlatformException(e.code());
+ }
+ }
+
+
+ template< typename FUNC, typename ...PARAMS >
+ typename Detail::EnableIfTypeIs< typename Detail::ResultType< FUNC, PARAMS... >::type,
+ OCStackResult >::type
invokeOCFunc(FUNC&& fn, PARAMS&& ...params)
{
try
{
expectOCStackResultOK(fn(std::forward< PARAMS >(params)...));
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
template< typename FUNC, typename ...PARAMS >
typename Detail::EnableIfTypeIs< typename Detail::ResultType< FUNC, PARAMS... >::type,
Detail::NotOCStackResult >::type
- invokeOC(FUNC* fn, PARAMS&& ...params)
+ invokeOCFunc(FUNC* fn, PARAMS&& ...params)
{
try
{
return fn(std::forward< PARAMS >(params)...);
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
{
expectOCStackResultOK(obj->*fn(std::forward< PARAMS >(params)...));
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
{
obj->*fn(std::forward< PARAMS >(params)...);
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
{
expectOCStackResultOK((obj.get()->*fn)(std::forward< PARAMS >(params)...));
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
{
return (obj.get()->*fn)(std::forward< PARAMS >(params)...);
}
- catch (OC::OCException& e)
+ catch (const OC::OCException& e)
{
throw PlatformException(e.code());
}
virtual ~ResourceObject();
- template< typename T >
- void setAttribute(const std::string& key, T&& value)
- {
- WeakGuard lock(*this);
- m_resourceAttributes[key] = std::forward<T>(value);
- }
+ void setAttribute(const std::string& key, const ResourceAttributes::Value&);
+ void setAttribute(const std::string& key, ResourceAttributes::Value&&);
- template< typename T >
- void setAttribute(std::string&& key, T&& value)
- {
- WeakGuard lock(*this);
- m_resourceAttributes[std::move(key)] = std::forward<T>(value);
- }
+ void setAttribute(std::string&& key, const ResourceAttributes::Value&);
+ void setAttribute(std::string&& key, ResourceAttributes::Value&&);
+
+ ResourceAttributes::Value getAttributeValue(const std::string& key) const;
template< typename T >
T getAttribute(const std::string& key) const
bool removeAttribute(const std::string& key);
- bool hasAttribute(const std::string& key) const;
+ bool containsAttribute(const std::string& key) const;
ResourceAttributes& getAttributes();
const ResourceAttributes& getAttributes() const;
}
}
+ void ResourceObject::setAttribute(const std::string& key,
+ const ResourceAttributes::Value& value)
+ {
+ WeakGuard lock(*this);
+ m_resourceAttributes[key] = value;
+ }
+
+ void ResourceObject::setAttribute(const std::string& key, ResourceAttributes::Value&& value)
+ {
+ WeakGuard lock(*this);
+ m_resourceAttributes[key] = std::move(value);
+ }
+
+ void ResourceObject::setAttribute(std::string&& key, const ResourceAttributes::Value& value)
+ {
+ WeakGuard lock(*this);
+ m_resourceAttributes[std::move(key)] = value;
+ }
+
+ void ResourceObject::setAttribute(std::string&& key, ResourceAttributes::Value&& value)
+ {
+ WeakGuard lock(*this);
+ m_resourceAttributes[std::move(key)] = std::move(value);
+ }
+
+ ResourceAttributes::Value ResourceObject::getAttributeValue(const std::string& key) const
+ {
+ WeakGuard lock(*this);
+ return m_resourceAttributes.at(key);
+ }
+
bool ResourceObject::removeAttribute(const std::string& key)
{
WeakGuard lock(*this);
return m_resourceAttributes.erase(key);
}
- bool ResourceObject::hasAttribute(const std::string& key) const
+ bool ResourceObject::containsAttribute(const std::string& key) const
{
WeakGuard lock(*this);
return m_resourceAttributes.contains(key);
{
using NotifyAllObservers = OCStackResult (*)(OCResourceHandle);
- invokeOCFunc(static_cast<NotifyAllObservers>(OC::OCPlatform::notifyAllObservers),
+ invokeOCFuncWithResultExpect(
+ { OC_STACK_OK, OC_STACK_NO_OBSERVERS },
+ static_cast< NotifyAllObservers >(OC::OCPlatform::notifyAllObservers),
m_resourceHandle);
}