mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-05-05 07:48:01 +02:00
metadata: fix more coding style issues
This commit is contained in:
parent
3ae506d223
commit
3e65325519
2 changed files with 97 additions and 85 deletions
|
|
@ -9,7 +9,7 @@
|
|||
/**
|
||||
* SECTION: WpMetadata
|
||||
*
|
||||
* The #WpMetadata class allows accessing the properties and methods of
|
||||
* The #WpMetadata class allows accessing the properties and methods of
|
||||
* Pipewire Jack metadata object (`struct pw_metadata`).
|
||||
*
|
||||
*/
|
||||
|
|
@ -95,12 +95,12 @@ struct _WpImplMetadata
|
|||
|
||||
G_DEFINE_TYPE (WpImplMetadata, wp_impl_metadata, WP_TYPE_METADATA)
|
||||
|
||||
#define pw_metadata_emit(hooks,method,version,...) \
|
||||
spa_hook_list_call_simple(hooks, struct pw_metadata_events, \
|
||||
method, version, ##__VA_ARGS__)
|
||||
#define pw_metadata_emit(hooks,method,version,...) \
|
||||
spa_hook_list_call_simple(hooks, struct pw_metadata_events, \
|
||||
method, version, ##__VA_ARGS__)
|
||||
|
||||
#define pw_metadata_emit_property(hooks,...) \
|
||||
pw_metadata_emit(hooks,property, 0, ##__VA_ARGS__)
|
||||
#define pw_metadata_emit_property(hooks,...) \
|
||||
pw_metadata_emit(hooks,property, 0, ##__VA_ARGS__)
|
||||
|
||||
struct item {
|
||||
uint32_t subject;
|
||||
|
|
@ -109,17 +109,17 @@ struct item {
|
|||
char *value;
|
||||
};
|
||||
|
||||
static void
|
||||
clear_item(struct item *item)
|
||||
static void
|
||||
clear_item (struct item *item)
|
||||
{
|
||||
free(item->key);
|
||||
free(item->type);
|
||||
free(item->value);
|
||||
spa_zero(*item);
|
||||
free (item->key);
|
||||
free (item->type);
|
||||
free (item->value);
|
||||
spa_zero (*item);
|
||||
}
|
||||
|
||||
static void
|
||||
set_item(struct item *item, uint32_t subject, const char *key,
|
||||
static void
|
||||
set_item(struct item *item, uint32_t subject, const char *key,
|
||||
const char *type, const char *value)
|
||||
{
|
||||
item->subject = subject;
|
||||
|
|
@ -128,21 +128,22 @@ set_item(struct item *item, uint32_t subject, const char *key,
|
|||
item->value = strdup(value);
|
||||
}
|
||||
|
||||
static void
|
||||
emit_properties(WpImplMetadata *self,
|
||||
static void
|
||||
emit_properties(WpImplMetadata *self,
|
||||
const struct spa_dict *dict)
|
||||
{
|
||||
struct item *item;
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
pw_array_for_each(item, &priv->metadata) {
|
||||
wp_info_object (self, "metadata : %d %s %s %s",
|
||||
item->subject, item->key, item->type, item->value);
|
||||
pw_metadata_emit_property(&priv->hooks,
|
||||
item->subject,
|
||||
item->key,
|
||||
item->type,
|
||||
item->value);
|
||||
item->subject, item->key, item->type, item->value);
|
||||
pw_metadata_emit_property (&priv->hooks,
|
||||
item->subject,
|
||||
item->key,
|
||||
item->type,
|
||||
item->value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -153,68 +154,73 @@ impl_add_listener(void *object,
|
|||
void *data)
|
||||
{
|
||||
WpImplMetadata *self = WP_IMPL_METADATA (object);
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
struct spa_hook_list save;
|
||||
|
||||
spa_hook_list_isolate (&priv->hooks, &save, listener, events, data);
|
||||
|
||||
emit_properties(self, &priv->properties->dict);
|
||||
|
||||
spa_hook_list_join (&priv->hooks, &save);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct item *
|
||||
find_item(WpImplMetadata *self, uint32_t subject, const char *key)
|
||||
find_item (WpImplMetadata *self, uint32_t subject, const char *key)
|
||||
{
|
||||
struct item *item;
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
pw_array_for_each(item, &priv->metadata) {
|
||||
if (item->subject == subject && (key == NULL ||
|
||||
!strcmp(item->key, key))) {
|
||||
return item;
|
||||
if (item->subject == subject && (key == NULL || !strcmp (item->key, key))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
clear_subjects(WpImplMetadata *self, uint32_t subject)
|
||||
static int
|
||||
clear_subjects (WpImplMetadata *self, uint32_t subject)
|
||||
{
|
||||
struct item *item;
|
||||
uint32_t removed = 0;
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
while (true) {
|
||||
item = find_item(self, subject, NULL);
|
||||
if (item == NULL)
|
||||
break;
|
||||
break;
|
||||
|
||||
wp_debug_object (self, "remove id:%d key:%s", subject, item->key);
|
||||
|
||||
clear_item(item);
|
||||
pw_array_remove(&priv->metadata, item);
|
||||
clear_item (item);
|
||||
pw_array_remove (&priv->metadata, item);
|
||||
removed++;
|
||||
}
|
||||
|
||||
if (removed > 0)
|
||||
pw_metadata_emit_property(&priv->hooks, subject, NULL, NULL, NULL);
|
||||
pw_metadata_emit_property (&priv->hooks, subject, NULL, NULL, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
clear_items(WpImplMetadata *self)
|
||||
static void
|
||||
clear_items (WpImplMetadata *self)
|
||||
{
|
||||
struct item *item;
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
pw_array_consume(item, &priv->metadata)
|
||||
clear_subjects(self, item->subject);
|
||||
pw_array_reset(&priv->metadata);
|
||||
pw_array_consume (item, &priv->metadata) {
|
||||
clear_subjects (self, item->subject);
|
||||
}
|
||||
pw_array_reset (&priv->metadata);
|
||||
}
|
||||
|
||||
static int
|
||||
impl_set_property(void *object, uint32_t subject, const char *key,
|
||||
static int
|
||||
impl_set_property (void *object, uint32_t subject, const char *key,
|
||||
const char *type, const char *value)
|
||||
{
|
||||
WpImplMetadata *self = WP_IMPL_METADATA (object);
|
||||
|
|
@ -225,45 +231,45 @@ impl_set_property(void *object, uint32_t subject, const char *key,
|
|||
priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
if (key == NULL)
|
||||
return clear_subjects(self, subject);
|
||||
return clear_subjects (self, subject);
|
||||
|
||||
item = find_item(self, subject, key);
|
||||
item = find_item (self, subject, key);
|
||||
if (item == NULL) {
|
||||
if (value == NULL)
|
||||
return 0;
|
||||
item = pw_array_add(&priv->metadata, sizeof(*item));
|
||||
item = pw_array_add (&priv->metadata, sizeof (*item));
|
||||
if (item == NULL)
|
||||
return -errno;
|
||||
} else {
|
||||
clear_item(item);
|
||||
clear_item (item);
|
||||
}
|
||||
|
||||
if (value != NULL) {
|
||||
if (type == NULL)
|
||||
type = "string";
|
||||
set_item(item, subject, key, type, value);
|
||||
wp_debug_object (self, "%p: add id:%d key:%s type:%s value:%s", self,
|
||||
subject, key, type, value);
|
||||
set_item (item, subject, key, type, value);
|
||||
wp_debug_object (self, "add id:%d key:%s type:%s value:%s",
|
||||
subject, key, type, value);
|
||||
} else {
|
||||
type = NULL;
|
||||
pw_array_remove(&priv->metadata, item);
|
||||
wp_debug_object(self, "%p: remove id:%d key:%s", self, subject, key);
|
||||
pw_array_remove (&priv->metadata, item);
|
||||
wp_debug_object (self, "remove id:%d key:%s", subject, key);
|
||||
}
|
||||
|
||||
pw_metadata_emit_property(&priv->hooks, subject, key, type, value);
|
||||
pw_metadata_emit_property (&priv->hooks, subject, key, type, value);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
impl_clear(void *object)
|
||||
static int
|
||||
impl_clear (void *object)
|
||||
{
|
||||
WpImplMetadata *self = WP_IMPL_METADATA (object);
|
||||
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
clear_items(self);
|
||||
pw_array_clear(&priv->metadata);
|
||||
pw_properties_free(priv->properties);
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
clear_items (self);
|
||||
pw_array_clear (&priv->metadata);
|
||||
pw_properties_free (priv->properties);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -277,18 +283,19 @@ static const struct pw_metadata_methods impl_metadata = {
|
|||
static void
|
||||
wp_impl_metadata_init (WpImplMetadata * self)
|
||||
{
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
self->iface = SPA_INTERFACE_INIT (
|
||||
PW_TYPE_INTERFACE_Metadata,
|
||||
PW_VERSION_METADATA,
|
||||
&impl_metadata, self);
|
||||
PW_TYPE_INTERFACE_Metadata,
|
||||
PW_VERSION_METADATA,
|
||||
&impl_metadata, self);
|
||||
spa_hook_list_init (&priv->hooks);
|
||||
|
||||
priv->iface = (struct pw_metadata *) &self->iface;
|
||||
|
||||
priv->properties = pw_properties_new(NULL, NULL);
|
||||
pw_array_init(&priv->metadata, 4096);
|
||||
priv->properties = pw_properties_new (NULL, NULL);
|
||||
pw_array_init (&priv->metadata, 4096);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -301,7 +308,8 @@ static void
|
|||
wp_impl_metadata_augment (WpProxy * proxy, WpProxyFeatures features)
|
||||
{
|
||||
WpImplMetadata *self = WP_IMPL_METADATA (proxy);
|
||||
WpMetadataPrivate *priv = wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
WpMetadataPrivate *priv =
|
||||
wp_metadata_get_instance_private (WP_METADATA (self));
|
||||
|
||||
/* PW_PROXY depends on BOUND */
|
||||
if (features & WP_PROXY_FEATURE_PW_PROXY)
|
||||
|
|
@ -311,20 +319,19 @@ wp_impl_metadata_augment (WpProxy * proxy, WpProxyFeatures features)
|
|||
g_autoptr (WpCore) core = wp_proxy_get_core (proxy);
|
||||
struct pw_core *pw_core = wp_core_get_pw_core (core);
|
||||
|
||||
/* no pw_core -> we are not connected */
|
||||
if (!pw_core) {
|
||||
wp_proxy_augment_error (proxy, g_error_new (WP_DOMAIN_LIBRARY,
|
||||
WP_LIBRARY_ERROR_OPERATION_FAILED,
|
||||
"The WirePlumber core is not connected; "
|
||||
"object cannot be exported to PipeWire"));
|
||||
wp_critical(G_LOG_DOMAIN "metadata : FAIL - Exiting %s",__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
/* no pw_core -> we are not connected */
|
||||
if (!pw_core) {
|
||||
wp_proxy_augment_error (proxy, g_error_new (WP_DOMAIN_LIBRARY,
|
||||
WP_LIBRARY_ERROR_OPERATION_FAILED,
|
||||
"The WirePlumber core is not connected; "
|
||||
"object cannot be exported to PipeWire"));
|
||||
return;
|
||||
}
|
||||
|
||||
wp_proxy_set_pw_proxy (proxy, pw_core_export (pw_core,
|
||||
PW_TYPE_INTERFACE_Metadata,
|
||||
&priv->properties->dict,
|
||||
priv->iface, 0));
|
||||
wp_proxy_set_pw_proxy (proxy, pw_core_export (pw_core,
|
||||
PW_TYPE_INTERFACE_Metadata,
|
||||
&priv->properties->dict,
|
||||
priv->iface, 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -348,6 +355,6 @@ wp_impl_metadata_new (WpCore * core)
|
|||
g_return_val_if_fail (WP_IS_CORE (core), NULL);
|
||||
|
||||
return g_object_new (WP_TYPE_IMPL_METADATA,
|
||||
"core", core,
|
||||
NULL);
|
||||
"core", core,
|
||||
NULL);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,12 +15,14 @@ G_BEGIN_DECLS
|
|||
|
||||
#define WP_METADATA_FEATURES_STANDARD \
|
||||
(WP_PROXY_FEATURES_STANDARD)
|
||||
|
||||
/**
|
||||
* WP_TYPE_METADATA:
|
||||
*
|
||||
* The #WpMetadata #GType
|
||||
*/
|
||||
#define WP_TYPE_METADATA (wp_metadata_get_type ())
|
||||
|
||||
WP_API
|
||||
G_DECLARE_DERIVABLE_TYPE (WpMetadata, wp_metadata, WP, METADATA, WpProxy)
|
||||
|
||||
|
|
@ -36,10 +38,13 @@ struct _WpMetadataClass
|
|||
* The #WpImplMetadata #GType
|
||||
*/
|
||||
#define WP_TYPE_IMPL_METADATA (wp_impl_metadata_get_type ())
|
||||
|
||||
WP_API
|
||||
G_DECLARE_FINAL_TYPE (WpImplMetadata, wp_impl_metadata, WP, IMPL_METADATA, WpMetadata)
|
||||
|
||||
WP_API
|
||||
WpImplMetadata * wp_impl_metadata_new (WpCore * core);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue