2015-06-30 18:06:36 +02:00
|
|
|
/* Pinos
|
2015-04-16 16:58:33 +02:00
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
2015-06-30 18:06:36 +02:00
|
|
|
#include <client/pinos.h>
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
static GMainLoop *loop;
|
|
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
static gboolean
|
|
|
|
|
print_field (GQuark field, const GValue * value, gpointer user_data)
|
|
|
|
|
{
|
2016-04-07 11:51:05 +02:00
|
|
|
gchar *mark = user_data;
|
2015-07-28 17:05:03 +02:00
|
|
|
gchar *str = gst_value_serialize (value);
|
|
|
|
|
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\t%15s: %s\n", *mark, g_quark_to_string (field), str);
|
2015-07-28 17:05:03 +02:00
|
|
|
g_free (str);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-01-07 15:27:35 +01:00
|
|
|
print_formats (const gchar *name, GBytes *formats, gchar mark)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
GstCaps *caps;
|
2015-07-28 17:05:03 +02:00
|
|
|
guint i;
|
|
|
|
|
|
2016-02-01 16:29:56 +01:00
|
|
|
if (formats == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
caps = gst_caps_from_string (g_bytes_get_data (formats, NULL));
|
2016-01-07 15:27:35 +01:00
|
|
|
g_print ("%c\t%s:\n", mark, name);
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
if (gst_caps_is_any (caps)) {
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\tANY\n", mark);
|
2015-07-28 17:05:03 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (gst_caps_is_empty (caps)) {
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\tEMPTY\n", mark);
|
2015-07-28 17:05:03 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
|
|
|
|
GstStructure *structure = gst_caps_get_structure (caps, i);
|
|
|
|
|
GstCapsFeatures *features = gst_caps_get_features (caps, i);
|
|
|
|
|
|
|
|
|
|
if (features && (gst_caps_features_is_any (features) ||
|
|
|
|
|
!gst_caps_features_is_equal (features,
|
|
|
|
|
GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY))) {
|
|
|
|
|
gchar *features_string = gst_caps_features_to_string (features);
|
|
|
|
|
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\t%s(%s)\n", mark, gst_structure_get_name (structure),
|
2015-07-28 17:05:03 +02:00
|
|
|
features_string);
|
|
|
|
|
g_free (features_string);
|
|
|
|
|
} else {
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\t%s\n", mark, gst_structure_get_name (structure));
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
2016-04-07 11:51:05 +02:00
|
|
|
gst_structure_foreach (structure, print_field, &mark);
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 09:05:14 +02:00
|
|
|
static void
|
2016-01-07 15:27:35 +01:00
|
|
|
print_properties (PinosProperties *props, gchar mark)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
|
|
|
|
gpointer state = NULL;
|
|
|
|
|
const gchar *key;
|
|
|
|
|
|
2016-02-01 16:29:56 +01:00
|
|
|
if (props == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2016-01-07 15:27:35 +01:00
|
|
|
g_print ("%c\tproperties:\n", mark);
|
2015-07-28 17:05:03 +02:00
|
|
|
while ((key = pinos_properties_iterate (props, &state))) {
|
2016-04-07 11:51:05 +02:00
|
|
|
g_print ("%c\t\t%s = \"%s\"\n", mark, key, pinos_properties_get (props, key));
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
|
|
|
|
info_ready (GObject *o, GAsyncResult *res, gpointer user_data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2016-01-07 12:15:57 +01:00
|
|
|
GError *error = NULL;
|
2015-07-28 17:05:03 +02:00
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
if (!pinos_context_info_finish (o, res, &error)) {
|
|
|
|
|
g_printerr ("introspection failure: %s\n", error->message);
|
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 16:29:56 +01:00
|
|
|
typedef struct {
|
|
|
|
|
gboolean print_mark;
|
|
|
|
|
gboolean print_all;
|
|
|
|
|
} DumpData;
|
|
|
|
|
|
|
|
|
|
#define MARK_CHANGE(f) ((data->print_mark && ((info)->change_mask & (1 << (f)))) ? '*' : ' ')
|
2016-01-07 15:27:35 +01:00
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2016-01-07 15:27:35 +01:00
|
|
|
dump_daemon_info (PinosContext *c, const PinosDaemonInfo *info, gpointer user_data)
|
2016-01-07 12:15:57 +01:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData *data = user_data;
|
2016-01-07 15:27:35 +01:00
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
g_print ("\tid: %p\n", info->id);
|
2015-08-12 11:34:29 +02:00
|
|
|
g_print ("\tdaemon-path: \"%s\"\n", info->daemon_path);
|
2016-02-01 16:29:56 +01:00
|
|
|
if (data->print_all) {
|
|
|
|
|
g_print ("%c\tuser-name: \"%s\"\n", MARK_CHANGE (0), info->user_name);
|
|
|
|
|
g_print ("%c\thost-name: \"%s\"\n", MARK_CHANGE (1), info->host_name);
|
|
|
|
|
g_print ("%c\tversion: \"%s\"\n", MARK_CHANGE (2), info->version);
|
|
|
|
|
g_print ("%c\tname: \"%s\"\n", MARK_CHANGE (3), info->name);
|
2016-05-06 17:54:23 +02:00
|
|
|
g_print ("%c\tcookie: %u\n", MARK_CHANGE (4), info->cookie);
|
2016-02-01 16:29:56 +01:00
|
|
|
print_properties (info->properties, MARK_CHANGE (5));
|
|
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2016-01-07 15:27:35 +01:00
|
|
|
dump_client_info (PinosContext *c, const PinosClientInfo *info, gpointer user_data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData *data = user_data;
|
2016-01-07 15:27:35 +01:00
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
g_print ("\tid: %p\n", info->id);
|
2015-08-12 11:34:29 +02:00
|
|
|
g_print ("\tclient-path: \"%s\"\n", info->client_path);
|
2016-02-01 16:29:56 +01:00
|
|
|
if (data->print_all) {
|
2016-05-06 17:54:23 +02:00
|
|
|
g_print ("\tsender: \"%s\"\n", info->sender);
|
|
|
|
|
print_properties (info->properties, MARK_CHANGE (0));
|
2016-02-01 16:29:56 +01:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2016-05-06 13:01:52 +02:00
|
|
|
dump_node_info (PinosContext *c, const PinosNodeInfo *info, gpointer user_data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData *data = user_data;
|
2016-01-07 15:27:35 +01:00
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
g_print ("\tid: %p\n", info->id);
|
2016-05-06 13:01:52 +02:00
|
|
|
g_print ("\tnode-path: \"%s\"\n", info->node_path);
|
2016-02-01 16:29:56 +01:00
|
|
|
if (data->print_all) {
|
|
|
|
|
g_print ("%c\tname: \"%s\"\n", MARK_CHANGE (0), info->name);
|
|
|
|
|
print_properties (info->properties, MARK_CHANGE (1));
|
2016-05-06 13:01:52 +02:00
|
|
|
g_print ("%c\tstate: \"%s\"\n", MARK_CHANGE (2), pinos_node_state_as_string (info->state));
|
2016-02-01 16:29:56 +01:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 12:15:57 +01:00
|
|
|
static void
|
2016-05-06 13:01:52 +02:00
|
|
|
dump_port_info (PinosContext *c, const PinosPortInfo *info, gpointer user_data)
|
2015-04-27 09:05:14 +02:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData *data = user_data;
|
2016-01-07 15:27:35 +01:00
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
g_print ("\tid: %p\n", info->id);
|
2016-05-06 13:01:52 +02:00
|
|
|
g_print ("\tport-path: \"%s\"\n", info->port_path);
|
2016-05-03 18:00:56 +02:00
|
|
|
if (data->print_all) {
|
2016-05-06 13:01:52 +02:00
|
|
|
g_print ("\tnode-path: \"%s\"\n", info->node_path);
|
|
|
|
|
g_print ("\tdirection: \"%s\"\n", pinos_direction_as_string (info->direction));
|
2016-05-03 18:00:56 +02:00
|
|
|
g_print ("%c\tname: \"%s\"\n", MARK_CHANGE (0), info->name);
|
|
|
|
|
print_properties (info->properties, MARK_CHANGE (1));
|
2016-05-06 13:01:52 +02:00
|
|
|
print_formats ("possible formats", info->possible_formats, MARK_CHANGE (2));
|
2016-05-03 18:00:56 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-12 17:03:28 +02:00
|
|
|
#if 0
|
2016-05-03 18:00:56 +02:00
|
|
|
static void
|
2016-05-12 17:03:28 +02:00
|
|
|
dump_connection_info (PinosContext *c, const PinosConnectionInfo *info, gpointer user_data)
|
2016-05-03 18:00:56 +02:00
|
|
|
{
|
|
|
|
|
DumpData *data = user_data;
|
|
|
|
|
|
|
|
|
|
g_print ("\tid: %p\n", info->id);
|
2016-05-12 17:03:28 +02:00
|
|
|
g_print ("\tconnection-path: \"%s\"\n", info->connection_path);
|
2016-02-01 16:29:56 +01:00
|
|
|
if (data->print_all) {
|
2016-05-12 17:03:28 +02:00
|
|
|
g_print ("%c\tsource-port-path: \"%s\"\n", MARK_CHANGE (0), info->source_port_path);
|
|
|
|
|
g_print ("%c\tdestination-port-path: \"%s\"\n", MARK_CHANGE (1), info->destination_port_path);
|
2016-02-01 16:29:56 +01:00
|
|
|
}
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
2016-05-12 17:03:28 +02:00
|
|
|
#endif
|
2015-07-28 17:05:03 +02:00
|
|
|
|
|
|
|
|
static void
|
2016-01-07 15:27:35 +01:00
|
|
|
dump_object (PinosContext *context, gpointer id, PinosSubscriptionFlags flags,
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData *data)
|
2015-07-28 17:05:03 +02:00
|
|
|
{
|
2015-08-04 17:34:11 +02:00
|
|
|
if (flags & PINOS_SUBSCRIPTION_FLAG_DAEMON) {
|
2015-07-28 17:05:03 +02:00
|
|
|
pinos_context_get_daemon_info (context,
|
|
|
|
|
PINOS_DAEMON_INFO_FLAGS_NONE,
|
|
|
|
|
dump_daemon_info,
|
|
|
|
|
NULL,
|
2016-01-07 12:15:57 +01:00
|
|
|
info_ready,
|
2016-02-01 16:29:56 +01:00
|
|
|
data);
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
2015-08-04 17:34:11 +02:00
|
|
|
else if (flags & PINOS_SUBSCRIPTION_FLAG_CLIENT) {
|
2015-07-28 17:05:03 +02:00
|
|
|
pinos_context_get_client_info_by_id (context,
|
2015-08-12 11:34:29 +02:00
|
|
|
id,
|
2015-07-28 17:05:03 +02:00
|
|
|
PINOS_CLIENT_INFO_FLAGS_NONE,
|
|
|
|
|
dump_client_info,
|
|
|
|
|
NULL,
|
2016-01-07 12:15:57 +01:00
|
|
|
info_ready,
|
2016-02-01 16:29:56 +01:00
|
|
|
data);
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
2016-05-06 13:01:52 +02:00
|
|
|
else if (flags & PINOS_SUBSCRIPTION_FLAG_NODE) {
|
|
|
|
|
pinos_context_get_node_info_by_id (context,
|
|
|
|
|
id,
|
|
|
|
|
PINOS_NODE_INFO_FLAGS_NONE,
|
|
|
|
|
dump_node_info,
|
|
|
|
|
NULL,
|
|
|
|
|
info_ready,
|
|
|
|
|
data);
|
2015-07-28 17:05:03 +02:00
|
|
|
}
|
2016-05-06 13:01:52 +02:00
|
|
|
else if (flags & PINOS_SUBSCRIPTION_FLAG_PORT) {
|
|
|
|
|
pinos_context_get_port_info_by_id (context,
|
2016-05-03 18:00:56 +02:00
|
|
|
id,
|
2016-05-06 13:01:52 +02:00
|
|
|
PINOS_PORT_INFO_FLAGS_FORMATS,
|
|
|
|
|
dump_port_info,
|
2016-05-03 18:00:56 +02:00
|
|
|
NULL,
|
|
|
|
|
info_ready,
|
|
|
|
|
data);
|
|
|
|
|
}
|
2015-04-27 09:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
static void
|
2015-07-08 17:40:37 +02:00
|
|
|
subscription_cb (PinosContext *context,
|
|
|
|
|
PinosSubscriptionEvent type,
|
|
|
|
|
PinosSubscriptionFlags flags,
|
|
|
|
|
gpointer id,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2016-02-01 16:29:56 +01:00
|
|
|
DumpData data;
|
|
|
|
|
|
2015-04-27 09:05:14 +02:00
|
|
|
switch (type) {
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_SUBSCRIPTION_EVENT_NEW:
|
2015-08-12 11:34:29 +02:00
|
|
|
g_print ("added:\n");
|
2016-02-01 16:29:56 +01:00
|
|
|
data.print_mark = FALSE;
|
|
|
|
|
data.print_all = TRUE;
|
|
|
|
|
dump_object (context, id, flags, &data);
|
2015-04-27 09:05:14 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_SUBSCRIPTION_EVENT_CHANGE:
|
2015-08-12 11:34:29 +02:00
|
|
|
g_print ("changed:\n");
|
2016-02-01 16:29:56 +01:00
|
|
|
data.print_mark = TRUE;
|
|
|
|
|
data.print_all = TRUE;
|
|
|
|
|
dump_object (context, id, flags, &data);
|
2015-04-27 09:05:14 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_SUBSCRIPTION_EVENT_REMOVE:
|
2015-08-12 11:34:29 +02:00
|
|
|
g_print ("removed:\n");
|
2016-02-01 16:29:56 +01:00
|
|
|
data.print_mark = FALSE;
|
|
|
|
|
data.print_all = FALSE;
|
|
|
|
|
dump_object (context, id, flags, &data);
|
2015-04-27 09:05:14 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_state_notify (GObject *gobject,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContextState state;
|
2015-08-12 09:53:27 +02:00
|
|
|
PinosContext *c = PINOS_CONTEXT (gobject);
|
|
|
|
|
const GError *error;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-08-12 09:53:27 +02:00
|
|
|
g_object_get (c, "state", &state, NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (state) {
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_CONTEXT_STATE_ERROR:
|
2015-08-12 09:53:27 +02:00
|
|
|
error = pinos_context_get_error (c);
|
|
|
|
|
g_print ("context error: %s\n", error->message);
|
2015-04-16 16:58:33 +02:00
|
|
|
break;
|
2015-04-17 17:27:26 +02:00
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
default:
|
2015-09-30 10:50:45 +02:00
|
|
|
g_print ("context state: \"%s\"\n", pinos_context_state_as_string (state));
|
2015-04-16 16:58:33 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
main (gint argc, gchar *argv[])
|
|
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContext *c;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_init (&argc, &argv);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
|
2015-08-25 13:06:05 +02:00
|
|
|
c = pinos_context_new (NULL, "pinos-monitor", NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
g_signal_connect (c, "notify::state", (GCallback) on_state_notify, c);
|
2015-07-07 16:46:23 +02:00
|
|
|
g_object_set (c, "subscription-mask", PINOS_SUBSCRIPTION_FLAGS_ALL, NULL);
|
2015-05-21 10:18:21 +02:00
|
|
|
g_signal_connect (c, "subscription-event", (GCallback) subscription_cb, NULL);
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_context_connect(c, PINOS_CONTEXT_FLAGS_NOFAIL);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
g_main_loop_run (loop);
|
|
|
|
|
|
|
|
|
|
g_object_unref (c);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|