/**
* @file
*
- * This file contains the RCSDiscoveryManager class which provide APIs to discover the Resource in the network
+ * This file contains the RCSDiscoveryManager class which provides APIs to discover the
+ * Resource in the network
*
*/
class RCSDiscoveryManager
{
public:
+
+ /**
+ * This class represents a discovery task.
+ *
+ * @note A discovery task will be automatically canceled when destroyed.
+ */
class DiscoveryTask
{
public:
+ /**
+ * Cancel the task for discovery request. If cancel is called in duplicate, the request is ignored.
+ */
void cancel();
+
+ /**
+ * Return a boolean value whether the discovery request is canceled or not.
+ */
bool isCanceled();
+
~DiscoveryTask();
+ public:
+
DiscoveryTask(const DiscoveryTask&) = delete;
DiscoveryTask(DiscoveryTask&&) = delete;
DiscoveryTask& operator = (const DiscoveryTask&) const = delete;
ResourceDiscoveredCallback;
/**
- * Returns RCSDiscoveryManager instance.
+ * @return RCSDiscoveryManager instance.
*
*/
static RCSDiscoveryManager* getInstance();
/**
- * API for discovering the resource of Interest, regardless of URI and resource type
+ * Discovering the resource of interest, regardless of uri and resource type.
+ * Find resource matching request periodically until returned resource is disappeared or destroyed.
+ *
+ * @return Returned object must be received.
*
- * @param address A RCSAddress object
- * @param cb A callback to obtain discovered resource
+ * @param address A RCSAddress object
+ * @param cb A callback to obtain discovered resource
*
* @throws InvalidParameterException If cb is empty.
- * @throws PlatformException If the operation failed.
*
* @note The callback will be invoked in an internal thread.
*
- * @see RCSAddress
- *
*/
std::unique_ptr<DiscoveryTask> discoverResource(const RCSAddress& address,
ResourceDiscoveredCallback cb);
/**
- * API for discovering the resource of Interest, regardless of resource type
+ * Discovering the resource of Interest, regardless of resource type.
+ * Find resource matching request periodically until returned resource is disappeared or destroyed.
+ *
+ * @return Returned object must be received.
*
- * @param address A RCSAddress object
- * @param relativeURI The relative uri of resource to be searched
- * @param cb A callback to obtain discovered resource
+ * @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.
- * @throws PlatformException If the operation failed.
*
* @note The callback will be invoked in an internal thread.
*
const std::string& relativeURI, ResourceDiscoveredCallback cb);
/**
- * API for discovering the resource of Interest by Resource type.
+ * Discovering the resource of Interest by Resource type.
+ * Find resource matching request periodically until returned resource is disappeared or destroyed.
*
- * @param address A RCSAddress object
- * @param resourceType Ressource Type
- * @param cb A callback to obtain discovered resource
+ * @return Returned object must be received.
+ *
+ * @param address A RCSAddress object
+ * @param resourceType Resource Type
+ * @param cb A callback to obtain discovered resource
*
* @throws InvalidParameterException If cb is empty.
- * @throws PlatformException If the operation failed.
*
* @note The callback will be invoked in an internal thread.
*
const std::string& resourceType, ResourceDiscoveredCallback cb);
/**
- * API for discovering the resource of Interest by Resource type with provided relativeURI
+ * Discovering the resource of Interest by Resource type with provided relativeURI.
+ * Find resource matching request periodically until returned resource is disappeared or destroyed.
+ *
+ * @return Returned object must be received.
*
- * @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
+ * @param address A RCSAddress object
+ * @param relativeURI The relative uri of resource to be searched
+ * @param resourceType Resource Type
+ * @param cb A callback to obtain discovered resource
*
* @throws InvalidParameterException If cb is empty.
- * @throws PlatformException If the operation failed.
*
* @note The callback will be invoked in an internal thread.
*
/**
* @file
*
- * This file contains the RCSActiveDiscoveryManager class which provide APIs to discover the Resource in the network
+ * This file contains the RCSActiveDiscoveryManagerImpl class which provide APIs to discover the Resource in the network
+ * and discovery requests management.
*
*/
class RCSDiscoveryManager;
class PrimitiveResource;
class RCSAddress;
+
+ /**
+ * The class contains discovery request information
+ *
+ * @see RCSDiscoveryManager
+ */
class DiscoverRequestInfo
{
public:
RCSDiscoveryManager::ResourceDiscoveredCallback m_discoverCB;
};
+ /**
+ * The class contains the resource discovery and management requests methods.
+ */
class RCSDiscoveryManagerImpl
{
static unsigned int s_uniqueId;
public:
+ /*
+ * Typedef for callback of requesting presence API
+ *
+ * @see requestMulticastPresence
+ */
typedef std::function<void(OCStackResult, const unsigned int,
const std::string&)> PresenceCallback;
+
+ /*
+ * Typedef for discovery request ID
+ *
+ * @note This is generated for each discovery request
+ */
typedef unsigned int ID;
+
+ /*
+ * Typedef for callback of discoverResource API
+ */
typedef std::function<void(std::shared_ptr< PrimitiveResource >, ID)> FindCallback;
public:
+ /*
+ * @return Returns RCSDiscoveryManagerImpl instance.
+ */
static RCSDiscoveryManagerImpl* getInstance();
DiscoverRequestInfo m_discoveryItem;
public:
+ /**
+ * Starting discovery of resource
+ *
+ * @return DiscoverTask pointer
+ *
+ * @param address A RCSAddress object
+ * @param relativeURI The relative uri of resource to be searched
+ * @param resourceType Resource Type
+ * @param cb A callback to obtain discovered resource
+ *
+ * @throws InvalidParameterException If cb is empty
+ *
+ * @note If relativeURI is empty, will be discovered after be changed into "OC_RSRVD_WELL_KNOWN_URI"
+ * @note If resourceType is empty, will be discovered all resources in network
+ *
+ * @see RCSAddress
+ * @see RCSDiscoveryManager
+ */
std::unique_ptr<RCSDiscoveryManager::DiscoveryTask> startDiscovery(const RCSAddress& address,
const std::string& relativeURI,const std::string& resourceType,
RCSDiscoveryManager::ResourceDiscoveredCallback cb);
private:
+ /**
+ * Requesting presence by multicast
+ */
void requestMulticastPresence();
+
+ /**
+ * Initializing callback of presence and polling
+ */
void initializedDiscoveryEnvironment();
+
+ /**
+ * Checking duplicated callback and invoking callback when resource is discovered
+ *
+ * @param resource A pointer of discovered resource
+ * @param discoverID The ID of discovery request
+ *
+ * @see PrimitiveResource
+ */
void findCallback(std::shared_ptr< PrimitiveResource > resource, ID discoverID);
+
+ /**
+ * Discovering resource on all requests and posting timer when timer is expired
+ */
void pollingCallback(unsigned int /*msg*/);
+
+ /**
+ * Discovering resource on all requests when supporting presence function resource enter into network
+ *
+ * @param ret Not used in this class
+ * @param seq Not used in this class
+ * @param address A address of supporting presence function resource
+ */
void presenceCallback(OCStackResult, const unsigned int,const std::string&);
- bool isDuplicatedCallback(std::shared_ptr<PrimitiveResource> resource,ID discoverID);
+
+ /**
+ * Checking duplicated callback
+ *
+ * @return The callback is duplicated or not
+ *
+ * @param resource A pointer of discovered resource
+ * @param discoverID The ID of discovery request
+ *
+ * @see PrimitiveResource
+ */
+ bool isDuplicatedCallback(std::shared_ptr<PrimitiveResource> resource, ID discoverID);
+
+ /**
+ * Creating unique id
+ *
+ * @return Returns the id
+ */
ID createId();
private: