Add iotivity retransmission logic about discovery. 78/115478/3 accepted/tizen_common accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable accepted/tizen/common/20170221.134913 accepted/tizen/mobile/20170221.225341 accepted/tizen/tv/20170221.225404 accepted/tizen/unified/20170309.032809 accepted/tizen/wearable/20170221.225415 submit/tizen/20170221.001425 submit/tizen_unified/20170308.100406
authorSegwon <segwon.han@samsung.com>
Mon, 20 Feb 2017 06:11:08 +0000 (15:11 +0900)
committerSegwon <segwon.han@samsung.com>
Mon, 20 Feb 2017 09:11:54 +0000 (18:11 +0900)
Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I79469ead28aeb1c8dc55857dc65268d23dce803a

daemon/discovery_provider/IotconDiscoveryProvider.cpp
daemon/discovery_provider/IotconDiscoveryProvider.h

index a9b6df1..9326e63 100755 (executable)
@@ -36,6 +36,7 @@ typedef std::list <string> discovery_complete_list_t;
 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()
 {
@@ -57,6 +58,8 @@ int conv::IotconDiscoveryProvider::init()
                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;
@@ -330,38 +333,62 @@ bool conv::IotconDiscoveryProvider::__found_resource(iotcon_remote_resource_h re
        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;
 }
 
index d0e109c..0a05566 100755 (executable)
@@ -53,6 +53,8 @@ namespace conv {
                        int init();
                        int release();
 
+                       static void discovery(void *user_data);
+
                        int start();
                        int stop();