/* Read devices from a /proc/bus/input/devices-like file
 * Version 1.0 (17/02/2008)
 *
 * Written by Daniel Collins <solemnwarning@solemnwarning.net>
 * Released as public domain
*/

#ifndef SOLEMN_DEVICES_H
#define SOLEMN_DEVICES_H
#include <stdlib.h>
#include <stdint.h>

#define DEVFILE "/proc/bus/input/devices"
#define MAX_HANDLERS 16

#define DEVICE_DEFAULTS(ptr) \
	(ptr)->bus = 0;\
	(ptr)->vendor = 0;\
	(ptr)->product = 0;\
	(ptr)->version = 0;\
	memset((ptr)->name, '\0', 1024);\
	memset((ptr)->phys, '\0', 1024);\
	memset((ptr)->handlers, '\0', MAX_HANDLERS*64);\
	(ptr)->hcount = 0;\
	(ptr)->next = NULL;

typedef struct input_dev_list input_dev_list;

struct input_dev_list {
	uint16_t bus;
	uint16_t vendor;
	uint16_t product;
	uint16_t version;
	
	char name[1024];
	char phys[1024];
	
	char handlers[64][MAX_HANDLERS];
	unsigned int hcount;
	
	input_dev_list *next;
};

extern char input_errmsg[];

input_dev_list *fetch_devices(void);
void free_devices(input_dev_list *list);

#endif /* !SOLEMN_DEVICES_H */
