diff options
Diffstat (limited to 'src/input-device')
-rw-r--r-- | src/input-device/.gitignore | 1 | ||||
-rw-r--r-- | src/input-device/Makefile | 10 | ||||
-rw-r--r-- | src/input-device/input-device-interface.vala | 2 | ||||
-rw-r--r-- | src/input-device/input-device.vala | 15 | ||||
-rw-r--r-- | src/input-device/main.vala | 31 |
5 files changed, 31 insertions, 28 deletions
diff --git a/src/input-device/.gitignore b/src/input-device/.gitignore deleted file mode 100644 index 3ba6df4..0000000 --- a/src/input-device/.gitignore +++ /dev/null @@ -1 +0,0 @@ -input-device diff --git a/src/input-device/Makefile b/src/input-device/Makefile deleted file mode 100644 index aba6c73..0000000 --- a/src/input-device/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: input-device - @echo > /dev/null - -input-device: main.vala input-device.vala input-device-interface.vala ../config/config-interface.vala - valac -X -w -o $@ --pkg linux --pkg posix --pkg gio-2.0 $^ - -clean: - rm -rf input-device - -.PHONY: all clean diff --git a/src/input-device/input-device-interface.vala b/src/input-device/input-device-interface.vala index 067b827..9b16da4 100644 --- a/src/input-device/input-device-interface.vala +++ b/src/input-device/input-device-interface.vala @@ -16,5 +16,5 @@ [DBus (name = "io.mainframe.shopsystem.InputDevice")] public interface InputDevice : Object { public abstract signal void received_barcode(string barcode); - public abstract void blink(uint duration) throws IOError; + public abstract void blink(uint duration) throws IOError, DBusError; } diff --git a/src/input-device/input-device.vala b/src/input-device/input-device.vala index 6988c6d..1dba213 100644 --- a/src/input-device/input-device.vala +++ b/src/input-device/input-device.vala @@ -1,4 +1,5 @@ /* Copyright 2015, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,7 +24,7 @@ public class Device { public Device(string device) { if (device == "ignore") { - stdout.printf("Ignoring InputDevice!\n"); + stdout.printf(_("Ignoring InputDevice!\n")); return; } try { @@ -36,10 +37,10 @@ public class Device { Posix.fcntl(fd, Posix.F_SETFL, flags | Posix.O_NONBLOCK); if(!(io_read.add_watch(IOCondition.IN | IOCondition.HUP, device_read) != 0)) { - error("Could not bind IOChannel"); + error(_("Could not bind IOChannel")); } } catch(FileError e) { - error("FileError: %s", e.message); + error(_("File Error: %s"), e.message); } } @@ -211,7 +212,7 @@ public class Device { char key = '\0'; if((cond & IOCondition.HUP) == IOCondition.HUP) - error("Lost device"); + error(_("Lost device")); do { int fd = source.unix_get_fd(); @@ -220,7 +221,7 @@ public class Device { /* short read */ if (s != sizeof(Linux.Input.Event)) { if(s > 0) - stdout.printf("short read!\n"); + stdout.printf(_("short read!\n")); return true; } @@ -245,7 +246,7 @@ public class Device { buffer += "%c".printf(key); } while(key != '\n'); - stdout.printf("barcode: %s\n", buffer); + stdout.printf(_("barcode: %s\n"), buffer); if(buffer.has_prefix("USER ") || buffer.has_prefix("STOCK") || buffer.has_prefix("AMOUNT ")) { if(!check_code39_checksum(buffer)) @@ -315,7 +316,7 @@ public class Device { /** * @param duration duration of the blink in 0.1 seconds */ - public void blink(uint duration) { + public void blink(uint duration) throws IOError, DBusError { /* not supported */ } } diff --git a/src/input-device/main.vala b/src/input-device/main.vala index 8578033..487c028 100644 --- a/src/input-device/main.vala +++ b/src/input-device/main.vala @@ -1,4 +1,5 @@ /* Copyright 2015, Sebastian Reichel <sre@ring0.de> + * Copyright 2017-2018, Johannes Rudolph <johannes.rudolph@gmx.com> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -13,35 +14,47 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -Device dev; +Device devScanner; +Device devRfid; public static int main(string[] args) { + Intl.setlocale(LocaleCategory.ALL, ""); + Intl.textdomain("shopsystem"); + try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - dev = new Device(cfg.get_string("INPUT", "device")); + devScanner = new Device(cfg.get_string("INPUT", "barcodescanner")); + devRfid = new Device(cfg.get_string("INPUT", "rfidreader")); } catch(IOError e) { - error("IOError: %s\n", e.message); + error(_("IO Error: %s\n"), e.message); } catch(KeyFileError e) { - error("Config Error: %s\n", e.message); + error(_("Config Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); } Bus.own_name( BusType.SYSTEM, "io.mainframe.shopsystem.InputDevice", BusNameOwnerFlags.NONE, - on_bus_aquired, + on_bus_acquired, () => {}, - () => stderr.printf("Could not aquire name\n")); + () => stderr.printf(_("Could not acquire name\n"))); new MainLoop().run(); return 0; } -void on_bus_aquired(DBusConnection con) { +void on_bus_acquired(DBusConnection con) { + try { + con.register_object("/io/mainframe/shopsystem/device/scanner", devScanner); + } catch(IOError e) { + stderr.printf(_("Could not register service\n")); + } try { - con.register_object("/io/mainframe/shopsystem/device", dev); + con.register_object("/io/mainframe/shopsystem/device/rfid", devRfid); } catch(IOError e) { - stderr.printf("Could not register service\n"); + stderr.printf(_("Could not register service\n")); } } |