session-item: add _register and _remove API

Allows using object managers to listen for registered items
This commit is contained in:
Julian Bouzas
2021-03-18 13:17:27 -04:00
parent 120aab04ae
commit 3aef916d51
3 changed files with 60 additions and 0 deletions

View File

@@ -345,6 +345,40 @@ wp_session_item_get_associated_proxy_id (WpSessionItem * self, GType proxy_type)
return wp_proxy_get_bound_id (proxy);
}
/**
* wp_session_item_register:
* @self: (transfer full): the session item
*
* Registers the session item to its associated core
*/
void
wp_session_item_register (WpSessionItem * self)
{
g_autoptr (WpCore) core = NULL;
g_return_if_fail (WP_IS_SESSION_ITEM (self));
core = wp_object_get_core (WP_OBJECT (self));
wp_registry_register_object (wp_core_get_registry (core), self);
}
/**
* wp_session_item_remove:
* @self: (transfer none): the session item
*
* Removes the session item from the registry
*/
void
wp_session_item_remove (WpSessionItem * self)
{
g_autoptr (WpCore) core = NULL;
g_return_if_fail (WP_IS_SESSION_ITEM (self));
core = wp_object_get_core (WP_OBJECT (self));
wp_registry_remove_object (wp_core_get_registry (core), self);
}
/**
* wp_session_item_get_properties:
* @self: the session item

View File

@@ -90,6 +90,14 @@ WP_API
guint32 wp_session_item_get_associated_proxy_id (WpSessionItem * self,
GType proxy_type);
/* registry */
WP_API
void wp_session_item_register (WpSessionItem * self);
WP_API
void wp_session_item_remove (WpSessionItem * self);
/* properties */
WP_API

View File

@@ -1088,9 +1088,27 @@ session_item_configure (lua_State *L)
return 1;
}
static int
session_item_register (lua_State *L)
{
WpSessionItem *si = wplua_checkobject (L, 1, WP_TYPE_SESSION_ITEM);
wp_session_item_register (g_object_ref (si));
return 0;
}
static int
session_item_remove (lua_State *L)
{
WpSessionItem *si = wplua_checkobject (L, 1, WP_TYPE_SESSION_ITEM);
wp_session_item_remove (si);
return 0;
}
static const luaL_Reg session_item_methods[] = {
{ "reset", session_item_reset },
{ "configure", session_item_configure },
{ "register", session_item_register },
{ "remove", session_item_remove },
{ NULL, NULL }
};