From 98a2c46e49343ac0becc73f8f37c4334a5c2adb2 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Tue, 16 Feb 2010 18:29:30 +0100 Subject: Add a limit argument to DevicesGet The pycups API has this argument. --- src/cups-pk-helper-mechanism.c | 2 ++ src/cups-pk-helper-mechanism.h | 1 + src/cups-pk-helper-mechanism.xml | 1 + src/cups.c | 17 ++++++++++++++--- src/cups.h | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cups-pk-helper-mechanism.c b/src/cups-pk-helper-mechanism.c index d4b6a38..bc341f4 100644 --- a/src/cups-pk-helper-mechanism.c +++ b/src/cups-pk-helper-mechanism.c @@ -1170,6 +1170,7 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism, gboolean cph_mechanism_devices_get (CphMechanism *mechanism, int timeout, + int limit, const char *include_schemes, const char *exclude_schemes, DBusGMethodInvocation *context) @@ -1183,6 +1184,7 @@ cph_mechanism_devices_get (CphMechanism *mechanism, devices = cph_cups_devices_get (mechanism->priv->cups, timeout, + limit, include_schemes, exclude_schemes); _cph_mechanism_return_error_and_value (mechanism, context, diff --git a/src/cups-pk-helper-mechanism.h b/src/cups-pk-helper-mechanism.h index 2094945..81ddb82 100644 --- a/src/cups-pk-helper-mechanism.h +++ b/src/cups-pk-helper-mechanism.h @@ -239,6 +239,7 @@ cph_mechanism_job_set_hold_until (CphMechanism *mechanism, gboolean cph_mechanism_devices_get (CphMechanism *mechanism, int timeout, + int limit, const char *include_schemes, const char *exclude_schemes, DBusGMethodInvocation *context); diff --git a/src/cups-pk-helper-mechanism.xml b/src/cups-pk-helper-mechanism.xml index 9f732f1..10b7eff 100644 --- a/src/cups-pk-helper-mechanism.xml +++ b/src/cups-pk-helper-mechanism.xml @@ -196,6 +196,7 @@ + diff --git a/src/cups.c b/src/cups.c index 15d92b7..8739a55 100644 --- a/src/cups.c +++ b/src/cups.c @@ -1809,6 +1809,7 @@ cph_cups_job_get_status (CphCups *cups, struct _CphCupsGetDevices { int iter; + int limit; GHashTable *hash; }; @@ -1825,6 +1826,9 @@ _cph_cups_get_devices_cb (const char *device_class, g_return_if_fail (data != NULL); + if (data->limit > 0 && data->iter >= data->limit) + return; + if (device_class && device_class[0] != '\0') g_hash_table_replace (data->hash, g_strdup_printf ("device-class:%d", @@ -1862,6 +1866,7 @@ _cph_cups_get_devices_cb (const char *device_class, GHashTable * cph_cups_devices_get (CphCups *cups, int timeout, + int limit, const char *include_schemes, const char *exclude_schemes) { @@ -1870,9 +1875,12 @@ cph_cups_devices_get (CphCups *cups, g_return_val_if_fail (CPH_IS_CUPS (cups), NULL); - data.iter = 0; - data.hash = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, g_free); + data.iter = 0; + data.limit = -1; + data.hash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, g_free); + if (limit > 0) + data.limit = limit; #if (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 4) || CUPS_VERSION_MAJOR > 1 ipp_status_t retval; @@ -1915,6 +1923,9 @@ cph_cups_devices_get (CphCups *cups, if (timeout > 0) ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "timeout", timeout); + if (limit > 0) + ippAddInteger (request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, + "limit", limit); resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT); reply = cupsDoRequest (cups->priv->connection, diff --git a/src/cups.h b/src/cups.h index 47b7a36..251bc26 100644 --- a/src/cups.h +++ b/src/cups.h @@ -186,6 +186,7 @@ CphJobStatus cph_cups_job_get_status (CphCups *cups, GHashTable *cph_cups_devices_get (CphCups *cups, int timeout, + int limit, const char *include_schemes, const char *exclude_schemes); -- cgit v1.2.3