diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dbus-print-message.c | 23 | ||||
-rw-r--r-- | tools/dbus-send.1 | 5 | ||||
-rw-r--r-- | tools/dbus-send.c | 46 |
3 files changed, 68 insertions, 6 deletions
diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c index bb380ce5..7c5328da 100644 --- a/tools/dbus-print-message.c +++ b/tools/dbus-print-message.c @@ -21,15 +21,36 @@ */ #include "dbus-print-message.h" +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)"; + } +} + void print_message (DBusMessage *message) { DBusMessageIter iter; const char *sender; + int message_type; + message_type = dbus_message_get_type (message); sender = dbus_message_get_sender (message); - printf ("message name=%s; sender=%s\n", + printf ("%s name=%s; sender=%s\n", + type_to_name (message_type), dbus_message_get_name (message), sender ? sender : "(no sender)"); diff --git a/tools/dbus-send.1 b/tools/dbus-send.1 index 08ea1335..f71c4c6e 100644 --- a/tools/dbus-send.1 +++ b/tools/dbus-send.1 @@ -8,7 +8,7 @@ dbus-send \- Send a message to a message bus .SH SYNOPSIS .PP .B dbus-send -[\-\-system | \-\-session] [\-\-dest=SERVICE] [\-\-print-reply] <message name> [contents ...] +[\-\-system | \-\-session] [\-\-dest=SERVICE] [\-\-print-reply] [\-\-type=TYPE] <message name> [contents ...] .SH DESCRIPTION @@ -62,6 +62,9 @@ Send to the system message bus. .TP .I "--session" Send to the session message bus. (This is the default.) +.TP +.I "--type=TYPE" +Specify "method_call" or "signal" (defaults to "signal"). .SH AUTHOR dbus-send was written by Philip Blundell. diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 12ad5c8c..fb876b52 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -30,7 +30,7 @@ static void usage (char *name, int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session] [--dest=SERVICE] [--print-reply] <message type> [contents ...]\n", name); + fprintf (stderr, "Usage: %s [--help] [--system | --session] [--dest=SERVICE] [--type=TYPE] [--print-reply] <message name> [contents ...]\n", name); exit (ecode); } @@ -44,9 +44,11 @@ main (int argc, char *argv[]) DBusMessageIter iter; int i; DBusBusType type = DBUS_BUS_SESSION; - char *dest = DBUS_SERVICE_BROADCAST; + const char *dest = DBUS_SERVICE_BROADCAST; char *name = NULL; - + int message_type = DBUS_MESSAGE_TYPE_SIGNAL; + const char *type_str = NULL; + if (argc < 2) usage (argv[0], 1); @@ -64,6 +66,8 @@ main (int argc, char *argv[]) print_reply = TRUE; else if (strstr (arg, "--dest=") == arg) dest = strchr (arg, '=') + 1; + else if (strstr (arg, "--type=") == arg) + type_str = strchr (arg, '=') + 1; else if (!strcmp(arg, "--help")) usage (argv[0], 0); else if (arg[0] == '-') @@ -75,6 +79,20 @@ main (int argc, char *argv[]) if (name == NULL) usage (argv[0], 1); + if (type_str != NULL) + { + if (strcmp (type_str, "method_call") == 0) + message_type = DBUS_MESSAGE_TYPE_METHOD_CALL; + else if (strcmp (type_str, "signal") == 0) + message_type = DBUS_MESSAGE_TYPE_SIGNAL; + else + { + fprintf (stderr, "Message type \"%s\" is not supported\n", + type_str); + exit (1); + } + } + dbus_error_init (&error); connection = dbus_bus_get (type, &error); if (connection == NULL) @@ -86,13 +104,32 @@ main (int argc, char *argv[]) exit (1); } - message = dbus_message_new (name, dest); + if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) + { + message = dbus_message_new_method_call (name, NULL); + } + else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL) + { + message = dbus_message_new_signal (name); + } + else + { + fprintf (stderr, "Internal error, unknown message type\n"); + exit (1); + } + if (message == NULL) { fprintf (stderr, "Couldn't allocate D-BUS message\n"); exit (1); } + if (dest && !dbus_message_set_destination (message, dest)) + { + fprintf (stderr, "Not enough memory\n"); + exit (1); + } + dbus_message_append_iter_init (message, &iter); while (i < argc) @@ -135,6 +172,7 @@ main (int argc, char *argv[]) exit (1); } + /* FIXME - we are ignoring OOM returns on all these functions */ switch (type) { case DBUS_TYPE_BYTE: |