Fixed bugs 77/81777/3
authorkmook <kmook.choi@samsung.com>
Thu, 28 Jul 2016 09:17:23 +0000 (18:17 +0900)
committerKyoung-Mook Choi <kmook.choi@samsung.com>
Thu, 28 Jul 2016 11:17:18 +0000 (04:17 -0700)
 - applied error handling in appcomm service
 - bug fixes in discovery finish callback handling

Change-Id: I299fb0f132e3d52a1b34dc666c903cdb83ddc638
Signed-off-by: kmook <kmook.choi@samsung.com>
daemon/DiscoveryManager.cpp
daemon/ServiceManager.cpp
daemon/Util.cpp
daemon/service_provider/AppCommServiceInfo.h
daemon/service_provider/AppCommServiceProvider.cpp
lib/conv_lib.cpp

index f0c1062..33d849c 100755 (executable)
@@ -90,11 +90,12 @@ int conv::DiscoveryManager::notifyTimeOut(std::string client)
        }
 
        // 3. Notify the client that the requested discovery has been finished
-       RequestMap::iterator request_itr = __requestMap.find(client);
-       if (request_itr != __requestMap.end()) {
+       RequestMap::iterator requestIter = __requestMap.find(client);
+       if (requestIter != __requestMap.end()) {
                Json noData;
-               Request* currentRequest = request_itr->second;
+               Request* currentRequest = requestIter->second;
                currentRequest->publish(CONV_DISCOVERY_FINISHED, noData);
+               __requestMap.erase(requestIter);
        }
 
        return CONV_ERROR_NONE;
index bef1df0..07615a0 100755 (executable)
@@ -64,7 +64,7 @@ int conv::ServiceManager::init()
 
        if ( error < 0 ) {
                _E("vconf error (%d)", error);
-               // temporary code
+//             temporary code for binary without vconf
                __activationState = 1;
        }
 
@@ -75,6 +75,7 @@ int conv::ServiceManager::init()
        }
 
        error = vconf_notify_key_changed(VCONFKEY_SETAPPL_D2D_CONVERGENCE, vconf_update_cb, this);
+//     temporarily commented out for binary without vconf
 //     IF_FAIL_RETURN_TAG(error >= 0, CONV_ERROR_INVALID_OPERATION, _E, "vconf error (%d)", error);
 
        return CONV_ERROR_NONE;
