Use a macro for type_to_mask

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2013-06-05 16:03:54 +10:00
parent 6019083a1a
commit 31961e8d59

View file

@ -53,30 +53,26 @@ set_bit_state(unsigned long *array, int bit, int state)
clear_bit(array, bit); clear_bit(array, bit);
} }
#define max_mask(uc, lc) \
case EV_##uc: \
*mask = dev->lc##_bits; \
max = libevdev_get_event_type_max(type); \
break;
static inline int static inline int
type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned long **mask) type_to_mask_const(const struct libevdev *dev, unsigned int type, const unsigned long **mask)
{ {
int max; int max;
switch(type) { switch(type) {
case EV_ABS: max_mask(ABS, abs);
*mask = dev->abs_bits; max_mask(REL, rel);
max = ABS_MAX; max_mask(KEY, key);
break; max_mask(LED, led);
case EV_REL:
*mask = dev->rel_bits;
max = REL_MAX;
break;
case EV_KEY:
*mask = dev->key_bits;
max = KEY_MAX;
break;
case EV_LED:
*mask = dev->led_bits;
max = LED_MAX;
break;
default: default:
return -1; max = -1;
break;
} }
return max; return max;
@ -88,27 +84,18 @@ type_to_mask(struct libevdev *dev, unsigned int type, unsigned long **mask)
int max; int max;
switch(type) { switch(type) {
case EV_ABS: max_mask(ABS, abs);
*mask = dev->abs_bits; max_mask(REL, rel);
max = ABS_MAX; max_mask(KEY, key);
break; max_mask(LED, led);
case EV_REL:
*mask = dev->rel_bits;
max = REL_MAX;
break;
case EV_KEY:
*mask = dev->key_bits;
max = KEY_MAX;
break;
case EV_LED:
*mask = dev->led_bits;
max = LED_MAX;
break;
default: default:
return -1; max = -1;
break;
} }
return max; return max;
} }
#undef max_mask
#endif #endif