session-item: add export API with closure

This commit is contained in:
Julian Bouzas 2021-01-20 10:26:46 -05:00
parent 73c6e65a74
commit 7c0739af50
2 changed files with 36 additions and 8 deletions

View file

@ -813,11 +813,10 @@ on_export_transition_post_completed (gpointer data, GClosure *closure)
}
/**
* wp_session_item_export:
* wp_session_item_export_closure:
* @self: the session item
* @session: the session on which to export this item
* @callback: (scope async): a callback to call when exporting is finished
* @callback_data: (closure): data passed to @callback
* @closure: (transfer full): the closure to use when export is completed
*
* Exports this item asynchronously on PipeWire, making it part of the
* specified @session. You can use wp_session_item_export_finish() in the
@ -847,8 +846,8 @@ on_export_transition_post_completed (gpointer data, GClosure *closure)
* already exported.
*/
void
wp_session_item_export (WpSessionItem * self, WpSession * session,
GAsyncReadyCallback callback, gpointer callback_data)
wp_session_item_export_closure (WpSessionItem * self, WpSession * session,
GClosure *closure)
{
g_return_if_fail (WP_IS_SESSION_ITEM (self));
g_return_if_fail (WP_IS_SESSION (session));
@ -861,9 +860,6 @@ wp_session_item_export (WpSessionItem * self, WpSession * session,
g_weak_ref_set (&priv->session, session);
GClosure *closure =
g_cclosure_new (G_CALLBACK (callback), callback_data, NULL);
/* TODO: add a way to cancel the transition if unexport() is called in the meantime */
WpTransition *transition = wp_transition_new_closure (
wp_si_transition_get_type (), self, NULL, closure);
@ -889,6 +885,34 @@ wp_session_item_export (WpSessionItem * self, WpSession * session,
wp_transition_advance (transition);
}
/**
* wp_session_item_export:
* @self: the session item
* @session: the session on which to export this item
* @callback: (scope async): a callback to call when exporting is finished
* @callback_data: (closure): data passed to @callback
*
* @callback and @callback_data version of wp_session_item_export_closure()
*/
void
wp_session_item_export (WpSessionItem * self, WpSession * session,
GAsyncReadyCallback callback, gpointer callback_data)
{
g_return_if_fail (WP_IS_SESSION_ITEM (self));
g_return_if_fail (WP_IS_SESSION (session));
WpSessionItemPrivate *priv =
wp_session_item_get_instance_private (self);
g_return_if_fail (!(priv->flags &
(WP_SI_FLAGS_MASK_OPERATION_IN_PROGRESS | WP_SI_FLAG_EXPORTED)));
GClosure *closure =
g_cclosure_new (G_CALLBACK (callback), callback_data, NULL);
wp_session_item_export_closure (self, session, closure);
}
/**
* wp_session_item_export_finish:
* @self: the session item

View file

@ -173,6 +173,10 @@ void wp_session_item_deactivate (WpSessionItem * self);
/* exporting */
WP_API
void wp_session_item_export_closure (WpSessionItem * self, WpSession * session,
GClosure *closure);
WP_API
void wp_session_item_export (WpSessionItem * self, WpSession * session,
GAsyncReadyCallback callback, gpointer callback_data);