2003-06-19 Philip Blundell <philb@gnu.org>
[platform/upstream/dbus.git] / tools / dbus-print-message.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-print-message.h  Utility function to print out a message
3  *
4  * Copyright (C) 2003 Philip Blundell <philb@gnu.org>
5  * Copyright (C) 2003 Red Hat, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22 #include "dbus-print-message.h"
23
24 void
25 print_message (DBusMessage *message)
26 {
27   DBusMessageIter iter;
28   const char *sender;
29
30   sender = dbus_message_get_sender (message); 
31   
32   printf ("message name=%s; sender=%s\n",
33           dbus_message_get_name (message),
34           sender ? sender : "(no sender)");
35   
36   dbus_message_iter_init (message, &iter);
37
38   do
39     {
40       int type = dbus_message_iter_get_arg_type (&iter);
41       char *str;
42       dbus_uint32_t uint32;
43       dbus_int32_t int32;
44       double d;
45       unsigned char byte;
46       dbus_bool_t boolean;
47
48       if (type == DBUS_TYPE_INVALID)
49         break;
50
51       switch (type)
52         {
53         case DBUS_TYPE_STRING:
54           str = dbus_message_iter_get_string (&iter);
55           printf ("string:%s\n", str);
56           break;
57
58         case DBUS_TYPE_INT32:
59           int32 = dbus_message_iter_get_int32 (&iter);
60           printf ("int32:%d\n", int32);
61           break;
62
63         case DBUS_TYPE_UINT32:
64           uint32 = dbus_message_iter_get_uint32 (&iter);
65           printf ("int32:%u\n", uint32);
66           break;
67
68         case DBUS_TYPE_DOUBLE:
69           d = dbus_message_iter_get_double (&iter);
70           printf ("double:%f\n", d);
71           break;
72
73         case DBUS_TYPE_BYTE:
74           byte = dbus_message_iter_get_byte (&iter);
75           printf ("byte:%d\n", byte);
76           break;
77
78         case DBUS_TYPE_BOOLEAN:
79           boolean = dbus_message_iter_get_boolean (&iter);
80           printf ("boolean:%s\n", boolean ? "true" : "false");
81           break;
82
83         default:
84           printf ("(unknown arg type %d)\n", type);
85           break;
86         }
87     } while (dbus_message_iter_next (&iter));
88 }
89