Skip to content
Snippets Groups Projects
Commit ec30336f authored by Julian Bouzas's avatar Julian Bouzas
Browse files

session-item: add id property

Makes it easier when handling session items in Lua
parent c0143b5f
No related branches found
No related tags found
No related merge requests found
......@@ -26,12 +26,14 @@ enum {
typedef struct _WpSessionItemPrivate WpSessionItemPrivate;
struct _WpSessionItemPrivate
{
guint id;
GWeakRef parent;
WpProperties *properties;
};
enum {
PROP_0,
PROP_ID,
PROP_PROPERTIES,
};
......@@ -41,11 +43,20 @@ enum {
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (WpSessionItem, wp_session_item,
WP_TYPE_OBJECT)
static guint
get_next_id ()
{
static guint next_id = 0;
g_atomic_int_inc (&next_id);
return next_id;
}
static void
wp_session_item_init (WpSessionItem * self)
{
WpSessionItemPrivate *priv = wp_session_item_get_instance_private (self);
priv->id = get_next_id ();
g_weak_ref_init (&priv->parent, NULL);
priv->properties = NULL;
}
......@@ -86,8 +97,12 @@ wp_session_item_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
WpSessionItem *self = WP_SESSION_ITEM (object);
WpSessionItemPrivate *priv = wp_session_item_get_instance_private (self);
switch (property_id) {
case PROP_ID:
g_value_set_uint (value, priv->id);
break;
case PROP_PROPERTIES:
g_value_set_boxed (value, wp_session_item_get_properties (self));
break;
......@@ -204,6 +219,11 @@ wp_session_item_class_init (WpSessionItemClass * klass)
klass->reset = wp_session_item_default_reset;
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_uint ("id", "id",
"The session item unique id", 0, G_MAXUINT, 0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_PROPERTIES,
g_param_spec_boxed ("properties", "properties",
"The session item properties", WP_TYPE_PROPERTIES,
......@@ -248,6 +268,23 @@ wp_session_item_set_parent (WpSessionItem *self, WpSessionItem *parent)
g_weak_ref_set (&priv->parent, parent);
}
/**
* wp_session_item_get_id:
* @self: the session item
*
* Gets the unique Id of the session item
*/
guint
wp_session_item_get_id (WpSessionItem * self)
{
WpSessionItemPrivate *priv = NULL;
g_return_val_if_fail (WP_IS_SESSION_ITEM (self), SPA_ID_INVALID);
priv = wp_session_item_get_instance_private (self);
return priv->id;
}
/**
* wp_session_item_reset: (virtual reset)
* @self: the session item
......
......@@ -69,6 +69,11 @@ WpSessionItem * wp_session_item_get_parent (WpSessionItem * self);
WP_PRIVATE_API
void wp_session_item_set_parent (WpSessionItem *self, WpSessionItem *parent);
/* Id */
WP_API
guint wp_session_item_get_id (WpSessionItem * self);
/* configuration */
WP_API
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment