Applied internal APIs to check service state 45/108445/2
authorkmook <kmook.choi@samsung.com>
Wed, 4 Jan 2017 10:00:02 +0000 (19:00 +0900)
committerKyoung-Mook Choi <kmook.choi@samsung.com>
Wed, 4 Jan 2017 10:01:02 +0000 (02:01 -0800)
Change-Id: I187c6b1a8f6ab4b8b907283b953e165141192f5a
Signed-off-by: kmook <kmook.choi@samsung.com>
common/Types.h
daemon/IServiceProvider.h
daemon/RequestHandler.cpp
daemon/ServiceManager.cpp
daemon/service_provider/AppCommServiceProvider.cpp
daemon/service_provider/AppCommServiceProvider.h
daemon/service_provider/RemoteAppControlServiceProvider.cpp
daemon/service_provider/RemoteAppControlServiceProvider.h
lib/conv_lib_service.cpp
lib/dbus_client.cpp
lib/include/d2d_conv_internal.h

index 637a500..09a9526 100644 (file)
@@ -66,6 +66,7 @@
 #define CONV_SUBJECT_COMMUNICATION_STOP        "conv/communication/stop"
 #define CONV_SUBJECT_COMMUNICATION_GET "conv/communication/get"
 #define CONV_SUBJECT_COMMUNICATION_SET "conv/communication/set"
+#define CONV_SUBJECT_COMMUNICATION_CHECK_STATE "conv/communication/check_state"
 
 #define CONV_SUBJECT_COMMUNICATION_WRITE       "conv/communication/write"
 #define CONV_SUBJECT_COMMUNICATION_READ        "conv/communication/read"
index 239d20b..905253c 100644 (file)
@@ -33,6 +33,7 @@ namespace conv {
                        virtual int readRequest(Request* requestObj) = 0;
                        virtual int publishRequest(Request* requestObj) = 0;
                        virtual int registerRequest(Request* requestObj) = 0;
+                       virtual int checkStateRequest(Request* requestObj) = 0;
                        virtual int loadServiceInfo(Request* requestObj) = 0;
                        virtual int getServiceInfoForDiscovery(Json* jsonObj) = 0;
                        int checkActivationState() {
index bf5338c..3e9f1db 100755 (executable)
@@ -68,7 +68,8 @@ int conv::RequestHandler::handleRequest(Request* requestObj)
                if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_DISCOVERY_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_DISCOVERY_STOP))
                        return discovery_manager::handleRequest (requestObj);
                else if ( !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_STOP)
-                               || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_GET) )
+                               || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_SET) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_GET)
+                               || !strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_CHECK_STATE))
                        result = service_manager::handleRequest(requestObj);
                else if ( !strcmp(requestObj->getSubject(), CONV_SUBJECT_CONNECTION_START) || !strcmp(requestObj->getSubject(), CONV_SUBJECT_CONNECTION_STOP) )
                        result = connection_manager::handleRequest(requestObj);
index 0a8c14d..a3698d7 100755 (executable)
@@ -187,6 +187,8 @@ int conv::ServiceManager::handleRequest(Request* requestObj)
                                error = (*it)->publishRequest(requestObj);
                        } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_RECV)) {
                                return (*it)->registerRequest(requestObj);
+                       } else if (!strcmp(requestObj->getSubject(), CONV_SUBJECT_COMMUNICATION_CHECK_STATE)) {
+                               error = (*it)->checkStateRequest(requestObj);
                        }
                        IF_FAIL_CATCH_TAG(error == CONV_ERROR_NONE, _E, "service manager request handle error");
                }
