~xdavidwu/motion-control

ffeec99fd75a4fe980e55a6eecb07e9cc71e70d9 — xdavidwu 2 years ago c72d54e
evdev: wrap errors to errors::error
M cmd/pointerd/main.ha => cmd/pointerd/main.ha +2 -2
@@ 42,8 42,8 @@ export fn main() void = {
	const uinput = match (uinput::create_from_device(evdev, uinput::OPEN_MANAGED)) {
	case let uinput: uinput::uinput =>
		yield uinput;
	case let err: rt::errno =>
		fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err));
	case let err: errors::error =>
		fmt::fatalf("Failed to create uinput dev: {}", errors::strerror(err));
	};
	defer uinput::destroy(uinput);


M evdev/libevdev.ha => evdev/libevdev.ha +4 -4
@@ 3,11 3,11 @@ use io;
use rt;
use strings;

export fn new_from_fd(fd: io::file) (rt::errno | libevdev) = {
export fn new_from_fd(fd: io::file) (errors::error | libevdev) = {
	let handle = null: libevdev;
	const r = c_libevdev_new_from_fd(fd, &handle);
	if (r < 0) {
		return (-r): rt::errno;
		return errors::errno(-r);
	};
	return handle;
};


@@ 22,11 22,11 @@ export fn set_name(dev: libevdev, name: str) void = {
	c_libevdev_set_name(dev, cstr);
};

export fn next_event(dev: libevdev, flags: uint) (rt::errno | input_event) = {
export fn next_event(dev: libevdev, flags: uint) (errors::error | input_event) = {
	let ev = input_event { ... };
	const r = c_libevdev_next_event(dev, flags, &ev);
	if (r < 0) {
		return (-r): rt::errno;
		return errors::errno(-r);
	};
	return ev;
};

M evdev/uinput/uinput.ha => evdev/uinput/uinput.ha +5 -4
@@ 1,22 1,23 @@
use errors;
use evdev;
use io;
use rt;

export fn create_from_device(dev: evdev::libevdev, fd: io::file)
			(uinput | rt::errno) = {
			(uinput | errors::error) = {
	let handle = null: uinput;
	const r = c_libevdev_uinput_create_from_device(dev, fd: int, &handle);
	if (r < 0) {
		return (-r): rt::errno;
		return errors::errno(-r);
	};
	return handle;
};

export fn write_event(uinput_dev: uinput, event_type: uint, code: uint, value: int)
		(void | rt::errno) = {
		(void | errors::error) = {
	const r = c_libevdev_uinput_write_event(uinput_dev, event_type, code, value);
	if (r < 0) {
		return (-r): rt::errno;
		return errors::errno(-r);
	};
};


M tools/evdev-dump-events/main.ha => tools/evdev-dump-events/main.ha +6 -7
@@ 4,7 4,6 @@ use fmt;
use fs;
use io;
use os;
use rt;
use strconv;

export fn main() void = {


@@ 21,8 20,8 @@ export fn main() void = {
	const evdev = match (evdev::new_from_fd(file)) {
	case let evdev: evdev::libevdev =>
		yield evdev;
	case let err: rt::errno =>
		fmt::fatalf("Failed to init libevdev: {}", rt::strerror(err));
	case let err: errors::error =>
		fmt::fatalf("Failed to init libevdev: {}", errors::strerror(err));
	};

	fmt::printfln("Input device name: {}", evdev::get_name(evdev))!;


@@ 31,12 30,12 @@ export fn main() void = {
		let ev = match (evdev::next_event(evdev, evdev::READ_FLAG_NORMAL)) {
		case let ev: evdev::input_event =>
			yield ev;
		case let err: rt::errno =>
			switch (err) {
			case rt::EAGAIN =>
		case let err: errors::error =>
			match (err) {
			case errors::again =>
				continue;
			case =>
				fmt::fatalf("Failed to get event: {}", rt::strerror(err));
				fmt::fatalf("Failed to get event: {}", errors::strerror(err));
			};
		};
		match (evdev::event_type_get_name(ev._type)) {

M tools/uinput-pointer/main.ha => tools/uinput-pointer/main.ha +3 -2
@@ 1,3 1,4 @@
use errors;
use evdev;
use evdev::uinput;
use fmt;


@@ 19,8 20,8 @@ export fn main() void = {
	const uinput = match (uinput::create_from_device(evdev, uinput::OPEN_MANAGED)) {
	case let uinput: uinput::uinput =>
		yield uinput;
	case let err: rt::errno =>
		fmt::fatalf("Failed to create uinput dev: {}", rt::strerror(err));
	case let err: errors::error =>
		fmt::fatalf("Failed to create uinput dev: {}", errors::strerror(err));
	};
	defer uinput::destroy(uinput);