Add new methods to primitiveServeResource(removeAttribute and setAttribute with rval ref key)
Change-Id: I796599584fab56dfef697140b819069e3a9612b7
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1464
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
void subscribePresence(OCDoHandle& handle, const std::string& host,
OCConnectivityType connectivityType, SubscribeCallback presenceHandler)
{
- OCStackResult result = OC::OCPlatform::subscribePresence(
- handle, host, connectivityType, presenceHandler);
+ using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+ const std::string&, OCConnectivityType, SubscribeCallback);
- expectOCStackResultOK(result);
+ invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
+ handle, host, connectivityType, presenceHandler);
}
void subscribePresence(OCDoHandle& handle, const std::string& host,
const std::string& resourceType, OCConnectivityType connectivityType,
SubscribeCallback presenceHandler)
{
- OCStackResult result = OC::OCPlatform::subscribePresence(handle, host, resourceType,
- connectivityType, presenceHandler);
+ using SubscribePresence = OCStackResult (*)(OC::OCPlatform::OCPresenceHandle&,
+ const std::string&, const std::string&, OCConnectivityType, SubscribeCallback);
- expectOCStackResultOK(result);
+ invokeOCFunc(static_cast<SubscribePresence>(OC::OCPlatform::subscribePresence),
+ handle, host, resourceType, connectivityType, presenceHandler);
}
void unsubscribePresence(OCDoHandle handle)
{
- expectOCStackResultOK(OC::OCPlatform::unsubscribePresence(handle));
+ invokeOCFunc(OC::OCPlatform::unsubscribePresence, handle);
}
virtual ~PrimitiveServerResource();
template< typename T >
- void setAttribute(const std::string& key, const T &value)
+ void setAttribute(const std::string& key, T&& value)
{
WeakGuard lock(*this);
- m_resourceAttributes[key] = value;
+ m_resourceAttributes[key] = std::forward<T>(value);
+ }
+
+ template< typename T >
+ void setAttribute(std::string&& key, T&& value)
+ {
+ WeakGuard lock(*this);
+ m_resourceAttributes[std::move(key)] = std::forward<T>(value);
}
template< typename T >
return m_resourceAttributes.at(key).get< T >();
}
+ bool removeAttribute(const std::string& key);
+
bool hasAttribute(const std::string& key) const;
ResourceAttributes& getAttributes();
PrimitiveServerResource::Builder::Builder(const std::string& uri, const std::string& type,
const std::string& interface) :
- m_uri{ uri }, m_type{ type }, m_interface{ interface }, m_properties{ 0 }
+ m_uri{ uri }, m_type{ type }, m_interface{ interface },
+ m_properties{ OC_DISCOVERABLE | OC_OBSERVABLE }
{
}
try
{
- expectOCStackResultOK(
- OC::OCPlatform::registerResource(handle, m_uri, m_type, m_interface,
- entityHandler, m_properties));
+ using RegisterResource = OCStackResult (*)(OCResourceHandle&, std::string&,
+ const std::string&, const std::string&, OC::EntityHandler, uint8_t);
+
+ invokeOCFunc(static_cast<RegisterResource>(OC::OCPlatform::registerResource),
+ handle, m_uri, m_type, m_interface, entityHandler, m_properties);
}
catch (OC::OCException& e)
{
}
}
+ bool PrimitiveServerResource::removeAttribute(const std::string& key)
+ {
+ WeakGuard lock(*this);
+ return m_resourceAttributes.erase(key);
+ }
+
bool PrimitiveServerResource::hasAttribute(const std::string& key) const
{
WeakGuard lock(*this);
void PrimitiveServerResource::notify() const
{
- expectOCStackResultOK(OC::OCPlatform::notifyAllObservers(m_resourceHandle));
+ using NotifyAllObservers = OCStackResult (*)(OCResourceHandle);
+
+ invokeOCFunc(static_cast<NotifyAllObservers>(OC::OCPlatform::notifyAllObservers),
+ m_resourceHandle);
}
OCEntityHandlerResult PrimitiveServerResource::entityHandler(