index 48ab640..68d4d86 100755 (executable)
@@ -172,8 +172,8 @@ int conv::AppCommServiceProvider::startRequest(Request* requestObj)
        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) ) {
-                       if ( (*iter)->state == APP_COMM_STATE_STARTED || (*iter)->state == APP_COMM_STATE_STARTING ) {
-                               _D("already started or now starting");
+                       if ( (*iter)->state == APP_COMM_STATE_STARTED ) {
+                               _D("already started");
                                return CONV_ERROR_INVALID_OPERATION;
                        } else {
                                _D("appInfo exists but no application instance");
@@ -462,6 +462,7 @@ int conv::AppCommServiceProvider::registerRequest(Request* requestObj)
                _D("subscribe requested");
                break;
        case REQ_UNSUBSCRIBE:
+               delete svcInfo->registeredRequest;
                svcInfo->registeredRequest = NULL;
                requestObj->reply(CONV_ERROR_NONE);
                delete requestObj;
@@ -475,6 +476,39 @@ int conv::AppCommServiceProvider::registerRequest(Request* requestObj)
        return CONV_ERROR_NONE;
 }
 
+int conv::AppCommServiceProvider::checkStateRequest(Request* requestObj)
+{
+       _D("communcation/check_state requested");
+       AppCommServiceInfo *svcInfo = reinterpret_cast<AppCommServiceInfo*>(requestObj->getServiceInfo());
+
+       Json channel;
+       requestObj->getChannelFromDescription(&channel);
+
+       string uri, channelId;
+
+       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) ) {
+                       if ( (*iter)->state == APP_COMM_STATE_STARTED ) {
+                               _D("service is started");
+                               return CONV_ERROR_NONE;
+                       } else {
+                               _D("service is not started");
+                               return CONV_ERROR_INVALID_OPERATION;
+                       }
+               }
+       }
+
+       _D("no service found");
+       return CONV_ERROR_NONE;
+}
+
 int conv::AppCommServiceProvider::getServiceInfoForDiscovery(Json* jsonObj)
 {
        jsonObj->set(NULL, CONV_JSON_DISCOVERY_SERVICE_TYPE, CONV_SERVICE_APP_TO_APP_COMMUNICATION);
index e10f3da..ecdf5c2 100755 (executable)
@@ -38,6 +38,7 @@ namespace conv {
                        int readRequest(Request* requestObj);
                        int publishRequest(Request* requestObj);
                        int registerRequest(Request* requestObj);
+                       int checkStateRequest(Request* requestObj);
                        int loadServiceInfo(Request* requestObj);
                        int getServiceInfoForDiscovery(Json* jsonObj);
                        int handleVconfUpdate(keynode_t *node);
index 497e3f7..77bf683 100755 (executable)
@@ -890,6 +890,21 @@ int conv::RemoteAppControlServiceProvider::stopRequest(Request* requestObj)
        return CONV_ERROR_NONE;
 }
 
+int conv::RemoteAppControlServiceProvider::checkStateRequest(Request* requestObj)
+{
+       _D("communcation/check_state requested");
+
+       RemoteAppControlServiceInfo *svcInfo = reinterpret_cast<RemoteAppControlServiceInfo*>(requestObj->getServiceInfo());
+
+       if (svcInfo->iotconInfoObj.iotconResourceHandle == NULL) {
+               _D("not started");
+               return CONV_ERROR_INVALID_OPERATION;
+       } else {
+               _D("started");
+               return CONV_ERROR_NONE;
+       }
+}
+
 int conv::RemoteAppControlServiceProvider::readRequest(Request* requestObj)
 {
        return CONV_ERROR_NONE;
index 455838b..354f1ca 100644 (file)
@@ -45,6 +45,7 @@ namespace conv {
                        int readRequest(Request* requestObj);
                        int publishRequest(Request* requestObj);
                        int registerRequest(Request* requestObj);
+                       int checkStateRequest(Request* requestObj);
                        int loadServiceInfo(Request* requestObj);
                        int getServiceInfoForDiscovery(Json* jsonObj);
                        int handleVconfUpdate(keynode_t *node);
index 6a3d55f..346ba56 100755 (executable)
@@ -488,6 +488,7 @@ static int conv_service_unset_connected_cb(conv_service_h handle)
 
        json description;
        json service = handle->jservice;
+       json device = handle->jdevice;
 
        std::string service_type = convert_type_to_string(handle->service_type);
        if (service_type.empty())
@@ -495,6 +496,7 @@ static int conv_service_unset_connected_cb(conv_service_h handle)
 
        description.set(NULL, CONV_JSON_SERVICE, service);
        description.set(NULL, CONV_JSON_TYPE, service_type);
+       description.set(NULL, CONV_JSON_DEVICE, device);
        description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
 
        int req_id;
@@ -674,5 +676,44 @@ conv_service_e convert_string_to_type(std::string type_name)
        }
        return service_type;
 }
+
+EXTAPI int conv_service_is_started(conv_service_h handle, conv_channel_h channel_handle, bool* started)
+{
+       ASSERT_NOT_NULL(handle);
+       ASSERT_NOT_NULL(started);
+
+       IF_FAIL_RETURN_TAG(conv::util::is_feature_supported(), CONV_ERROR_NOT_SUPPORTED, _E, "Not supported");
+
+       *started = false;
+
+       int req_id;
+
+       json description;
+       json channel;
+       json payload;
+
+       if (channel_handle != NULL)
+               channel = channel_handle->jchannel;
+
+       json service = handle->jservice;
+       json device = handle->jdevice;
+       std::string type = convert_type_to_string(handle->service_type);
+       if (type.empty())
+               return CONV_ERROR_INVALID_PARAMETER;
+
+       description.set(NULL, CONV_JSON_SERVICE, service);
+       description.set(NULL, CONV_JSON_CHANNEL, channel);
+       description.set(NULL, CONV_JSON_DEVICE, device);
+       description.set(NULL, CONV_JSON_TYPE, type);
+       description.set(NULL, CONV_JSON_IS_LOCAL, handle->is_local);
+
+       int err = conv::dbus_client::request(REQ_WRITE, &req_id, CONV_SUBJECT_COMMUNICATION_CHECK_STATE, description.str().c_str(), 0, NULL);
+       IF_FAIL_RETURN_TAG(err == CONV_ERROR_NONE, err, _E, "Failed to get started status");
+
+       *started = true;
+
+       return CONV_ERROR_NONE;
+}
+
 //LCOV_EXCL_STOP
 
index 02556d5..a413967 100755 (executable)
@@ -65,7 +65,7 @@ static void handle_response(const gchar *sender, GVariant *param, GDBusMethodInv
        g_variant_get(param, "(i&si&si@a(y))", &req_id, &subject, &error, &data, &length, &binary_array);
        _D("[Response] ReqId: %d, Subject: %s, Error: %d", req_id, subject, error);
        const unsigned char *binary = (const unsigned char*)g_variant_get_data(binary_array);
-       _D("%s", binary);
+
        response_cb_map_t::iterator it = response_cb_map->find(subject);
        IF_FAIL_VOID_TAG(it!= response_cb_map->end(), _E, "Unknown subject'%s'", subject);
        it->second(subject, req_id,  error, data, length, binary);
index 7758179..4538560 100755 (executable)
@@ -270,6 +270,23 @@ int conv_payload_set_binary(conv_payload_h handle, int length, const unsigned ch
  */
 int conv_payload_get_binary(conv_payload_h handle, int* length, const unsigned char** value);
 
+/**
+ * @brief              Gets service start status.
+ * @since_tizen 3.0
+ *
+ * @param[in]  handle                          The service handle
+ * @param[in]  channel_handle          The channel handle
+ * @param[out] started                         The boolean value of service started check
+ *
+ * @return             0 on success, otherwise a negative error value
+ * @retval             #CONV_ERROR_NONE                                        Successful
+ * @retval             #CONV_ERROR_INVALID_PARAMETER   Invalid parameter
+ * @retval             #CONV_ERROR_NOT_SUPPORTED               Not supported
+ * @retval             #CONV_ERROR_NO_DATA                             No Data
+ *
+ */
+int conv_service_is_started(conv_service_h handle, conv_channel_h channel_handle, bool* started);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */