diff --git a/src/client/context.c b/src/client/context.c index 2fb51bc50..00e0ed85a 100644 --- a/src/client/context.c +++ b/src/client/context.c @@ -295,6 +295,25 @@ pinos_context_init (PinosContext * context) context); } +/** + * pinos_context_state_as_string: + * @state: a #PinosContextState + * + * Return the string representation of @state. + * + * Returns: the string representation of @state. + */ +const gchar * +pinos_context_state_as_string (PinosContextState state) +{ + GEnumValue *val; + + val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_CONTEXT_STATE)), + state); + + return val == NULL ? "invalid-state" : val->value_nick; +} + /** * pinos_context_new: * @context: a #GMainContext to run in diff --git a/src/client/context.h b/src/client/context.h index bc9b874d3..b9b5aa8a5 100644 --- a/src/client/context.h +++ b/src/client/context.h @@ -74,6 +74,8 @@ typedef enum { PINOS_CONTEXT_STATE_READY = 3, } PinosContextState; +const gchar * pinos_context_state_as_string (PinosContextState state); + /** * PinosContext: * diff --git a/src/client/introspect.c b/src/client/introspect.c index 87defa35a..16b115ed4 100644 --- a/src/client/introspect.c +++ b/src/client/introspect.c @@ -229,6 +229,25 @@ pinos_context_get_client_info_by_id (PinosContext *context, cb (context, NULL, user_data); } +/** + * pinos_source_state_as_string: + * @state: a #PinosSourceState + * + * Return the string representation of @state. + * + * Returns: the string representation of @state. + */ +const gchar * +pinos_source_state_as_string (PinosSourceState state) +{ + GEnumValue *val; + + val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_SOURCE_STATE)), + state); + + return val == NULL ? "invalid-state" : val->value_nick; +} + static void source_fill_info (PinosSourceInfo *info, GDBusProxy *proxy) { @@ -325,6 +344,25 @@ pinos_context_get_source_info_by_id (PinosContext *context, cb (context, NULL, user_data); } +/** + * pinos_source_output_state_as_string: + * @state: a #PinosSourceOutputState + * + * Return the string representation of @state. + * + * Returns: the string representation of @state. + */ +const gchar * +pinos_source_output_state_as_string (PinosSourceOutputState state) +{ + GEnumValue *val; + + val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_SOURCE_OUTPUT_STATE)), + state); + + return val == NULL ? "invalid-state" : val->value_nick; +} + static void source_output_fill_info (PinosSourceOutputInfo *info, GDBusProxy *proxy) { diff --git a/src/client/introspect.h b/src/client/introspect.h index 97c60ac4c..c9c630f80 100644 --- a/src/client/introspect.h +++ b/src/client/introspect.h @@ -125,6 +125,8 @@ typedef enum { PINOS_SOURCE_STATE_RUNNING = 3, } PinosSourceState; +const gchar * pinos_source_state_as_string (PinosSourceState state); + /** * PinosSourceInfo: * @id: generic id of the source @@ -190,6 +192,8 @@ typedef enum { PINOS_SOURCE_OUTPUT_STATE_STREAMING = 2, } PinosSourceOutputState; +const gchar * pinos_source_output_state_as_string (PinosSourceOutputState state); + /** * PinosSourceOutputInfo: * @id: generic id of the output diff --git a/src/client/stream.c b/src/client/stream.c index f7e453a1b..434098518 100644 --- a/src/client/stream.c +++ b/src/client/stream.c @@ -402,6 +402,25 @@ pinos_stream_init (PinosStream * stream) priv->state = PINOS_STREAM_STATE_UNCONNECTED; } +/** + * pinos_stream_state_as_string: + * @state: a #PinosStreamState + * + * Return the string representation of @state. + * + * Returns: the string representation of @state. + */ +const gchar * +pinos_stream_state_as_string (PinosStreamState state) +{ + GEnumValue *val; + + val = g_enum_get_value (G_ENUM_CLASS (g_type_class_ref (PINOS_TYPE_STREAM_STATE)), + state); + + return val == NULL ? "invalid-state" : val->value_nick; +} + /** * pinos_stream_new: * @context: a #PinosContext diff --git a/src/client/stream.h b/src/client/stream.h index b5ee277ad..0a42a29ea 100644 --- a/src/client/stream.h +++ b/src/client/stream.h @@ -49,6 +49,7 @@ typedef enum { PINOS_STREAM_STATE_STREAMING = 4 } PinosStreamState; +const gchar * pinos_stream_state_as_string (PinosStreamState state); typedef enum { PINOS_STREAM_FLAGS_NONE = 0, diff --git a/src/tools/pinos-monitor.c b/src/tools/pinos-monitor.c index d409b841d..709823743 100644 --- a/src/tools/pinos-monitor.c +++ b/src/tools/pinos-monitor.c @@ -133,7 +133,7 @@ dump_source_info (PinosContext *c, const PinosSourceInfo *info, gpointer userdat if (info->change_mask & (1 << 1)) print_properties (info->properties); if (info->change_mask & (1 << 2)) - g_print ("\tstate: %d\n", info->state); + g_print ("\tstate: \"%s\"\n", pinos_source_state_as_string (info->state)); if (info->change_mask & (1 << 3)) print_formats ("possible formats", info->possible_formats); @@ -155,7 +155,7 @@ dump_source_output_info (PinosContext *c, const PinosSourceOutputInfo *info, gpo if (info->change_mask & (1 << 2)) print_formats ("possible-formats", info->possible_formats); if (info->change_mask & (1 << 3)) - g_print ("\tstate: \"%d\"\n", info->state); + g_print ("\tstate: \"%s\"\n", pinos_source_output_state_as_string (info->state)); if (info->change_mask & (1 << 4)) print_formats ("format", info->format); if (info->change_mask & (1 << 5)) @@ -243,7 +243,7 @@ on_state_notify (GObject *gobject, break; default: - g_print ("context state %d\n", state); + g_print ("context state: \"%s\"\n", pinos_context_state_as_string (state)); break; } }