aboutsummaryrefslogtreecommitdiff
path: root/cups
diff options
context:
space:
mode:
authorTill Kamppeter <till.kamppeter@gmail.com>2009-08-27 09:07:49 +0200
committerMarcel Holtmann <marcel@holtmann.org>2009-08-30 09:26:56 -0700
commit74799904f87e948612ec563005033d7d0b4f9943 (patch)
treec377c873ec095771ddd36293ddcb4a2500a2574c /cups
parent970e9e9a48ae2c1226b1b05556a54c0ceb03a96d (diff)
downloadbluez-74799904f87e948612ec563005033d7d0b4f9943.tar.gz
Make discovery mode work with CUPS 1.4.x
The new CUPS 1.4.x does device discovery only for a given time frame requested by the client (printer setup tool, "lpinfo" command). CUPS's default for CUPS-1.3.x-ish requests without timeout specification seems to be 10 seconds. CUPS starts all backends at once in the beginning (in parallel) and kills every backend which remains running at the end of the timeout. It accepts output from the backends whenever it occurs not only when the backend finishes, so a backend can search for printers infinitely long if it outputs every found device immediately. Then all printers found during CUPS' timeout are taken into account. The bluetooth backend of 4.48 asks the Bluetooth daemon for printers and collects results for 10 seconds and after that it outputs them. This takes a total of 10.5 sec and so CUPS kills the backend right before it answers (at least with the 10-second default timeout), resulting in Bluetooth printers never being discovered by CUPS. This change fixes it by making each new printer added to the list being output immediately. Note that the list structure cannot be removed from cups/main.c as otherwise we would get duplicate listings. Also important is the addition of unbuffered output on stdout.
Diffstat (limited to 'cups')
-rw-r--r--cups/main.c63
1 files changed, 25 insertions, 38 deletions
diff --git a/cups/main.c b/cups/main.c
index da757b05..1bbc78c7 100644
--- a/cups/main.c
+++ b/cups/main.c
@@ -185,6 +185,27 @@ static char *device_get_ieee1284_id(const char *adapter, const char *device)
return id;
}
+static void print_printer_details(const char *name, const char *bdaddr, const char *id)
+{
+ char *uri, *escaped;
+
+ escaped = g_strdelimit(g_strdup(name), "\"", '\'');
+ uri = g_strdup_printf("bluetooth://%c%c%c%c%c%c%c%c%c%c%c%c",
+ bdaddr[0], bdaddr[1],
+ bdaddr[3], bdaddr[4],
+ bdaddr[6], bdaddr[7],
+ bdaddr[9], bdaddr[10],
+ bdaddr[12], bdaddr[13],
+ bdaddr[15], bdaddr[16]);
+ printf("direct %s \"%s\" \"%s (Bluetooth)\"", uri, escaped, escaped);
+ if (id != NULL)
+ printf(" \"%s\"\n", id);
+ else
+ printf("\n");
+ g_free(escaped);
+ g_free(uri);
+}
+
static void add_device_to_list(const char *name, const char *bdaddr, const char *id)
{
struct cups_device *device;
@@ -212,27 +233,7 @@ static void add_device_to_list(const char *name, const char *bdaddr, const char
device->id = g_strdup(id);
device_list = g_slist_prepend(device_list, device);
-}
-
-static void print_printer_details(const char *name, const char *bdaddr, const char *id)
-{
- char *uri, *escaped;
-
- escaped = g_strdelimit(g_strdup(name), "\"", '\'');
- uri = g_strdup_printf("bluetooth://%c%c%c%c%c%c%c%c%c%c%c%c",
- bdaddr[0], bdaddr[1],
- bdaddr[3], bdaddr[4],
- bdaddr[6], bdaddr[7],
- bdaddr[9], bdaddr[10],
- bdaddr[12], bdaddr[13],
- bdaddr[15], bdaddr[16]);
- printf("direct %s \"%s\" \"%s (Bluetooth)\"", uri, escaped, escaped);
- if (id != NULL)
- printf(" \"%s\"\n", id);
- else
- printf("\n");
- g_free(escaped);
- g_free(uri);
+ print_printer_details(device->name, device->bdaddr, device->id);
}
static gboolean parse_device_properties(DBusMessageIter *reply_iter, char **name, char **bdaddr)
@@ -384,23 +385,6 @@ static void remote_device_found(const char *adapter, const char *bdaddr, const c
static void discovery_completed(void)
{
- GSList *l;
-
- for (l = device_list; l != NULL; l = l->next) {
- struct cups_device *device = (struct cups_device *) l->data;
-
- if (device->name == NULL)
- device->name = g_strdelimit(g_strdup(device->bdaddr), ":", '-');
- /* Give another try to getting an ID for the device */
- if (device->id == NULL)
- remote_device_found(NULL, device->bdaddr, device->name);
- print_printer_details(device->name, device->bdaddr, device->id);
- g_free(device->name);
- g_free(device->bdaddr);
- g_free(device->id);
- g_free(device);
- }
-
g_slist_free(device_list);
device_list = NULL;
@@ -638,6 +622,9 @@ int main(int argc, char *argv[])
/* Make sure status messages are not buffered */
setbuf(stderr, NULL);
+ /* Make sure output is not buffered */
+ setbuf(stdout, NULL);
+
/* Ignore SIGPIPE signals */
#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);