Name: espp-service
Summary: ESPP service package which contains client lib. and daemon binary
-Version: 0.1.11
+Version: 0.1.12
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0
return ESPP_CLIENT_ERROR_NONE;
}
+int espp_client_set_error_cb(espp_h espp, espp_error_cb callback, void *user_data)
+{
+ espp_s *_espp = (espp_s *)espp;
+ g_autoptr(GMutexLocker) locker = NULL;
+ g_autoptr(GMutexLocker) cb_locker = NULL;
+
+ RET_VAL_IF(!espp, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "espp is NULL");
+ RET_VAL_IF(!callback, ESPP_CLIENT_ERROR_INVALID_PARAMETER, "callback is NULL");
+
+ locker = g_mutex_locker_new(&_espp->mutex);
+
+ if (espp_service_client_socket_request_set_callback(_espp, ESPP_SERVICE_EVENT_CB_ERROR, (void *)callback, user_data) != 0)
+ return ESPP_CLIENT_ERROR_INVALID_OPERATION;
+
+ cb_locker = g_mutex_locker_new(&_espp->cb_mutex);
+ LOG_WARNING_IF_CALLBACK_EXISTS(_espp->error_cb);
+
+ _espp->error_cb.callback = callback;
+ _espp->error_cb.user_data = user_data;
+
+ LOG_INFO("espp[%p] callback[%p] user_data[%p]", espp, callback, user_data);
+
+ return ESPP_CLIENT_ERROR_NONE;
+}
+
int espp_client_create(espp_h *espp)
{
espp_s *_espp;
*/
typedef void (*espp_resource_conflicted_cb)(void *user_data);
+/**
+ * @brief Called when an error occurs.
+ * @param[in] error The error value
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see espp_client_set_error_cb()
+ */
+typedef void (*espp_error_cb)(espp_client_error_e error, void *user_data);
+
/**
* @brief Sets a callback function to be invoked when the ESPP service client handle is prepared to receive ESPP packets after calling espp_client_prepare_async().
* @param[in] espp ESPP service client handle
int espp_client_set_buffer_status_cb(espp_h espp, espp_buffer_status_cb callback, void *user_data);
/**
- * @brief Sets a callback function to be invoked when when a H/W resource of the ESPP service client handle has been conflicted.
+ * @brief Sets a callback function to be invoked when a H/W resource of the ESPP service client handle has been conflicted.
* @param[in] espp ESPP service client handle
* @param[in] callback Callback function pointer
* @param[in] user_data The user data to be passed to the callback function
*/
int espp_client_set_resource_conflicted_cb(espp_h espp, espp_resource_conflicted_cb callback, void *user_data);
+/**
+ * @brief Sets a callback function to be invoked when an error occurs.
+ * @param[in] espp ESPP service client handle
+ * @param[in] callback Callback function pointer
+ * @param[in] user_data The user data to be passed to the callback function
+ * @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
+ * @pre The state must be #ESPP_STATE_NONE or #ESPP_STATE_IDLE.
+ * @post espp_error_cb() will be invoked.
+ */
+int espp_client_set_error_cb(espp_h espp, espp_error_cb callback, void *user_data);
+
/**
* @brief Creates an instance of ESPP service client.
* @param[out] espp ESPP service client handle
result->ret = 0;
}
+static void __handle_event_cb_error(espp_s *espp, espp_service_data_from_server_s *data, espp_service_data_from_client_s *result)
+{
+ int ret;
+ espp_client_error_e error;
+
+ ASSERT(espp);
+ ASSERT(data);
+ ASSERT(result);
+
+ result->ret = -1;
+
+ ret = espp_service_client_msg_parse_params(data->params, data->event, &error);
+ if (ret != 0)
+ return;
+
+ LOG_INFO("cb params[error:%d]", error);
+
+ if (espp->error_cb.callback) {
+ LOG_DEBUG(">>> callback[%p] user_data[%p]", espp->error_cb.callback, espp->error_cb.user_data);
+ ((espp_error_cb)(espp->error_cb.callback))(error, espp->error_cb.user_data);
+ LOG_DEBUG("<<< end of the callback");
+ }
+
+ result->ret = 0;
+}
+
static func_handler handlers[] = {
[ESPP_SERVICE_EVENT_MSG] = __handle_event_msg,
[ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE] = __handle_event_cb_ready_to_prepare,
[ESPP_SERVICE_EVENT_CB_EOS] = __handle_event_cb_eos,
[ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = __handle_event_cb_buffer_status,
[ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED] = __handle_event_cb_resource_conflicted,
+ [ESPP_SERVICE_EVENT_CB_ERROR] = __handle_event_cb_error,
};
static void __func_handler(espp_s *espp, espp_service_data_from_server_s *data, espp_service_data_from_client_s *result)
espp_callback_s eos_cb;
espp_callback_s buffer_status_cb;
espp_callback_s resource_conflicted_cb;
+ espp_callback_s error_cb;
} espp_s;
/* socket */
[ESPP_SERVICE_EVENT_CB_EOS] = { "EosCB", NULL },
[ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = { "BufferStatusCB", "ii" },
[ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED] = { "PrepareAsyncDoneCB", NULL },
+ [ESPP_SERVICE_EVENT_CB_ERROR] = { "ErrorCB", "i" },
};
const char *data_type_strs[] = {
ESPP_SERVICE_EVENT_CB_EOS,
ESPP_SERVICE_EVENT_CB_BUFFER_STATUS,
ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED,
+ ESPP_SERVICE_EVENT_CB_ERROR,
} espp_service_event_e;
enum {
espp_service_send_data(tbs->event_fd, &data);
}
+static void __error_cb(const int error, void *user_data)
+{
+ handler_userdata_s *hdata = (handler_userdata_s *)user_data;
+ tb_data_s *tbs;
+ espp_service_data_from_server_s data;
+
+ ASSERT(hdata);
+ ASSERT(hdata->svc);
+ ASSERT(hdata->fd >= 0);
+
+ LOG_DEBUG("error[%d], fd[%d], ESPP[%p]", error, hdata->fd, hdata->espp);
+
+ RET_IF(!(tbs = g_hash_table_lookup(hdata->svc->fd_table, hdata->key)), "failed to g_hash_table_lookup(), key[%s]", hdata->key);
+
+ LOG_DEBUG("event_fd[%d], ESPP[%p]", tbs->event_fd, tbs->espp);
+
+ FILL_SOCKET_MSG_EVENT(data, ESPP_SERVICE_EVENT_CB_ERROR);
+ FILL_SOCKET_MSG_PARAMS(data, ESPP_SERVICE_EVENT_CB_ERROR, "error", error);
+
+ espp_service_send_data(tbs->event_fd, &data);
+}
+
static cb_intf_s cb_setters[] = {
[ESPP_SERVICE_EVENT_CB_READY_TO_PREPARE] = { (set_cb_func)esplusplayer_set_ready_to_prepare_cb, __ready_to_prepare_cb},
[ESPP_SERVICE_EVENT_CB_PREPARE_ASYNC_DONE] = { (set_cb_func)esplusplayer_set_prepare_async_done_cb, __prepare_async_done_cb},
[ESPP_SERVICE_EVENT_CB_EOS] = { (set_cb_func)esplusplayer_set_eos_cb, __eos_cb},
[ESPP_SERVICE_EVENT_CB_BUFFER_STATUS] = { (set_cb_func)esplusplayer_set_buffer_status_cb, __buffer_status_cb},
[ESPP_SERVICE_EVENT_CB_RESOURCE_CONFLICTED] = { (set_cb_func)esplusplayer_set_resource_conflicted_cb, __resource_conflicted_cb},
+ [ESPP_SERVICE_EVENT_CB_ERROR] = { (set_cb_func)esplusplayer_set_error_cb, __error_cb},
};
static void __handle_set_callback(handler_userdata_s *hdata, espp_service_data_from_client_s *data, espp_service_data_from_server_s *result)