Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wireplumber
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pkg
wireplumber
Commits
2f43e3a1
Commit
2f43e3a1
authored
4 years ago
by
Julian Bouzas
Committed by
George Kiagiadakis
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
lib: add new session-bin class to handle multiple session items
parent
2d186ed6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
lib/wp/meson.build
+2
-0
2 additions, 0 deletions
lib/wp/meson.build
lib/wp/session-bin.c
+182
-0
182 additions, 0 deletions
lib/wp/session-bin.c
lib/wp/session-bin.h
+50
-0
50 additions, 0 deletions
lib/wp/session-bin.h
lib/wp/wp.h
+1
-0
1 addition, 0 deletions
lib/wp/wp.h
with
235 additions
and
0 deletions
lib/wp/meson.build
+
2
−
0
View file @
2f43e3a1
...
...
@@ -21,6 +21,7 @@ wp_lib_sources = files(
'properties.c'
,
'proxy.c'
,
'session.c'
,
'session-bin.c'
,
'session-item.c'
,
'si-factory.c'
,
'si-interfaces.c'
,
...
...
@@ -54,6 +55,7 @@ wp_lib_headers = files(
'properties.h'
,
'proxy.h'
,
'session.h'
,
'session-bin.h'
,
'session-item.h'
,
'si-factory.h'
,
'si-interfaces.h'
,
...
...
This diff is collapsed.
Click to expand it.
lib/wp/session-bin.c
0 → 100644
+
182
−
0
View file @
2f43e3a1
/* WirePlumber
*
* Copyright © 2019 Collabora Ltd.
* @author Julian Bouzas <julian.bouzas@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
/**
* SECTION: WpSessionBin
* @title: Session Bin
*/
#define G_LOG_DOMAIN "wp-sb"
#include
"private.h"
#include
"session-bin.h"
typedef
struct
_WpSessionBinPrivate
WpSessionBinPrivate
;
struct
_WpSessionBinPrivate
{
GPtrArray
*
items
;
};
/**
* WpSessionBin:
*/
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE
(
WpSessionBin
,
wp_session_bin
,
WP_TYPE_SESSION_ITEM
)
static
void
si_session_bin_reset
(
WpSessionItem
*
item
)
{
WpSessionBin
*
self
=
WP_SESSION_BIN
(
item
);
WpSessionBinPrivate
*
priv
=
wp_session_bin_get_instance_private
(
self
);
g_ptr_array_set_size
(
priv
->
items
,
0
);
}
static
void
wp_session_bin_finalize
(
GObject
*
object
)
{
WpSessionBin
*
self
=
WP_SESSION_BIN
(
object
);
WpSessionBinPrivate
*
priv
=
wp_session_bin_get_instance_private
(
self
);
g_clear_pointer
(
&
priv
->
items
,
g_ptr_array_unref
);
G_OBJECT_CLASS
(
wp_session_bin_parent_class
)
->
finalize
(
object
);
}
static
void
wp_session_bin_init
(
WpSessionBin
*
self
)
{
WpSessionBinPrivate
*
priv
=
wp_session_bin_get_instance_private
(
self
);
priv
->
items
=
g_ptr_array_new_with_free_func
((
GDestroyNotify
)
g_object_unref
);
}
static
void
wp_session_bin_class_init
(
WpSessionBinClass
*
klass
)
{
GObjectClass
*
object_class
=
(
GObjectClass
*
)
klass
;
WpSessionItemClass
*
si_class
=
(
WpSessionItemClass
*
)
klass
;
object_class
->
finalize
=
wp_session_bin_finalize
;
si_class
->
reset
=
si_session_bin_reset
;
}
/**
* wp_session_bin_new:
* Creates a new session bin.
*
* Returns: TRUE if the item was added into the session bin, FALSE otherwise
*/
WpSessionBin
*
wp_session_bin_new
(
void
)
{
return
g_object_new
(
WP_TYPE_SESSION_BIN
,
NULL
);
}
/**
* wp_session_bin_add:
* @self: the session bin
* @item (transfer full): the session item to be added
*
* Adds a session item into a session bin.
*
* Returns: TRUE if the item was added into the session bin, FALSE otherwise
*/
gboolean
wp_session_bin_add
(
WpSessionBin
*
self
,
WpSessionItem
*
item
)
{
WpSessionBinPrivate
*
priv
=
wp_session_bin_get_instance_private
(
self
);
guint
index
;
if
(
g_ptr_array_find
(
priv
->
items
,
item
,
&
index
))
return
FALSE
;
g_ptr_array_add
(
priv
->
items
,
item
);
return
TRUE
;
}
/**
* wp_session_bin_remove:
* @self: the session bin
* @item (transfer none): the session item to be removed
*
* Removes a session item from a session bin.
*
* Returns: TRUE if the item was removed from the session bin, FALSE otherwise
*/
gboolean
wp_session_bin_remove
(
WpSessionBin
*
self
,
WpSessionItem
*
item
)
{
WpSessionBinPrivate
*
priv
=
wp_session_bin_get_instance_private
(
self
);
return
g_ptr_array_remove_fast
(
priv
->
items
,
item
);
}
struct
_WpSessionBinIterator
{
WpSessionBin
*
bin
;
guint
index
;
};
typedef
struct
_WpSessionBinIterator
WpSessionBinIterator
;
static
void
wp_session_bin_iterator_reset
(
WpIterator
*
iterator
)
{
WpSessionBinIterator
*
self
=
wp_iterator_get_user_data
(
iterator
);
self
->
index
=
0
;
}
static
gboolean
wp_session_bin_iterator_next
(
WpIterator
*
iterator
,
GValue
*
item
)
{
WpSessionBinIterator
*
self
=
wp_iterator_get_user_data
(
iterator
);
WpSessionBinPrivate
*
bin_priv
=
wp_session_bin_get_instance_private
(
self
->
bin
);
if
(
self
->
index
>=
bin_priv
->
items
->
len
)
return
FALSE
;
if
(
item
)
{
g_value_init
(
item
,
G_TYPE_OBJECT
);
g_value_set_object
(
item
,
g_ptr_array_index
(
bin_priv
->
items
,
self
->
index
++
));
}
return
TRUE
;
}
static
void
wp_session_bin_iterator_finalize
(
WpIterator
*
iterator
)
{
WpSessionBinIterator
*
self
=
wp_iterator_get_user_data
(
iterator
);
self
->
bin
=
NULL
;
}
/**
* wp_session_bin_iterate:
* @self: the session bin
* @item (transfer none): the session item to be removed
*
* Gets an iterator to iterate throught all session items.
*
* Returns (transfer full): The session bin iterator.
*/
WpIterator
*
wp_session_bin_iterate
(
WpSessionBin
*
self
)
{
static
const
WpIteratorMethods
methods
=
{
.
reset
=
wp_session_bin_iterator_reset
,
.
next
=
wp_session_bin_iterator_next
,
.
fold
=
NULL
,
.
foreach
=
NULL
,
.
finalize
=
wp_session_bin_iterator_finalize
};
WpIterator
*
ret
=
wp_iterator_new
(
&
methods
,
sizeof
(
WpSessionBinIterator
));
WpSessionBinIterator
*
it
=
wp_iterator_get_user_data
(
ret
);
it
->
bin
=
self
;
return
ret
;
}
This diff is collapsed.
Click to expand it.
lib/wp/session-bin.h
0 → 100644
+
50
−
0
View file @
2f43e3a1
/* WirePlumber
*
* Copyright © 2020 Collabora Ltd.
* @author Julian Bouzas <julian.bouzas@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_SESSION_BIN_H__
#define __WIREPLUMBER_SESSION_BIN_H__
#include
"core.h"
#include
"session-item.h"
#include
"iterator.h"
G_BEGIN_DECLS
/**
* WP_TYPE_SESSION_BIN:
*
* The #WpSessionBin #GType
*/
#define WP_TYPE_SESSION_BIN (wp_session_bin_get_type ())
WP_API
G_DECLARE_DERIVABLE_TYPE
(
WpSessionBin
,
wp_session_bin
,
WP
,
SESSION_BIN
,
WpSessionItem
)
/**
* WpSessionBinClass:
*/
struct
_WpSessionBinClass
{
WpSessionItemClass
parent_class
;
};
WP_API
WpSessionBin
*
wp_session_bin_new
(
void
);
WP_API
gboolean
wp_session_bin_add
(
WpSessionBin
*
self
,
WpSessionItem
*
item
);
WP_API
gboolean
wp_session_bin_remove
(
WpSessionBin
*
self
,
WpSessionItem
*
item
);
WP_API
WpIterator
*
wp_session_bin_iterate
(
WpSessionBin
*
self
);
G_END_DECLS
#endif
This diff is collapsed.
Click to expand it.
lib/wp/wp.h
+
1
−
0
View file @
2f43e3a1
...
...
@@ -28,6 +28,7 @@
#include
"properties.h"
#include
"proxy.h"
#include
"session.h"
#include
"session-bin.h"
#include
"session-item.h"
#include
"si-factory.h"
#include
"si-interfaces.h"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment