2003-05-16 20:09:25 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* dbus-print-message.h Utility function to print out a message
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Philip Blundell <philb@gnu.org>
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include "dbus-print-message.h"
|
|
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
static const char*
|
|
|
|
|
type_to_name (int message_type)
|
|
|
|
|
{
|
|
|
|
|
switch (message_type)
|
|
|
|
|
{
|
|
|
|
|
case DBUS_MESSAGE_TYPE_SIGNAL:
|
|
|
|
|
return "signal";
|
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_CALL:
|
|
|
|
|
return "method call";
|
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
|
|
|
|
return "method return";
|
|
|
|
|
case DBUS_MESSAGE_TYPE_ERROR:
|
|
|
|
|
return "error";
|
|
|
|
|
default:
|
|
|
|
|
return "(unknown message type)";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 18:48:24 +00:00
|
|
|
static void
|
|
|
|
|
print_iter (DBusMessageIter *iter, int depth)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
int type = dbus_message_iter_get_arg_type (iter);
|
|
|
|
|
const char *str;
|
|
|
|
|
dbus_uint32_t uint32;
|
|
|
|
|
dbus_int32_t int32;
|
|
|
|
|
double d;
|
|
|
|
|
unsigned char byte;
|
|
|
|
|
dbus_bool_t boolean;
|
|
|
|
|
|
|
|
|
|
if (type == DBUS_TYPE_INVALID)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
while (depth-- > 0)
|
|
|
|
|
putc (' ', stdout);
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case DBUS_TYPE_STRING:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &str);
|
|
|
|
|
printf ("string \"%s\"\n", str);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_INT32:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &int32);
|
|
|
|
|
printf ("int32 %d\n", int32);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_UINT32:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &uint32);
|
|
|
|
|
printf ("uint32 %u\n", uint32);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_DOUBLE:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &d);
|
|
|
|
|
printf ("double %g\n", d);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_BYTE:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &byte);
|
|
|
|
|
printf ("byte %d\n", byte);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_BOOLEAN:
|
|
|
|
|
dbus_message_iter_get_basic (iter, &boolean);
|
|
|
|
|
printf ("boolean %s\n", boolean ? "true" : "false");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_TYPE_VARIANT:
|
|
|
|
|
{
|
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (iter, &subiter);
|
|
|
|
|
|
|
|
|
|
printf ("variant:");
|
|
|
|
|
print_iter (&subiter, depth);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DBUS_TYPE_ARRAY:
|
|
|
|
|
{
|
|
|
|
|
int current_type;
|
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (iter, &subiter);
|
|
|
|
|
|
|
|
|
|
printf("[");
|
|
|
|
|
while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
print_iter (&subiter, depth);
|
|
|
|
|
dbus_message_iter_next (&subiter);
|
|
|
|
|
if (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID)
|
|
|
|
|
printf (",");
|
|
|
|
|
}
|
|
|
|
|
printf("]");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-06-16 04:48:10 +00:00
|
|
|
case DBUS_TYPE_DICT_ENTRY:
|
|
|
|
|
{
|
|
|
|
|
DBusMessageIter subiter;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (iter, &subiter);
|
|
|
|
|
|
|
|
|
|
printf("{");
|
|
|
|
|
print_iter (&subiter, depth);
|
|
|
|
|
dbus_message_iter_next (&subiter);
|
|
|
|
|
print_iter (&subiter, depth);
|
|
|
|
|
printf("}");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-05-11 18:48:24 +00:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while (dbus_message_iter_next (iter));
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-16 20:09:25 +00:00
|
|
|
void
|
|
|
|
|
print_message (DBusMessage *message)
|
|
|
|
|
{
|
|
|
|
|
DBusMessageIter iter;
|
|
|
|
|
const char *sender;
|
2005-01-30 07:44:08 +00:00
|
|
|
const char *destination;
|
2003-08-11 02:11:58 +00:00
|
|
|
int message_type;
|
2003-05-16 20:09:25 +00:00
|
|
|
|
2003-08-11 02:11:58 +00:00
|
|
|
message_type = dbus_message_get_type (message);
|
2005-01-30 07:44:08 +00:00
|
|
|
sender = dbus_message_get_sender (message);
|
|
|
|
|
destination = dbus_message_get_destination (message);
|
|
|
|
|
|
|
|
|
|
printf ("%s sender=%s -> dest=%s",
|
|
|
|
|
type_to_name (message_type),
|
|
|
|
|
sender ? sender : "(null sender)",
|
|
|
|
|
destination ? destination : "(null destination)");
|
|
|
|
|
|
2003-08-18 22:43:30 +00:00
|
|
|
switch (message_type)
|
|
|
|
|
{
|
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_CALL:
|
|
|
|
|
case DBUS_MESSAGE_TYPE_SIGNAL:
|
2005-01-30 07:44:08 +00:00
|
|
|
printf (" interface=%s; member=%s\n",
|
2003-08-18 22:43:30 +00:00
|
|
|
dbus_message_get_interface (message),
|
2005-01-30 07:44:08 +00:00
|
|
|
dbus_message_get_member (message));
|
2003-08-18 22:43:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
|
2005-01-30 07:44:08 +00:00
|
|
|
printf ("\n");
|
2003-08-18 22:43:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DBUS_MESSAGE_TYPE_ERROR:
|
2005-01-30 07:44:08 +00:00
|
|
|
printf (" error_name=%s\n",
|
|
|
|
|
dbus_message_get_error_name (message));
|
2003-08-18 22:43:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2005-01-30 07:44:08 +00:00
|
|
|
printf ("\n");
|
2003-08-18 22:43:30 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2003-05-16 20:09:25 +00:00
|
|
|
|
2005-01-30 07:44:08 +00:00
|
|
|
dbus_message_iter_init (message, &iter);
|
2005-05-11 18:48:24 +00:00
|
|
|
print_iter (&iter, 1);
|
2005-01-30 07:44:08 +00:00
|
|
|
|
2003-05-16 20:09:25 +00:00
|
|
|
}
|
|
|
|
|
|