typedef std::map <string, conv::ResourceHandle> discovery_process_map_t;
static discovery_complete_list_t discovery_complete_list;
static discovery_process_map_t discovery_process_map;
+static int discovery_timer_id;
conv::IotconDiscoveryProvider::IotconDiscoveryProvider()
{
delete resource_h_map;
resource_h_map = new(std::nothrow) resource_h_map_t;
+ discovery_timer_id = -1;
+
_D("IotconDiscoveryProvider init done");
return CONV_ERROR_NONE;
return IOTCON_FUNC_CONTINUE;
}
-int conv::IotconDiscoveryProvider::start()
+void conv::IotconDiscoveryProvider::discovery(void* user_data)
{
- int ret;
- _D("iotcon discovery provider start..");
iotcon_query_h query;
- discovery_complete_list.clear();
- discovery_process_map.clear();
+ int ret;
ret = iotcon_query_create(&query);
-
- IF_FAIL_RETURN_TAG((ret == IOTCON_ERROR_NONE), CONV_ERROR_INVALID_OPERATION, _E, "failed on iotcon_query_create[%d]", ret);
+ if (ret != IOTCON_ERROR_NONE) {
+ _E("failed on iotcon_query_create(%d)", ret);
+ return;
+ }
ret = iotcon_query_set_resource_type(query, CONV_RESOURCE_TYPE_TIZEN_D2D_SERVICE);
if (IOTCON_ERROR_NONE != ret) {
_E("iotcon_query_set_resource_type() Fail(%d)", ret);
iotcon_query_destroy(query);
- return CONV_ERROR_INVALID_OPERATION;
+ return;
}
+ _D("iotcon find resource called..");
ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_IPV4_ONLY | IOTCON_CONNECTIVITY_PREFER_UDP,
query, __found_resource, NULL);
iotcon_query_destroy(query);
- IF_FAIL_RETURN_TAG((ret == IOTCON_ERROR_NONE), CONV_ERROR_INVALID_OPERATION, _E, "failed on iotcon_find_resource[%d]", ret);
+ if (ret != IOTCON_ERROR_NONE) {
+ _E("failed on iotcon_find_resource(%d)", ret);
+ return;
+ }
+}
+
+int conv::IotconDiscoveryProvider::start()
+{
+ _D("iotcon discovery provider start..");
+
+ discovery_complete_list.clear();
+ discovery_process_map.clear();
+
+ if (discovery_timer_id != -1) {
+ conv::util::miscStopTimer(discovery_timer_id);
+ return CONV_ERROR_NOT_SUPPORTED;
+ }
+
+ int interval = 2;
+ discovery(NULL);
+ discovery_timer_id = conv::util::miscStartTimer(discovery, interval, NULL);
return CONV_ERROR_NONE;
}
int conv::IotconDiscoveryProvider::stop()
{
+ if (discovery_timer_id != -1) {
+ conv::util::miscStopTimer(discovery_timer_id);
+ discovery_timer_id = -1;
+ }
return CONV_ERROR_NONE;
}