Added clear code on discovery start 40/109940/2
authorkmook <kmook.choi@samsung.com>
Thu, 12 Jan 2017 08:36:09 +0000 (17:36 +0900)
committerkmook <kmook.choi@samsung.com>
Thu, 12 Jan 2017 12:34:22 +0000 (21:34 +0900)
Change-Id: I6acb5bc0d9f3939b987d991850446373c0f1010f
Signed-off-by: kmook <kmook.choi@samsung.com>
msf_tizen_client/src/MSFDSearchProvider.cpp
msf_tizen_client/src/Search.cpp
msf_tizen_client/src/mDNSSearchProvider.cpp

index baa13ff..6f17c20 100755 (executable)
@@ -106,6 +106,9 @@ void MSFDSearchProvider::start()
        if (searching) {
                stop();
        }
+
+       aliveMap.clear();
+
        clearServices();
 
        createMSFD();
index ad830ec..fe0e5c8 100755 (executable)
@@ -115,6 +115,12 @@ Search::Search()
        searching_now = false;
        searchListener = NULL;
 
+       int i;
+
+       for (i=0; i < NUM_OF_THREADS; i++) {
+               threads[i] = 0;
+       }
+
        search_list.push_back(this);
 }
 
@@ -149,24 +155,11 @@ Service Search::getServiceById(string id)
 bool Search::start()
 {
        MSF_DBG("Search::start()");
-       if (searching_now == false) {
-               if (search_ref_count == 0) {
-                       search_ref_count++;
-
-                       searching_now = true;
 
+       search_ref_count++;
+       searching_now = true;
 
-                       startDiscovery();
-               } else {
-                       search_ref_count++;
-
-                       searching_now = true;
-
-                       if (searchListener != NULL) {
-                               searchListener->onStart();
-                       }
-               }
-       }
+       startDiscovery();
 
        return true;
 }
@@ -176,15 +169,9 @@ bool Search::stop()
        MSF_DBG("search stop");
        if (searching_now == true) {
                search_ref_count--;
-               searching_now = false;
 
-               if (search_ref_count == 0) {
-                       stopDiscovery();
-               } else {
-                       if (searchListener != NULL) {
-                               searchListener->onStop();
-                       }
-               }
+               stopDiscovery();
+               searching_now = false;
        }
 
        return true;
@@ -236,14 +223,18 @@ void Search::startDiscovery()
 
        provider_mdns.start();
 
-       ret = pthread_create(&threads[MSFD_THREAD_NUMBER], NULL, pt_startMSFD, NULL);
-       if (ret == -1) {
-               MSF_DBG("MSFD thread create failed");
+       if ( threads[MSFD_THREAD_NUMBER] == 0 ) {
+               ret = pthread_create(&threads[MSFD_THREAD_NUMBER], NULL, pt_startMSFD, NULL);
+               if (ret == -1) {
+                       MSF_DBG("MSFD thread create failed");
+               }
        }
 
-       ret = pthread_create(&threads[UPDATE_THREAD_NUMBER], NULL, pt_update_alivemap, NULL);
-       if (ret == -1) {
-               MSF_DBG("update thread create failed");
+       if ( threads[UPDATE_THREAD_NUMBER] == 0 ) {
+               ret = pthread_create(&threads[UPDATE_THREAD_NUMBER], NULL, pt_update_alivemap, NULL);
+               if (ret == -1) {
+                       MSF_DBG("update thread create failed");
+               }
        }
 
        onStart();
@@ -267,6 +258,9 @@ void Search::stopDiscovery()
        pthread_cancel(threads[UPDATE_THREAD_NUMBER]);
        pthread_join(threads[UPDATE_THREAD_NUMBER], NULL);
 
+       threads[MSFD_THREAD_NUMBER] = 0;
+       threads[UPDATE_THREAD_NUMBER] = 0;
+
        MSF_DBG("MSFD thread joined");
        MSF_DBG("update alivemap thread joined");
 }
index 7384522..0990295 100755 (executable)
@@ -241,6 +241,8 @@ void mDNSSearchProvider::start()
                g_service = 0;
        }
 
+       aliveMap.clear();
+
        int rv = dnssd_initialize();
        if (rv != DNSSD_ERROR_NONE) {
                MSF_DBG("mDNS is not initialzed.");