Handler setters should accept null to erase one set earlier.
It is to make apis consistent between c++ and android.
Additionally an issue caused by using old exception class name is fixed.
Change-Id: I273755b6d2ab48a489d1829aa932b2f675332db6
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2915
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
*
* @throws RcsException
* If the object is destroyed.
- * @throws NullPointerException
- * If handler is null.
- *
*/
public void setGetRequestHandler(GetRequestHandler handler)
throws RcsException {
assertAlive();
- if (handler == null) throw new NullPointerException("handler is null.");
nativeSetGetRequestHandler(handler);
}
*
* @throws RcsException
* If the object is destroyed.
- * @throws NullPointerException
- * If handler is null.
*
*/
public void setSetRequestHandler(SetRequestHandler handler)
throws RcsException {
assertAlive();
- if (handler == null) throw new NullPointerException("handler is null.");
-
nativeSetSetRequestHandler(handler);
}
auto res = getResource(env, obj);
VERIFY_NO_EXC(env);
- res->setGetRequestHandler(std::bind(onGetRequest, std::placeholders::_1, std::placeholders::_2,
- JavaGlobalRef{ env, listenerObj }));
+ if (listenerObj)
+ {
+ res->setGetRequestHandler(std::bind(onGetRequest, std::placeholders::_1, std::placeholders::_2,
+ JavaGlobalRef{ env, listenerObj }));
+ }
+ else
+ {
+ res->setGetRequestHandler({ });
+ }
}
JNIEXPORT void JNICALL
auto res = getResource(env, obj);
VERIFY_NO_EXC(env);
- res->setSetRequestHandler(std::bind(onSetRequest, std::placeholders::_1, std::placeholders::_2,
- JavaGlobalRef{ env, listenerObj }));
+ if (listenerObj)
+ {
+ res->setSetRequestHandler(std::bind(onSetRequest, std::placeholders::_1,
+ std::placeholders::_2, JavaGlobalRef{ env, listenerObj }));
+ }
+ else
+ {
+ res->setSetRequestHandler({ });
+ }
}
JNIEXPORT void JNICALL
RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
relativetUri, resourceType, &onResourceDiscovered);
}
- catch(PlatformException e)
+ catch(const RCSPlatformException& e)
{
- std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
+ std::cout << e.what() << std::endl;
}
std::unique_lock<std::mutex> lck(mtx);
cond.wait_for(lck, std::chrono::seconds(2));
std::cin >> addressInput;
- if (addressInput == multicastAdd)
+ try
{
- try
- {
- discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
- relativeUri, resourceType, &onResourceDiscovered);
- }
- catch (PlatformException e)
- {
- std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
- }
+ RCSAddress targetAddress = addressInput == multicastAdd ? RCSAddress::multicast() :
+ RCSAddress::unicast(addressInput);
+
+ discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(
+ targetAddress, relativeUri, resourceType, &onResourceDiscovered);
}
- else
+ catch (const RCSPlatformException& e)
{
- try
- {
- discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::unicast
- (addressInput), relativeUri, resourceType, &onResourceDiscovered);
- }
- catch (PlatformException e)
- {
- std::cout << "Platform Exception while calling discoverResourceByType" << std::endl;
- }
+ std::cout << e.what() << std::endl;
}
}