class CloudResource;
class EnrolleeSecurity;
+ typedef std::function<void(const std::shared_ptr<OC::OCResource> resource)> onDeviceDiscoveredCb;
+
/**
* This class represents Remote Enrollee device instance. What operation the class provides:
* 1) Ownership transfer for enabling secured communication between Mediator and Enrollee
* 3) Provision Device confiruation setting, i.e. language, country, and etc
* 4) Provision Cloud information used for which Enrollee is going to register to the cloud
*/
- class RemoteEnrollee
+ class RemoteEnrollee : public std::enable_shared_from_this<RemoteEnrollee>
{
public:
~RemoteEnrollee() = default;
RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource);
ESResult discoverResource();
+
+ static void onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
+ std::weak_ptr<RemoteEnrollee> this_ptr);
+
void onDeviceDiscovered(const std::shared_ptr<OC::OCResource> resource);
void initCloudResource();
{
static const char ES_BASE_RES_URI[] = "/oic/res";
#define ES_REMOTE_ENROLLEE_TAG "ES_REMOTE_ENROLLEE"
- #define DISCOVERY_TIMEOUT 5
+ #define DISCOVERY_TIMEOUT 1
RemoteEnrollee::RemoteEnrollee(const std::shared_ptr< OC::OCResource > resource)
{
OIC_LOG(DEBUG, ES_REMOTE_ENROLLEE_TAG, "cloudPropProvisioningStatusHandler OUT");
}
+ void RemoteEnrollee::onDiscoveredCallback(const std::shared_ptr<OC::OCResource> resource,
+ std::weak_ptr<RemoteEnrollee> this_ptr)
+ {
+ OIC_LOG_V(DEBUG,ES_REMOTE_ENROLLEE_TAG,"onDiscoveredCallback()");
+ std::shared_ptr<RemoteEnrollee> Ptr = this_ptr.lock();
+ if(Ptr)
+ {
+ Ptr->onDeviceDiscovered(resource);
+ }
+ }
+
void RemoteEnrollee::onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource)
{
OIC_LOG (DEBUG, ES_REMOTE_ENROLLEE_TAG, "onDeviceDiscovered IN");
m_discoveryResponse = false;
- std::function< void (std::shared_ptr<OC::OCResource>) > onDeviceDiscoveredCb =
- std::bind(&RemoteEnrollee::onDeviceDiscovered, this,
- std::placeholders::_1);
- OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT,
- onDeviceDiscoveredCb);
+ onDeviceDiscoveredCb cb = std::bind(&RemoteEnrollee::onDiscoveredCallback,
+ std::placeholders::_1,
+ shared_from_this());
+
+ OCStackResult result = OC::OCPlatform::findResource("", query, CT_DEFAULT, cb);
if (result != OCStackResult::OC_STACK_OK)
{