{
std::string host = address;
std::string uri = OC_RSRVD_WELL_KNOWN_URI + std::string("?rt=") + HOSTING_RESOURSE_TYPE;
- OCConnectivityType type = OCConnectivityType::CT_DEFAULT;
- discoveryManager->discoverResource(host, uri, type, pDiscoveryCB);
+ RCSAddress rcsAddress = RCSAddress::unicast(host);
+ discoveryManager->discoverResource(rcsAddress, uri, pDiscoveryCB);
}
void ResourceHosting::discoverHandler(RemoteObjectPtr remoteResource)
#include "octypes.h"
#include "ResourceClient.h"
+#include "RCSAddress.h"
#include "PresenceSubscriber.h"
#include "HostingObject.h"
#include "PrimitiveResource.h"
#include "ResourceClient.h"
#include "RCSResourceAttributes.h"
#include "OCPlatform.h"
+#include "RCSAddress.h"
using namespace std;
using namespace OC;
try
{
+
uri = OC_RSRVD_WELL_KNOWN_URI + uri + "?rt=" + rt;
+
+ //getting the object of RCSAddress for multicast discovery
+ RCSAddress rcsAddress = RCSAddress::multicast();
+
//discover the resource in the network
- discoveryManagerInstance->discoverResource(address, uri , CT_DEFAULT, &OnResourceDiscovered);
+ discoveryManagerInstance->discoverResource(rcsAddress, uri , &OnResourceDiscovered);
}
catch (InvalidParameterException e)
{
class RCSException;
class RemoteResourceObject;
class PrimitiveResource;
+ class RCSAddress;
/**
* @class BadRequestException
*
* @return ResourceState - current state of the resource.
*
+ * @throw BadRequestException
+ *
* @see ResourceState
*/
ResourceState getState() const ;
*
* @param cb - callback to get updated resourceAttributes.
*
+ * @throw InvalidParameterException
+ *
* @see CacheUpdatedCallback
*
* NOTE: Developer can call this API any number of time. Developer should
*
* @return CacheState - Current state of the Cache.
*
+ * @throw BadRequestException
+ *
* @see CacheState
*
*/
* @details This API send a get request to the resource of interest and provides the attributes
* to the caller in the RemoteAttributesReceivedCallback.
*
+ *
+ * @throw InvalidParameterException
+ *
* @see RCSResourceAttributes::Value
*/
void getRemoteAttributes(RemoteAttributesReceivedCallback cb);
* @param attributes - resourceAttributes data to set
* @param cb - callback on setting resourceAttributes data.
*
+ * @throw InvalidParameterException
+ *
*/
void setRemoteAttributes(const RCSResourceAttributes &attributes, RemoteAttributesSetCallback cb);
/**
* API for discovering the resource of Interest.
*
- * @param host - host of the Resource
+ * @param address - RCSAddress object
* @param resourceURI - uri of resource to be searched
- * @param connectivityType - connection type
* @param cb - callback to obtain discovered resource
*
* @throw InvalidParameterException : This API throws the InvalidParameterException if any of
* the parameter is invalid.
- *
+ * @RCSAddress
*/
- void discoverResource(std::string host, std::string resourceURI,
- OCConnectivityType connectivityType,
+ void discoverResource(const RCSAddress &address, const std::string &resourceURI,
OnResourceDiscoveredCallback cb);
-
private:
/**
void RemoteResourceObject::startCaching(CacheUpdatedCallback cb)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching entry");
- if (true == m_cachingFlag)
+ if (!cb)
{
- OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching : already Started");
+ throw InvalidParameterException {"startCaching : Callback is NULL" };
}
else
{
- try
+ if (true == m_cachingFlag)
{
- CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
- std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
- REPORT_FREQUENCY::UPTODATE, 0);
-
- m_cacheId = cacheId;
- m_cachingFlag = true;
- OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
+ OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching : already Started");
}
- catch (std::exception &exception)
+ else
{
- throw InvalidParameterException {"startCaching : Callback is NULL" };
+ try
+ {
+ CacheID cacheId = ResourceCacheManager::getInstance()->requestResourceCache(m_primitiveResource,
+ std::bind(cachingCallback, std::placeholders::_1, std::placeholders::_2, cb),
+ REPORT_FREQUENCY::UPTODATE, 0);
+
+ m_cacheId = cacheId;
+ m_cachingFlag = true;
+ OC_LOG_V(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::startCaching CACHE ID %d", cacheId);
+ }
+ catch (std::exception &exception)
+ {
+ throw InvalidParameterException {"startCaching : error" };
+ }
}
}
}
void RemoteResourceObject::getRemoteAttributes(RemoteAttributesReceivedCallback cb)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes entry");
-
- m_primitiveResource->requestGet(std::bind(getCallback, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, cb));
-
+ if (!cb)
+ {
+ throw InvalidParameterException {"getRemoteAttributes : Callback is NULL" };
+ }
+ else
+ {
+ m_primitiveResource->requestGet(std::bind(getCallback, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, cb));
+ }
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::getRemoteAttributes exit");
}
RemoteAttributesSetCallback cb)
{
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes entry");
-
- m_primitiveResource->requestSet(attribute, std::bind(setCallback, std::placeholders::_1,
- std::placeholders::_2, std::placeholders::_3, cb));
-
+ if (!cb)
+ {
+ throw InvalidParameterException {"setRemoteAttributes : Callback is NULL" };
+ }
+ else
+ {
+ m_primitiveResource->requestSet(attribute, std::bind(setCallback, std::placeholders::_1,
+ std::placeholders::_2, std::placeholders::_3, cb));
+ }
OC_LOG(DEBUG, CLIENT_W_TAG, "RemoteResourceObject::setRemoteAttributes exit");
}
return s_instance;
}
- void DiscoveryManager::discoverResource(std::string host, std::string resourceURI,
- OCConnectivityType connectivityType,
+ void DiscoveryManager::discoverResource(const RCSAddress &address, const std::string &resourceURI,
OnResourceDiscoveredCallback cb)
{
OC_LOG(ERROR, CLIENT_W_TAG, "discoverResource NULL Callback");
throw InvalidParameterException { "discoverResource NULL Callback'" };
}
- OIC::Service::discoverResource(host, resourceURI, connectivityType, std::bind(findCallback,
+ OIC::Service::discoverResource(address, resourceURI, std::bind(findCallback,
std::placeholders::_1,
cb));
#include "ResourceClient.h"
#include "RCSResourceObject.h"
#include "OCPlatform.h"
+#include "RCSAddress.h"
#define RESOURCEURI "/a/TemperatureSensor"
#define RESOURCETYPE "Resource.Hosting"
createResource();
DiscoveryManager *instance = DiscoveryManager::getInstance();
cbresult = false;
-
- instance->discoverResource("", uri, CT_DEFAULT, &onResourceDiscoveredCallback);
+ RCSAddress rcsAddress = RCSAddress::multicast();
+ instance->discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
sleep(2);
EXPECT_TRUE(object != NULL);
destroyResource();
TEST(ResourceClientTest, testIsMonitoring)
{
createResource();
- manager->DiscoveryManager::discoverResource("", uri, CT_DEFAULT, &onResourceDiscoveredCallback);
+ RCSAddress rcsAddress = RCSAddress::multicast();
+ manager->DiscoveryManager::discoverResource(rcsAddress, uri , &onResourceDiscoveredCallback);
sleep(1);
destroyResource();
EXPECT_FALSE(object->isMonitoring());
{
createResource();
DiscoveryManager *instance = DiscoveryManager::getInstance();
- EXPECT_THROW(instance->discoverResource("", "", CT_DEFAULT, &onResourceDiscoveredCallback),
+ RCSAddress rcsAddress = RCSAddress::multicast();
+ EXPECT_THROW(instance->discoverResource(rcsAddress, "", &onResourceDiscoveredCallback),
InvalidParameterException);
destroyResource();
}
{
createResource();
DiscoveryManager *instance = DiscoveryManager::getInstance();
- EXPECT_THROW(instance->discoverResource("", uri, CT_DEFAULT, NULL), InvalidParameterException);
+ RCSAddress rcsAddress = RCSAddress::multicast();
+ EXPECT_THROW(instance->discoverResource(rcsAddress, uri , NULL), InvalidParameterException);
destroyResource();
object->stopMonitoring();
}