Exemple #1
0
int cavan_input_service_start(struct cavan_input_service *service, void *data)
{
	int ret;
	struct cavan_event_service *event_service;

	if (service == NULL) {
		pr_red_info("service == NULL");
		ERROR_RETURN(EINVAL);
	}

	pthread_mutex_init(&service->lock, NULL);
	service->private_data = data;

	if (service->handler) {
		service->queue.handler = cavan_input_message_queue_handler;
	} else {
		service->queue.handler = cavan_input_message_queue_handler_dummy;
	}

	ret = cavan_data_queue_run(&service->queue, MOFS(cavan_input_message_t, node), \
			sizeof(cavan_input_message_t), CAVAN_INPUT_MESSAGE_POOL_SIZE, service);
	if (ret < 0) {
		pr_red_info("cavan_data_queue_run");
		return ret;
	}

	event_service = &service->event_service;
	event_service->matcher = cavan_input_device_matcher;
	event_service->probe = cavan_input_device_probe;
	event_service->remove = cavan_input_device_remove;
	event_service->event_handler = cavan_input_device_event_handler;

	ret = cavan_timer_service_start(&service->timer_service);
	if (ret < 0) {
		pr_red_info("cavan_timer_service_start");
		goto out_cavan_data_queue_stop;
	}

	ret = cavan_event_service_start(event_service, service);
	if (ret < 0) {
		pr_red_info("cavan_event_service_start");
		goto out_timer_service_stop;
	}

	return 0;

out_timer_service_stop:
	cavan_timer_service_stop(&service->timer_service);
out_cavan_data_queue_stop:
	cavan_data_queue_stop(&service->queue);
	cavan_data_queue_deinit(&service->queue);
	return ret;
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int ret;
	const char *dev_path;
	char name[64];
	struct cavan_event_service service;

	assert(argc < 3);

	if (argc > 1)
	{
		if (file_test(argv[1], "c") < 0 && text_is_number(argv[1]))
		{
			sprintf(name, "/dev/input/event%s", argv[1]);
			dev_path = name;
		}
		else
		{
			dev_path = argv[1];
		}
	}
	else
	{
		dev_path = NULL;
	}

	cavan_event_service_init(&service, cavan_event_simple_matcher);
	ret = cavan_event_service_start(&service, (void *) dev_path);
	if (ret < 0)
	{
		pr_red_info("cavan_event_service_start");
		return ret;
	}

	cavan_event_service_join(&service);
	cavan_event_service_stop(&service);

	return ret;
}