Add function to stop handle
authorSangchul Lee <sc11.lee@samsung.com>
Sat, 22 Apr 2023 11:15:45 +0000 (20:15 +0900)
committer이상철/Tizen Platform Lab(SR)/삼성전자 <sc11.lee@samsung.com>
Wed, 26 Apr 2023 05:43:33 +0000 (14:43 +0900)
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
src/client/espp_service_client.c
src/client/espp_service_client.h
src/client/espp_service_client_priv.h
src/client/espp_service_client_socket.c
src/common/espp_service_common.c
src/common/espp_service_common.h
src/daemon/espp_service_handler.c

index 17f53c36c502c99199c09d794c149336ff01b2cb..582236efc235a5d32e195a1d8c9cbd33f0436c7b 100644 (file)
@@ -79,6 +79,23 @@ int espp_client_start(espp_h espp)
        return ESPP_CLIENT_ERROR_NONE;
 }
 
+int espp_client_stop(espp_h espp)
+{
+       espp_s *_espp = (espp_s *)espp;
+       g_autoptr(GMutexLocker) locker = NULL;
+
+       RET_VAL_IF(!espp, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "espp is NULL");
+
+       locker = g_mutex_locker_new(&_espp->mutex);
+
+       if (espp_service_client_socket_request_stop(_espp) != 0)
+               return ESPP_CLIENT_ERROR_INVALID_OPERATION;
+
+       LOG_INFO("espp[%p] is stopped", espp);
+
+       return ESPP_CLIENT_ERROR_NONE;
+}
+
 int espp_client_set_audio_stream_info(espp_h espp, espp_audio_stream_info_s *info)
 {
        espp_s *_espp = (espp_s *)espp;
index e38c7377c2251f7c09110529e09ea4fd0ad26dc9..b4d9ecc0b00c12dc9e7937a3a77911ea3ff1c9fe 100644 (file)
@@ -142,12 +142,27 @@ int espp_client_destroy(espp_h espp);
  * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
  * @see espp_client_create()
+ * @see espp_client_stop()
  */
 int espp_client_start(espp_h espp);
 
+/**
+ * @brief Stops the espp.
+ * @remarks espp_client_close() must be called after this handle is stopped.
+ * @param[in] espp    ESPP service client handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #ESPP_CLIENT_ERROR_NONE Successful
+ * @retval #ESPP_CLIENT_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #ESPP_CLIENT_ERROR_INVALID_OPERATION Invalid operation
+ * @see espp_client_start()
+ * @see espp_client_close()
+ */
+int espp_client_stop(espp_h espp);
+
 /**
  * @brief Sets the audio stream information.
- * @remarks This API has to be called before calling the espp_client_prepare_async().
+ * @remarks This function must be called before calling the espp_client_prepare_async().
  * @param[in] espp    ESPP service client handle
  * @param[in] info    Audio stream information structure pointer
  * @return @c 0 on success,
@@ -162,7 +177,7 @@ int espp_client_set_audio_stream_info(espp_h espp, espp_audio_stream_info_s *inf
 
 /**
  * @brief Sets the video stream information.
- * @remarks This API has to be called before calling the espp_client_prepare_async().
+ * @remarks This function must be called before calling the espp_client_prepare_async().
  * @param[in] espp    ESPP service client handle
  * @param[in] info    Video stream information structure pointer
  * @return @c 0 on success,
index 44b14db6a4ce259430d8446e70735565abcb4a85..1660be67c29e050d70d2ef84998b801f9868e35a 100644 (file)
@@ -40,6 +40,7 @@ gchar *espp_service_client_msg_params_new(const char *formats, ...);
 int espp_service_client_socket_request_create(espp_s *espp);
 int espp_service_client_socket_request_destroy(espp_s *espp);
 int espp_service_client_socket_request_start(espp_s *espp);
+int espp_service_client_socket_request_stop(espp_s *espp);
 int espp_service_client_socket_request_set_audio_stream_info(espp_s *espp, espp_audio_stream_info_s *info);
 int espp_service_client_socket_request_set_video_stream_info(espp_s *espp, espp_video_stream_info_s *info);
 
index 0ef033931f1a0554729f2123b4b8faa1314cb840..10daefbca2cf44acc4dfb7fc9641057ffdc06678 100644 (file)
@@ -207,6 +207,25 @@ int espp_service_client_socket_request_start(espp_s *espp)
        return 0;
 }
 
+int espp_service_client_socket_request_stop(espp_s *espp)
+{
+       espp_service_data_from_client_s data;
+       espp_service_data_from_server_s result;
+
+       ASSERT(espp);
+       RET_VAL_IF(espp->fd == -1, -1, "fd is -1");
+
+       FILL_SOCKET_MSG_REQUEST(data, ESPP_SERVICE_REQUEST_STOP);
+       if (send_data(espp->fd, &data, &result) != 0)
+               return -1;
+
+       RET_VAL_IF_SERVER_RESULT_ERROR(result, -1);
+
+       LOG_DEBUG("espp[%p], fd[%d]", espp, espp->fd);
+
+       return 0;
+}
+
 int espp_service_client_socket_request_set_audio_stream_info(espp_s *espp, espp_audio_stream_info_s *info)
 {
        espp_service_data_from_client_s data;
index 830293dad2f6ab735edcad00c50d8fb83fa97cb8..07bda02f45eb2dbfb0f328e8ff840b02dcbaf5c1 100644 (file)
@@ -20,6 +20,7 @@ espp_service_request_s requests[] = { /* str, param_formats - 'b':bool, 'i':int,
        [ESPP_SERVICE_REQUEST_CREATE] = { "Create", NULL },
        [ESPP_SERVICE_REQUEST_DESTROY] = {"Destroy", NULL },
        [ESPP_SERVICE_REQUEST_START] = { "Start", NULL },
+       [ESPP_SERVICE_REQUEST_STOP] = { "Stop", NULL },
        [ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO] = { "SetAudioStreamInfo", "suiuuu" },
        [ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO] = { "SetVideoStreamInfo", "suiuuuuuu" },
 };
index 0167b0dbec5ae206109daa3be0be95c5a0d8a57a..db0f71538b2abe05a2d72af6f4164dcf29ebd6b6 100644 (file)
@@ -125,6 +125,7 @@ typedef enum {
        ESPP_SERVICE_REQUEST_CREATE,
        ESPP_SERVICE_REQUEST_DESTROY,
        ESPP_SERVICE_REQUEST_START,
+       ESPP_SERVICE_REQUEST_STOP,
        ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO,
        ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO,
 } espp_service_request_e;
index 8aee1239729d2d3c19434b8c842b276502ddc7d5..14434874a59d213c6fae7f21584a06ad1879c260 100644 (file)
@@ -88,6 +88,28 @@ static void __handle_start(espp_service_s *svc, int fd, espp_service_data_from_c
        result->ret = 0;
 }
 
+static void __handle_stop(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
+{
+       int ret;
+       esplusplayer_handle espp;
+
+       ASSERT(svc);
+       ASSERT(fd >= 0);
+       ASSERT(data);
+       ASSERT(result);
+
+       result->ret = -1;
+
+       RET_IF(!(espp = g_hash_table_lookup(svc->espp_handles, GINT_TO_POINTER(fd))), "failed to g_hash_table_lookup(), fd[%d]", fd);
+
+       ret = esplusplayer_stop(espp);
+       RET_IF(ret != ESPLUSPLAYER_ERROR_TYPE_NONE, "failed to esplusplayer_stop(), ESPP[%p]", espp);
+
+       LOG_INFO("fd[%d], ESPP[%p]: esplusplayer_stop() success", fd, espp);
+
+       result->ret = 0;
+}
+
 static void __handle_set_audio_stream_info(espp_service_s *svc, int fd, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)
 {
        int ret;
@@ -151,6 +173,7 @@ static func_handler handlers[] = {
        [ESPP_SERVICE_REQUEST_CREATE] = __handle_create,
        [ESPP_SERVICE_REQUEST_DESTROY] = __handle_destroy,
        [ESPP_SERVICE_REQUEST_START] = __handle_start,
+       [ESPP_SERVICE_REQUEST_STOP] = __handle_stop,
        [ESPP_SERVICE_REQUEST_SET_AUDIO_STREAM_INFO] = __handle_set_audio_stream_info,
        [ESPP_SERVICE_REQUEST_SET_VIDEO_STREAM_INFO] = __handle_set_video_stream_info,
 };