diff options
author | Bastien Nocera <hadess@hadess.net> | 2010-06-06 15:48:26 +0100 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-09-01 21:34:07 +0300 |
commit | 365a2d5ce84cb6d9a2ad94b6f70b0344d4930afc (patch) | |
tree | fb6200f492f5fe804a9072c28cbc254880d6e95a /cups | |
parent | 0aa80f9be37c496f17e46d4d95b50b507700f5b9 (diff) | |
download | bluez-365a2d5ce84cb6d9a2ad94b6f70b0344d4930afc.tar.gz |
cups: Add ability to print IEEE1284 device ID
Add ability to print IEEE1284 device ID for Bluetooth
printers to allow auto-configuration once paired.
Diffstat (limited to 'cups')
-rw-r--r-- | cups/main.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/cups/main.c b/cups/main.c index 9659a1147..b4206435f 100644 --- a/cups/main.c +++ b/cups/main.c @@ -605,6 +605,79 @@ static gboolean list_printers(void) return TRUE; } +static gboolean print_ieee1284(const char *bdaddr) +{ + DBusMessage *message, *reply, *adapter_reply; + DBusMessageIter iter; + char *object_path = NULL; + char *adapter; + char *id; + + adapter_reply = NULL; + + conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NULL, NULL); + if (conn == NULL) + return FALSE; + + message = dbus_message_new_method_call("org.bluez", "/", + "org.bluez.Manager", + "DefaultAdapter"); + + adapter_reply = dbus_connection_send_with_reply_and_block(conn, + message, -1, NULL); + + dbus_message_unref(message); + + if (dbus_message_get_args(adapter_reply, NULL, + DBUS_TYPE_OBJECT_PATH, &adapter, + DBUS_TYPE_INVALID) == FALSE) + return FALSE; + + message = dbus_message_new_method_call("org.bluez", adapter, + "org.bluez.Adapter", + "FindDevice"); + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &bdaddr); + + if (adapter_reply != NULL) + dbus_message_unref(adapter_reply); + + reply = dbus_connection_send_with_reply_and_block(conn, + message, -1, NULL); + + dbus_message_unref(message); + + if (!reply) { + message = dbus_message_new_method_call("org.bluez", adapter, + "org.bluez.Adapter", + "CreateDevice"); + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, + DBUS_TYPE_STRING, &bdaddr); + + reply = dbus_connection_send_with_reply_and_block(conn, + message, -1, NULL); + + dbus_message_unref(message); + + if (!reply) + return FALSE; + } + if (dbus_message_get_args(reply, NULL, + DBUS_TYPE_OBJECT_PATH, &object_path, + DBUS_TYPE_INVALID) == FALSE) { + return FALSE; + } + + id = device_get_ieee1284_id(adapter, object_path); + if (id == NULL) + return FALSE; + printf("%s", id); + g_free(id); + + return TRUE; +} + /* * Usage: printer-uri job-id user title copies options [file] * @@ -642,10 +715,20 @@ int main(int argc, char *argv[]) return CUPS_BACKEND_OK; else return CUPS_BACKEND_FAILED; + } else if (argc == 3 && strcmp(argv[1], "--get-deviceid") == 0) { + if (bachk(argv[2]) < 0) { + fprintf(stderr, "Invalid Bluetooth address '%s'\n", + argv[2]); + return CUPS_BACKEND_FAILED; + } + if (print_ieee1284(argv[2]) == FALSE) + return CUPS_BACKEND_FAILED; + return CUPS_BACKEND_OK; } if (argc < 6 || argc > 7) { fprintf(stderr, "Usage: bluetooth job-id user title copies options [file]\n"); + fprintf(stderr, " bluetooth --get-deviceid [bdaddr]\n"); return CUPS_BACKEND_FAILED; } |