improve introspection

Small cleanups
This commit is contained in:
Wim Taymans 2016-08-18 12:17:31 +02:00
parent ab0537305f
commit bdbddaf75b
15 changed files with 117 additions and 688 deletions

View file

@ -434,57 +434,44 @@ pinos_direction_as_string (PinosDirection direction)
}
static void
port_fill_info (PinosPortInfo *info, GDBusProxy *proxy)
link_fill_info (PinosLinkInfo *info, GDBusProxy *proxy)
{
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy;
info->port_path = g_dbus_proxy_get_object_path (proxy);
SET_UINT32 ("Direction", direction, 0, PINOS_DIRECTION_INVALID);
SET_STRING ("Node", node_path, 0);
info->link_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0;
SET_STRING ("Name", name, 0);
SET_OBJV ("Peers", peers, 1);
SET_PROPERTIES ("Properties", properties, 2);
SET_BYTES ("PossibleFormats", possible_formats, 3);
SET_BYTES ("Format", format, 4);
SET_STRING ("SrcPort", source_port_path, 0);
SET_STRING ("DestPort", destination_port_path, 1);
if (changed)
g_hash_table_remove_all (changed);
}
static void
port_clear_info (PinosPortInfo *info)
link_clear_info (PinosLinkInfo *info)
{
if (info->peers)
g_strfreev (info->peers);
if (info->properties)
pinos_properties_free (info->properties);
if (info->possible_formats)
g_bytes_unref (info->possible_formats);
if (info->format)
g_bytes_unref (info->format);
}
/**
* pinos_context_list_port_info:
* pinos_context_list_link_info:
* @context: a connected #PinosContext
* @flags: extra #PinosPortInfoFlags
* @cb: a #PinosPortInfoCallback
* @flags: extra #PinosLinkInfoFlags
* @cb: a #PinosLinkInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for each port.
* Call @cb for each link.
*/
void
pinos_context_list_port_info (PinosContext *context,
PinosPortInfoFlags flags,
PinosPortInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
pinos_context_list_link_info (PinosContext *context,
PinosLinkInfoFlags flags,
PinosLinkInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosContextPrivate *priv;
GList *walk;
@ -497,13 +484,13 @@ pinos_context_list_port_info (PinosContext *context,
priv = context->priv;
for (walk = priv->ports; walk; walk = g_list_next (walk)) {
for (walk = priv->links; walk; walk = g_list_next (walk)) {
GDBusProxy *proxy = walk->data;
PinosPortInfo info;
PinosLinkInfo info;
port_fill_info (&info, proxy);
link_fill_info (&info, proxy);
cb (context, &info, user_data);
port_clear_info (&info);
link_clear_info (&info);
}
g_task_return_boolean (task, TRUE);
@ -511,27 +498,27 @@ pinos_context_list_port_info (PinosContext *context,
}
/**
* pinos_context_get_port_info_by_id:
* pinos_context_get_link_info_by_id:
* @context: a connected #PinosContext
* @id: a port id
* @flags: extra #PinosPortInfoFlags
* @cb: a #PinosPortInfoCallback
* @id: a link id
* @flags: extra #PinosLinkInfoFlags
* @cb: a #PinosLinkInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for the port with @id.
* Call @cb for the link with @id.
*/
void
pinos_context_get_port_info_by_id (PinosContext *context,
pinos_context_get_link_info_by_id (PinosContext *context,
gpointer id,
PinosPortInfoFlags flags,
PinosPortInfoCallback cb,
PinosLinkInfoFlags flags,
PinosLinkInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosPortInfo info;
PinosLinkInfo info;
GDBusProxy *proxy;
GTask *task;
@ -543,270 +530,9 @@ pinos_context_get_port_info_by_id (PinosContext *context,
proxy = G_DBUS_PROXY (id);
port_fill_info (&info, proxy);
link_fill_info (&info, proxy);
cb (context, &info, user_data);
port_clear_info (&info);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
/**
* pinos_port_state_as_string:
* @state: a #PinosPortState
*
* Return the string representation of @state.
*
* Returns: the string representation of @state.
*/
const gchar *
pinos_port_state_as_string (PinosPortState state)
{
GEnumValue *val;
val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_PORT_STATE)),
state);
return val == NULL ? "invalid-state" : val->value_nick;
}
/**
* pinos_channel_state_as_string:
* @state: a #PinosChannelState
*
* Return the string representation of @state.
*
* Returns: the string representation of @state.
*/
const gchar *
pinos_channel_state_as_string (PinosChannelState state)
{
GEnumValue *val;
val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_CHANNEL_STATE)),
state);
return val == NULL ? "invalid-state" : val->value_nick;
}
static void
channel_fill_info (PinosChannelInfo *info, GDBusProxy *proxy)
{
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy;
info->channel_path = g_dbus_proxy_get_object_path (proxy);
SET_UINT32 ("Direction", direction, 2, PINOS_DIRECTION_INVALID);
SET_STRING ("Client", client_path, 0);
info->change_mask = 0;
SET_STRING ("Port", port_path, 0);
SET_PROPERTIES ("Properties", properties, 1);
SET_UINT32 ("State", state, 2, PINOS_CHANNEL_STATE_ERROR);
SET_BYTES ("PossibleFormats", possible_formats, 3);
SET_BYTES ("Format", format, 4);
if (changed)
g_hash_table_remove_all (changed);
}
static void
channel_clear_info (PinosChannelInfo *info)
{
if (info->possible_formats)
g_bytes_unref (info->possible_formats);
if (info->format)
g_bytes_unref (info->format);
if (info->properties)
pinos_properties_free (info->properties);
}
/**
* pinos_context_list_channel_info:
* @context: a connected #PinosContext
* @flags: extra #PinosChannelInfoFlags
* @cb: a #PinosChannelInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for each channel.
*/
void
pinos_context_list_channel_info (PinosContext *context,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosContextPrivate *priv;
GList *walk;
GTask *task;
g_return_if_fail (PINOS_IS_CONTEXT (context));
g_return_if_fail (cb != NULL);
task = g_task_new (context, cancellable, callback, user_data);
priv = context->priv;
for (walk = priv->channels; walk; walk = g_list_next (walk)) {
GDBusProxy *proxy = walk->data;
PinosChannelInfo info;
channel_fill_info (&info, proxy);
cb (context, &info, user_data);
channel_clear_info (&info);
}
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
/**
* pinos_context_get_channel_info_by_id:
* @context: a connected #PinosContext
* @id: a channel id
* @flags: extra #PinosChannelInfoFlags
* @cb: a #PinosChannelInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for the channel with @id.
*/
void
pinos_context_get_channel_info_by_id (PinosContext *context,
gpointer id,
PinosChannelInfoFlags flags,
PinosChannelInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosChannelInfo info;
GDBusProxy *proxy;
GTask *task;
g_return_if_fail (PINOS_IS_CONTEXT (context));
g_return_if_fail (id != NULL);
g_return_if_fail (cb != NULL);
task = g_task_new (context, cancellable, callback, user_data);
proxy = G_DBUS_PROXY (id);
channel_fill_info (&info, proxy);
cb (context, &info, user_data);
channel_clear_info (&info);
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
static void
connection_fill_info (PinosConnectionInfo *info, GDBusProxy *proxy)
{
GHashTable *changed = g_object_get_data (G_OBJECT (proxy), "pinos-changed-properties");
info->id = proxy;
info->connection_path = g_dbus_proxy_get_object_path (proxy);
info->change_mask = 0;
SET_STRING ("SourcePort", source_port_path, 0);
SET_STRING ("DestinationPort", destination_port_path, 1);
if (changed)
g_hash_table_remove_all (changed);
}
static void
connection_clear_info (PinosConnectionInfo *info)
{
}
/**
* pinos_context_list_connection_info:
* @context: a connected #PinosContext
* @flags: extra #PinosConnectionInfoFlags
* @cb: a #PinosConnectionInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for each connection.
*/
void
pinos_context_list_connection_info (PinosContext *context,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosContextPrivate *priv;
GList *walk;
GTask *task;
g_return_if_fail (PINOS_IS_CONTEXT (context));
g_return_if_fail (cb != NULL);
task = g_task_new (context, cancellable, callback, user_data);
priv = context->priv;
for (walk = priv->connections; walk; walk = g_list_next (walk)) {
GDBusProxy *proxy = walk->data;
PinosConnectionInfo info;
connection_fill_info (&info, proxy);
cb (context, &info, user_data);
connection_clear_info (&info);
}
g_task_return_boolean (task, TRUE);
g_object_unref (task);
}
/**
* pinos_context_get_connection_info_by_id:
* @context: a connected #PinosContext
* @id: a connection id
* @flags: extra #PinosConnectionInfoFlags
* @cb: a #PinosConnectionInfoCallback
* @cancelable: a #GCancellable
* @callback: a #GAsyncReadyCallback to call when the operation is finished
* @user_data: user data passed to @cb
*
* Call @cb for the connection with @id.
*/
void
pinos_context_get_connection_info_by_id (PinosContext *context,
gpointer id,
PinosConnectionInfoFlags flags,
PinosConnectionInfoCallback cb,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
PinosConnectionInfo info;
GDBusProxy *proxy;
GTask *task;
g_return_if_fail (PINOS_IS_CONTEXT (context));
g_return_if_fail (id != NULL);
g_return_if_fail (cb != NULL);
task = g_task_new (context, cancellable, callback, user_data);
proxy = G_DBUS_PROXY (id);
connection_fill_info (&info, proxy);
cb (context, &info, user_data);
connection_clear_info (&info);
link_clear_info (&info);
g_task_return_boolean (task, TRUE);
g_object_unref (task);