On Thu, 2012-04-19 at 13:09 +1000, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>

Reviewed-By: Bastien Nocera <had...@hadess.net>

> ---
> Changes since v1:
> - update for new libwacom_get_matches() API
> - moved the misplaced hunk for compare_matches to this patch
> 
>  libwacom/libwacom.c |   72 
> +++++++++++++++++++++++++++++++++++++++++++++++++++
>  libwacom/libwacom.h |   16 ++++++++++++
>  2 files changed, 88 insertions(+)
> 
> diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
> index 8fe2b59..f32ca16 100644
> --- a/libwacom/libwacom.c
> +++ b/libwacom/libwacom.c
> @@ -227,6 +227,78 @@ libwacom_copy(const WacomDevice *device)
>       return d;
>  }
>  
> +
> +static int
> +compare_matches(WacomDevice *a, WacomDevice *b)
> +{
> +     const WacomMatch **ma, **mb, **match_a, **match_b;
> +
> +     ma = libwacom_get_matches(a);
> +     mb = libwacom_get_matches(b);
> +
> +     for (match_a = ma; *match_a; match_a++) {
> +             int found = 0;
> +             for (match_b = mb; !found && *mb; mb++) {
> +                     if (strcmp((*match_a)->match, (*match_b)->match) == 0)
> +                             found = 1;
> +             }
> +             if (!found)
> +                     return 1;
> +     }
> +
> +     return 0;
> +}
> +
> +int
> +libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
> +{
> +     if ((a && !b) || (b && !a))
> +             return 1;
> +
> +     if (strcmp(a->name, b->name) != 0)
> +             return 1;
> +
> +     if (a->width != b->width || a->height != b->height)
> +             return 1;
> +
> +     if (a->cls != b->cls)
> +             return 1;
> +
> +     if (a->num_strips != b->num_strips)
> +             return 1;
> +
> +     if (a->features != b->features)
> +             return 1;
> +
> +     if (a->strips_num_modes != b->strips_num_modes)
> +             return 1;
> +
> +     if (a->ring_num_modes != b->ring_num_modes)
> +             return 1;
> +
> +     if (a->ring2_num_modes != b->ring2_num_modes)
> +             return 1;
> +
> +     if (a->num_buttons != b->num_buttons)
> +             return 1;
> +
> +     if (a->num_styli != b->num_styli)
> +             return 1;
> +
> +     if (memcmp(a->supported_styli, b->supported_styli, sizeof(int) * 
> a->num_styli) != 0)
> +             return 1;
> +
> +     if (memcmp(a->buttons, b->buttons, sizeof(WacomButtonFlags) * 
> a->num_buttons) != 0)
> +             return 1;
> +
> +     if ((flags & WCOMPARE_MATCHES) && compare_matches(a, b) != 0)
> +             return 1;
> +     else if (strcmp(a->matches[a->match]->match, 
> b->matches[b->match]->match) != 0)
> +             return 1;
> +
> +     return 0;
> +}
> +
>  static const WacomDevice *
>  libwacom_new (WacomDeviceDatabase *db, int vendor_id, int product_id, 
> WacomBusType bus, WacomError *error)
>  {
> diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
> index 4bd7940..f1402ce 100644
> --- a/libwacom/libwacom.h
> +++ b/libwacom/libwacom.h
> @@ -167,6 +167,11 @@ typedef enum {
>       WFALLBACK_GENERIC = 1
>  } WacomFallbackFlags;
>  
> +typedef enum {
> +     WCOMPARE_NORMAL         = 0,            /**< compare the device only */
> +     WCOMPARE_MATCHES        = (1 << 1),     /**< compare all possible 
> matches too */
> +} WacomCompareFlags;
> +
>  /**
>   * Allocate a new structure for error reporting.
>   *
> @@ -290,6 +295,17 @@ void libwacom_print_device_description (int fd, 
> WacomDevice *device);
>  void libwacom_destroy(WacomDevice *device);
>  
>  /**
> + * Compare the two devices for equal-ness.
> + *
> + * @param a The first device
> + * @param b The second device
> + * @param flags Flags to dictate what constitutes a match
> + *
> + * @return 0 if the devices are identical, nonzero otherwise
> + */
> +int libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags 
> flags);
> +
> +/**
>   * @param device The tablet to query
>   * @return The class of the device
>   */



------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel

Reply via email to