std::shared_ptr<RCSRemoteResourceObject> resource;
const std::string defaultKey = "Temperature";
-const std::string resourceType = "?rt=core.TemperatureSensor";
-const std::string targetUri = OC_RSRVD_WELL_KNOWN_URI + resourceType;
+const std::string resourceType = "core.TemperatureSensor";
+const std::string relativetUri = OC_RSRVD_WELL_KNOWN_URI;
std::mutex mtx;
std::condition_variable cond;
{
std::cout << "Wait 2 seconds until discovered." << std::endl;
- RCSDiscoveryManager::getInstance()->discoverResource(RCSAddress::multicast(), targetUri,
- &onResourceDiscovered);
+ RCSDiscoveryManager::getInstance()->discoverResourceByType(RCSAddress::multicast(),
+ relativetUri, resourceType, &onResourceDiscovered);
std::unique_lock<std::mutex> lck(mtx);
cond.wait_for(lck,std::chrono::seconds(2));
/**
* @file
*
- * This file contains the RCSDiscoveryManager class which provide API to discover the Resource in the network
+ * This file contains the RCSDiscoveryManager class which provide APIs to discover the Resource in the network
*
*/
{
namespace Service
{
-
class RCSRemoteResourceObject;
class RCSAddress;
/**
- * This class contains the resource discovery method.
+ * This class contains the resource discovery methods.
*
* @see RCSRemoteResourceObject
*/
class RCSDiscoveryManager
{
- public:
+ public:
+
+ /**
+ * Typedef for callback of discoverResource APIs
+ *
+ * @see discoverResource
+ */
+ typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
+ ResourceDiscoveredCallback;
+
+ /**
+ * Returns RCSDiscoveryManager instance.
+ *
+ */
+ static RCSDiscoveryManager* getInstance();
+
+ /**
+ * API for discovering the resource of Interest, regardless of URI and resource type
+ *
+ * @param address A RCSAddress object
+ * @param cb A callback to obtain discovered resource
+ *
+ * @throws InvalidParameterException If cb is empty.
+ *
+ * @note The callback will be invoked in an internal thread.
+ *
+ * @see RCSAddress
+ *
+ */
+ void discoverResource(const RCSAddress& address, ResourceDiscoveredCallback cb);
- /**
- * Typedef for callback of discoverResource API
- *
- * @see discoverResource
- */
- typedef std::function< void(std::shared_ptr< RCSRemoteResourceObject >) >
- ResourceDiscoveredCallback;
+ /**
+ * API for discovering the resource of Interest, regardless of resource type
+ *
+ * @param address A RCSAddress object
+ * @param relativeURI The relative uri of resource to be searched
+ * @param cb A callback to obtain discovered resource
+ *
+ * @throws InvalidParameterException If cb is empty.
+ *
+ * @note The callback will be invoked in an internal thread.
+ *
+ * @see RCSAddress
+ *
+ */
+ void discoverResource(const RCSAddress& address, const std::string& relativeURI,
+ ResourceDiscoveredCallback cb);
- /**
- * Returns RCSDiscoveryManager instance.
- *
- */
- static RCSDiscoveryManager* getInstance();
+ /**
+ * API for discovering the resource of Interest by Resource type.
+ *
+ * @param address A RCSAddress object
+ * @param resourceType Ressource Type
+ * @param cb A callback to obtain discovered resource
+ *
+ * @throws InvalidParameterException If cb is empty.
+ *
+ * @note The callback will be invoked in an internal thread.
+ *
+ * @see RCSAddress
+ *
+ */
+ void discoverResourceByType(const RCSAddress& address, const std::string& resourceType,
+ ResourceDiscoveredCallback cb);
- /**
- * API for discovering the resource of Interest.
- *
- * @param address A RCSAddress object
- * @param resourceURI The uri of resource to be searched
- * @param cb A callback to obtain discovered resource
- *
- * @throws InvalidParameterException If cb is empty.
- *
- * @note The callback will be invoked in an internal thread.
- *
- * @see RCSAddress
- *
- */
- void discoverResource(const RCSAddress& address, const std::string& resourceURI,
- ResourceDiscoveredCallback cb);
+ /**
+ * API for discovering the resource of Interest by Resource type with provided relativeURI
+ *
+ * @param address A RCSAddress object
+ * @param relativeURI The relative uri of resource to be searched
+ * @param resourceType Ressource Type
+ * @param cb A callback to obtain discovered resource
+ *
+ * @throws InvalidParameterException If cb is empty.
+ *
+ * @note The callback will be invoked in an internal thread.
+ *
+ * @see RCSAddress
+ *
+ */
+ void discoverResourceByType(const RCSAddress& address, const std::string& relativeURI,
+ const std::string& resourceType,
+ ResourceDiscoveredCallback cb);
- private:
- RCSDiscoveryManager() = default;
- ~RCSDiscoveryManager() = default;
+ private:
+ RCSDiscoveryManager() = default;
+ ~RCSDiscoveryManager() = default;
};
}
}
}
void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
- const std::string& resourceURI, ResourceDiscoveredCallback cb)
+ ResourceDiscoveredCallback cb)
{
- SCOPE_LOG_F(DEBUG, TAG);
+ discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, "", std::move(cb));
+ }
+
+ void RCSDiscoveryManager::discoverResource(const RCSAddress& address,
+ const std::string& relativeURI, ResourceDiscoveredCallback cb)
+ {
+ discoverResourceByType(address, relativeURI, "", std::move(cb));
+ }
+
+ void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
+ const std::string& resourceType,
+ ResourceDiscoveredCallback cb)
+ {
+ discoverResourceByType(address, OC_RSRVD_WELL_KNOWN_URI, resourceType, std::move(cb));
+ }
+ void RCSDiscoveryManager::discoverResourceByType(const RCSAddress& address,
+ const std::string& relativeURI, const std::string& resourceType,
+ ResourceDiscoveredCallback cb)
+ {
if (!cb)
{
- OC_LOG(ERROR, TAG, "discoverResource NULL Callback");
- throw InvalidParameterException{ "discoverResource NULL Callback'" };
+ OC_LOG(ERROR, TAG, "discoverResourceByType NULL Callback");
+ throw InvalidParameterException { "discoverResourceByType NULL Callback'" };
}
-
- OIC::Service::discoverResource(address, resourceURI,
+ else
+ {
+ std::string resourceURI = relativeURI + "?rt=" + resourceType;
+ OIC::Service::discoverResource(address, resourceURI,
std::bind(findCallback, std::placeholders::_1, std::move(cb)));
+ }
}
}
}