index e1c4a80..b377608 100755 (executable)
@@ -169,7 +169,9 @@ bool conv::util::isServiceActivated(int serviceValue)
 
        if (error != 0) {
                _D("vconf_get_int failed %d", error);
-               return false;
+//             return false;
+//             temporary code for binary without vconf
+               return true;
        }
 
        if ((serviceValue & currentState) > 0) {
index 99596d5..32cff12 100755 (executable)
@@ -151,7 +151,9 @@ namespace conv {
 
                                        payload.set(NULL, CONV_JSON_PAYLOAD_SIZE, message.m_payload_size);
                                        payload.set(NULL, CONV_JSON_RESULT_TYPE, CONV_JSON_ON_MESSAGE);
-                                       payload.set(NULL, CONV_JSON_MESSAGE, message_json);
+//                                     payload.set(NULL, CONV_JSON_MESSAGE, message_json);
+                                       payload.set(NULL, CONV_JSON_MESSAGE, message_json.dupCstr());
+                                       payload.set(NULL, CONV_JSON_FROM, message.m_from);
 
                                        description = (*requestObj)->getDescription();
 
@@ -231,7 +233,8 @@ namespace conv {
                                        client_json.set(NULL, CONV_JSON_CLIENT_ID, client->getId());
 
                                        payload.set(NULL, CONV_JSON_RESULT_TYPE, result_type);
-                                       payload.set(NULL, CONV_JSON_CLIENT, client_json);
+//                                     payload.set(NULL, CONV_JSON_CLIENT, client_json);
+                                       payload.set(NULL, CONV_JSON_CLIENT, client_json.dupCstr());
 
                                        description = (*requestObj)->getDescription();
 
index 3da29cc..0bb9413 100755 (executable)
@@ -169,6 +169,9 @@ int conv::AppCommServiceProvider::startRequest(Request* requestObj)
        channel.get(NULL, CONV_JSON_URI, &uri);
        channel.get(NULL, CONV_JSON_CHANNEL_ID, &channelId);
 
+       IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
+       IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
+
        ApplicationInstance *appInfo = NULL;
 
        for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
@@ -260,6 +263,9 @@ int conv::AppCommServiceProvider::stopRequest(Request* requestObj)
        channel.get(NULL, CONV_JSON_URI, &uri);
        channel.get(NULL, CONV_JSON_CHANNEL_ID, &channelId);
 
+       IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
+       IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
+
        for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
                _D("%s, %s", (*iter)->uri.c_str(), (*iter)->channelId.c_str());
                if ( (*iter) != NULL && !(*iter)->uri.compare(uri) && !(*iter)->channelId.compare(channelId) ) {
@@ -302,6 +308,9 @@ int conv::AppCommServiceProvider::readRequest(Request* requestObj)
        channel.get(NULL, CONV_JSON_URI, &uri);
        channel.get(NULL, CONV_JSON_CHANNEL_ID, &channelId);
 
+       IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
+       IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
+
        ApplicationInstance *appInfo = NULL;
        Json result;
 
@@ -346,7 +355,8 @@ int conv::AppCommServiceProvider::readRequest(Request* requestObj)
                                                if (cha != NULL)
                                                        client.set(NULL, CONV_JSON_CHANNEL_URI, cha->getChannelUri(NULL).c_str());
 
-                                               result.appendArray(NULL, CONV_JSON_CLIENT_LIST, client);
+//                                             result.appendArray(NULL, CONV_JSON_CLIENT_LIST, client);
+                                               result.appendArray(NULL, CONV_JSON_CLIENT_LIST, client.dupCstr());
                                        }
                                        sendReadResponse(result, CONV_JSON_GET_CLIENTS, CONV_ERROR_NONE, svcInfo->registeredRequest);
 
@@ -394,6 +404,9 @@ int conv::AppCommServiceProvider::publishRequest(Request* requestObj)
        channel.get(NULL, CONV_JSON_URI, &uri);
        channel.get(NULL, CONV_JSON_CHANNEL_ID, &channelId);
 
+       IF_FAIL_RETURN_TAG(!uri.empty() || svcInfo->isLocal, CONV_ERROR_INVALID_PARAMETER, _E, "uri is empty");
+       IF_FAIL_RETURN_TAG(!channelId.empty(), CONV_ERROR_INVALID_PARAMETER, _E, "channelId is empty");
+
        for (ApplicationInstanceList::iterator iter = svcInfo->applicationInstanceList.begin(); iter != svcInfo->applicationInstanceList.end(); ++iter) {
                _D("iteration");
                if ( (*iter) != NULL && !(*iter)->uri.compare(uri) && !(*iter)->channelId.compare(channelId) ) {
index 08c4afe..0586627 100755 (executable)
@@ -57,6 +57,13 @@ static void conv_subject_cb(const char* subject, int req_id, int error, json dat
        }
        device_callback_info_s* callback_info = itor->second;
        callback_info->cb(device, (conv_discovery_result_e)error, callback_info->user_data);
+
+       // unset callback..on finished
+       if (error == CONV_DISCOVERY_RESULT_FINISHED) {
+               _D("free memory for callback[id:%d]", req_id);
+               delete callback_map[req_id];
+               callback_map.erase(itor);
+       }
 }
 
 static void register_subject_callbacks()
@@ -134,17 +141,6 @@ EXTAPI int conv_discovery_stop(conv_h handle)
        int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_DISCOVERY_STOP, NULL, NULL, NULL);
        IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed in starting flow service");
 
-       // unset callback..
-       std::list<int>::iterator req_itr = handle->request_ids.begin();
-       for (; req_itr != handle->request_ids.end(); req_itr++) {
-               int cur_req_id = *req_itr;
-               if (callback_map[cur_req_id] !=  NULL) {
-                       _D("free memory for callback[id:%d]", cur_req_id);
-                       delete callback_map[cur_req_id];
-                       callback_map.erase(callback_map.find(cur_req_id));
-               }
-       }
-
        return CONV_ERROR_NONE;
 }