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
6fbf2527
Commit
6fbf2527
authored
5 years ago
by
Julian Bouzas
Browse files
Options
Downloads
Patches
Plain Diff
factory: add async support
parent
661010a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/wp/factory.c
+56
-6
56 additions, 6 deletions
lib/wp/factory.c
lib/wp/factory.h
+10
-0
10 additions, 0 deletions
lib/wp/factory.h
with
66 additions
and
6 deletions
lib/wp/factory.c
+
56
−
6
View file @
6fbf2527
...
...
@@ -15,7 +15,10 @@ struct _WpFactory
GWeakRef
core
;
gchar
*
name
;
GQuark
name_quark
;
WpFactoryFunc
create_object
;
union
{
WpFactoryFunc
sync
;
WpFactoryAsyncFunc
async
;
}
create_object
;
};
G_DEFINE_TYPE
(
WpFactory
,
wp_factory
,
G_TYPE_OBJECT
)
...
...
@@ -45,19 +48,29 @@ wp_factory_class_init (WpFactoryClass * klass)
object_class
->
finalize
=
wp_factory_finalize
;
}
WpFactory
*
wp
_factory
_new
(
WpCore
*
core
,
const
gchar
*
name
,
WpFactoryFunc
func
)
static
WpFactory
*
create
_factory
(
WpCore
*
core
,
const
gchar
*
name
)
{
WpFactory
*
f
=
NULL
;
g_return_val_if_fail
(
name
!=
NULL
&&
*
name
!=
'\0'
,
NULL
);
g_return_val_if_fail
(
func
!=
NULL
,
NULL
);
f
=
g_object_new
(
WP_TYPE_FACTORY
,
NULL
);
g_weak_ref_init
(
&
f
->
core
,
core
);
f
->
name
=
g_strdup
(
name
);
f
->
name_quark
=
g_quark_from_string
(
f
->
name
);
f
->
create_object
=
func
;
return
f
;
}
WpFactory
*
wp_factory_new
(
WpCore
*
core
,
const
gchar
*
name
,
WpFactoryFunc
func
)
{
WpFactory
*
f
=
NULL
;
g_return_val_if_fail
(
func
,
NULL
);
f
=
create_factory
(
core
,
name
);
f
->
create_object
.
sync
=
func
;
g_info
(
"WpFactory:%p new factory: %s"
,
f
,
name
);
...
...
@@ -66,6 +79,23 @@ wp_factory_new (WpCore * core, const gchar * name, WpFactoryFunc func)
return
f
;
}
WpFactory
*
wp_factory_new_async
(
WpCore
*
core
,
const
gchar
*
name
,
WpFactoryAsyncFunc
func
)
{
WpFactory
*
f
=
NULL
;
g_return_val_if_fail
(
func
,
NULL
);
f
=
create_factory
(
core
,
name
);
f
->
create_object
.
async
=
func
;
g_info
(
"WpFactory:%p new async factory: %s"
,
f
,
name
);
wp_core_register_global
(
core
,
WP_GLOBAL_FACTORY
,
f
,
g_object_unref
);
return
f
;
}
const
gchar
*
wp_factory_get_name
(
WpFactory
*
self
)
{
...
...
@@ -89,7 +119,18 @@ wp_factory_create_object (WpFactory * self, GType type, GVariant * properties)
{
g_debug
(
"WpFactory:%p (%s) create object of type %s"
,
self
,
self
->
name
,
g_type_name
(
type
));
return
self
->
create_object
(
self
,
type
,
properties
);
return
self
->
create_object
.
sync
(
self
,
type
,
properties
);
}
void
wp_factory_create_object_async
(
WpFactory
*
self
,
GType
type
,
GVariant
*
properties
,
GAsyncReadyCallback
ready
,
gpointer
user_data
)
{
g_debug
(
"WpFactory:%p (%s) create object async of type %s"
,
self
,
self
->
name
,
g_type_name
(
type
));
self
->
create_object
.
async
(
self
,
type
,
properties
,
ready
,
user_data
);
}
struct
find_factory_data
...
...
@@ -127,3 +168,12 @@ wp_factory_make (WpCore * core, const gchar * name, GType type,
if
(
!
f
)
return
NULL
;
return
wp_factory_create_object
(
f
,
type
,
properties
);
}
void
wp_factory_make_async
(
WpCore
*
core
,
const
gchar
*
name
,
GType
type
,
GVariant
*
properties
,
GAsyncReadyCallback
ready
,
gpointer
user_data
)
{
WpFactory
*
f
=
wp_factory_find
(
core
,
name
);
if
(
!
f
)
return
;
wp_factory_create_object_async
(
f
,
type
,
properties
,
ready
,
user_data
);
}
This diff is collapsed.
Click to expand it.
lib/wp/factory.h
+
10
−
0
View file @
6fbf2527
...
...
@@ -9,6 +9,8 @@
#ifndef __WIREPLUMBER_FACTORY_H__
#define __WIREPLUMBER_FACTORY_H__
#include
<gio/gio.h>
#include
"core.h"
G_BEGIN_DECLS
...
...
@@ -18,18 +20,26 @@ G_DECLARE_FINAL_TYPE (WpFactory, wp_factory, WP, FACTORY, GObject)
typedef
gpointer
(
*
WpFactoryFunc
)
(
WpFactory
*
self
,
GType
type
,
GVariant
*
properties
);
typedef
void
(
*
WpFactoryAsyncFunc
)
(
WpFactory
*
self
,
GType
type
,
GVariant
*
properties
,
GAsyncReadyCallback
ready
,
gpointer
user_data
);
WpFactory
*
wp_factory_new
(
WpCore
*
core
,
const
gchar
*
name
,
WpFactoryFunc
func
);
WpFactory
*
wp_factory_new_async
(
WpCore
*
core
,
const
gchar
*
name
,
WpFactoryAsyncFunc
func
);
const
gchar
*
wp_factory_get_name
(
WpFactory
*
self
);
WpCore
*
wp_factory_get_core
(
WpFactory
*
self
);
gpointer
wp_factory_create_object
(
WpFactory
*
self
,
GType
type
,
GVariant
*
properties
);
void
wp_factory_create_object_async
(
WpFactory
*
self
,
GType
type
,
GVariant
*
properties
,
GAsyncReadyCallback
ready
,
gpointer
user_data
);
WpFactory
*
wp_factory_find
(
WpCore
*
core
,
const
gchar
*
name
);
gpointer
wp_factory_make
(
WpCore
*
core
,
const
gchar
*
name
,
GType
type
,
GVariant
*
properties
);
void
wp_factory_make_async
(
WpCore
*
core
,
const
gchar
*
name
,
GType
type
,
GVariant
*
properties
,
GAsyncReadyCallback
ready
,
gpointer
user_data
);
G_END_DECLS
...
...
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