aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Healy <lmiphay@gmail.com>2015-11-15 13:55:15 +0000
committerPaul Healy <lmiphay@gmail.com>2015-11-15 13:55:15 +0000
commitacc24ed92d3b02557edf1f055d68502c8a9fae0e (patch)
tree51f67770ae573405894ab49609a4236df19337f9 /app-misc/g13
parentdont hang if the device is not present (diff)
downloadlmiphay-acc24ed92d3b02557edf1f055d68502c8a9fae0e.tar.gz
lmiphay-acc24ed92d3b02557edf1f055d68502c8a9fae0e.tar.bz2
lmiphay-acc24ed92d3b02557edf1f055d68502c8a9fae0e.zip
add experimental logging patch
Diffstat (limited to 'app-misc/g13')
-rw-r--r--app-misc/g13/Manifest3
-rw-r--r--app-misc/g13/files/add-logging.patch529
-rw-r--r--app-misc/g13/g13-9999.ebuild2
3 files changed, 532 insertions, 2 deletions
diff --git a/app-misc/g13/Manifest b/app-misc/g13/Manifest
index 7a2a82e..a1ac698 100644
--- a/app-misc/g13/Manifest
+++ b/app-misc/g13/Manifest
@@ -1,4 +1,5 @@
AUX 99-uinput-g13.rules 48 SHA256 499589608961e50edc99a9d4652a5153091436b487cd4e365fe1e4cc9b25b2e3 SHA512 880c08499031a0ee3ce0868112c689358a800a09489a33eea7c34d433221cc483ac1e6ca7fbbc95531b9f93259da84d6404070f59c9a3752d60971b3cd9e4c16 WHIRLPOOL 0319b513c89b4ddd09a855ebd6e3c0171275c2c66ba19ba56c31f5919628e1949b03132ffd62827e9a8077c0d66aa4d58d5a69bad250b633d068a2d22862c447
+AUX add-logging.patch 17677 SHA256 017122716b55f176fa6cea5df6cd16397b7f9a80b88a3a578b83a1abea20f3da SHA512 3098ccc33ab9dd3019035d7da7f4ad4c80a9a0a229db4981d4d2e4416a1c1f7657c5873ece6f3ce271c5ddbbfe5a32a9417068ec0043a3896ec8a1ba3ec04490 WHIRLPOOL 66327b609361d5d6bc822fec5f65073fde743ce08aae82c504a205f9d17dfbc923aa78c5dee722744c9e6dd727190f78df74a69fe594b8ba0e2bcffb67fdf3cc
AUX add-modifiers.patch 10316 SHA256 e2c4e6e556f1fcc908ef28d57ee3d9f1c4dc2a035b16c6621039fc9a2b664e16 SHA512 12d932bb53c10a2df93a943517ba07cfae98bbf0aeb1a4959d9e08e178894ebeb4a7fb4508a6ed76c5779a07aeda8a1ee6fcbb881f3d72b2a8cfa746b23d435e WHIRLPOOL 2072730fe365b67c68a7d76be982b41d49d92bc71805cab0b03a2b02f4dbb2c5a227c02ca9663e527e91a4b7d08cb6bd4422424c1a00bdbd579e101281a27510
AUX g13.conf.d 462 SHA256 089c36aa414ef9d5eacee759238a1775af0e54f12e8c2c2a8d2e4836f0e276b2 SHA512 801e2ed37243453fecc615099bedd60045dd04f31deaa79fd6ba72bec849e616d0621e52e1db37ce2af429600ca5493e75d7e54366deede9447b1e0ed1924dae WHIRLPOOL 3e227052b2bb3d922f814d6f6440db406b4e859140c7eb38546ef93abeeeceeb7e0917ea2aaba6392e8a83f2ae4b6430781e2c3fd1f057b9a7c9f2f162b5b556
AUX g13.init.d 1033 SHA256 432baa9c6fee5f78edee4e684230763e5d11643111d35defcaeda42aad7337da SHA512 9b690f28f4379efecd13dbcd67666027a659970933486e9be4331c3b3dc8f1ea0d7c69284a7ab83432672236854346052fbb03c21c0a16952ca5183fac551398 WHIRLPOOL 2549b52e1c36183139af941e09dc65a45de166efd929754816b85e24216b45d033043e55a860542d60f4b66e9b4568b80050bd2049a3646234a0443c200cbaa9
@@ -7,4 +8,4 @@ AUX g13mod 319 SHA256 2507f11307858fdec95370c635096b3f4b71bb84b137ec0a51c34b97cb
AUX g13writelcd 270 SHA256 2c379e59ed7030a54a16f29a9fc939c175ce3705f501cdd086061839a584e406 SHA512 330b968d676e5fab9034004d1c659f61f312194267021e0b07b4ed0f5660671a4bec59b21493bcb66c2eb711da188be6609c8fa7c0ff787ccfed8bf3a2b4ae71 WHIRLPOOL 33cbdcf2eb4b5069f953b8c17658d231a41006ea616e1d94b0af8d5c71ae94fd18b28ebc6431afe6e4ab90f0ca86ca8d91cbe96ceb2be1aec2fdf6766fb2e056
AUX keys.txt 1054 SHA256 aaf0a3b118fd79fe6b56433b0881c59d8bd101e4c4d0c2c6128a3364b90bfbdb SHA512 a96d1eaef75f1b93637d25fb5b94b34a14eb9083a596e37b3c147a4ad4d762bf679c1dba44545620e23a56fb7c7dc1bff7122cd2a36813a7a1aa8c51fa6d0e58 WHIRLPOOL cace8bbbb84f89e1145dfcb66ef9cd9185e4e79ae3179a3b95457667f8bc1993808c5f00956504ede497d4e2b2a057c579254b3ce3e23b5ee4ecb6c3848b888c
EBUILD g13-20150528.ebuild 1993 SHA256 885f53daa06d109da026d8331ef81d760ee586b40206d2ffc47fd65455d406d4 SHA512 d8573860f45950df1b7782df93b844ab9495ced2ec5eb20dde52e97223a682378e12752e0d536de730feb0b36b24994d5a488b9041061c0c13f504031c77804d WHIRLPOOL a852579686aea7455b1502db76fa3c234fc4a33d8d321b5853a0b0d2c4f2dd3a4fa8f3d24013592804dfb74a2765b4e063470b97c10b2394fc9f68772c0394ed
-EBUILD g13-9999.ebuild 2050 SHA256 7e70521d7a8d5a82429a0fc965a0fb4f3a4817d69ab5c14eec440a4ad4c9ce27 SHA512 26e54eb8ebfebed02d42a4adc0f2ec95e1dda157ea9827f39c64423fcf418c3532bc7eade28ba18272379c3fd9d1db35e0594625ecbaae39a3d183239e364f6d WHIRLPOOL ad1338fa9f86818435a59e9b4a6b8258f83c86f98496f045671aa94afe3b2a4a5f87f987123047d8434c65093ff9b59132bcfb236d086f5c1d5502a943449a09
+EBUILD g13-9999.ebuild 2029 SHA256 fe958836f8cf22cef6b06ea4ddf977a0d486cb8e41626830ec77c55cdaeb0e8f SHA512 a9df3606cd837612d1ca2fba0c57f75d9a4ea57e643f5139df2eb169c64d12d6b79d18fe69a9c6fbfa96091e570d73635e232a1a38752e3b917facac49c6849a WHIRLPOOL fb586cd68a9e3274219a95f75b94f62333c82b251504b22f6a9892dc2f5843852c9f14b37f7713a90d1d12df54596549a2d1d420f35fe26f04110db385dc30c0
diff --git a/app-misc/g13/files/add-logging.patch b/app-misc/g13/files/add-logging.patch
new file mode 100644
index 0000000..810ea41
--- /dev/null
+++ b/app-misc/g13/files/add-logging.patch
@@ -0,0 +1,529 @@
+diff --git a/Makefile b/Makefile
+index df3aeff..9e46229 100644
+--- a/Makefile
++++ b/Makefile
+@@ -1,19 +1,27 @@
++
++FLAGS=$(CXXFLAGS) -DBOOST_LOG_DYN_LINK -std=c++0x
++LIBS=-lusb-1.0 -lboost_log -lboost_log_setup-mt -lboost_thread -lboost_system-mt -lpthread
++
+ all: g13d pbm2lpbm
+
+-g13d: g13.h g13.cc g13map.o
+- g++ -o g13d -std=c++0x g13.cc g13map.o -lusb-1.0
++g13d: g13.o g13map.o g13logging.o
++ $(CXX) $(FLAGS) -o $@ $^ $(LIBS) $(LDFLAGS)
+
++g13.o: g13.cc g13.h g13logging.h g13map.h logo.h
+ g13map.o: g13map.cc g13map.h
+- g++ -c -o g13map.o -std=c++0x g13map.cc
++g13logging.o: g13logging.cc g13logging.h
++
++%.o: %.cc
++ $(CXX) $(FLAGS) -c $(FLAGS) -o $@ $<
+
+ pbm2lpbm: pbm2lpbm.c
+- g++ -o pbm2lpbm pbm2lpbm.c
++ $(CXX) $(FLAGS) -o pbm2lpbm pbm2lpbm.c $(LDFLAGS)
+
+ package:
+ rm -Rf g13-userspace
+ mkdir g13-userspace
+- cp g13.cc g13.h logo.h Makefile pbm2lpbm.c g13-userspace
++ cp *.cc *.h Makefile g13-userspace
+ tar cjf g13-userspace.tbz2 g13-userspace
+ rm -Rf g13-userspace
+-clean:
+- rm -f g13d g13map.o pbm2lpbm
++clean:
++ rm -f g13d *.o pbm2lpbm
+diff --git a/g13.cc b/g13.cc
+index 9a0e057..d2135f5 100644
+--- a/g13.cc
++++ b/g13.cc
+@@ -1,9 +1,12 @@
+ #include <libusb-1.0/libusb.h>
+ #include <iostream>
+ #include <vector>
++#include <cerrno>
++#include <memory>
+ #include <boost/lexical_cast.hpp>
+ #include <boost/foreach.hpp>
+ #include <boost/algorithm/string.hpp>
++#include <boost/log/trivial.hpp>
+ #include <iomanip>
+ #include <sys/stat.h>
+ #include "logo.h"
+@@ -16,6 +19,7 @@
+ #include <linux/uinput.h>
+ #include <fcntl.h>
+ #include "g13.h"
++#include "g13logging.h"
+
+ using namespace std;
+
+@@ -74,7 +78,7 @@ void g13_set_mode_leds(libusb_device_handle *handle, int leds) {
+ usb_data[1] = leds;
+ int r = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, 9, 0x305, 0, usb_data, 5, 1000);
+ if(r != 5) {
+- cerr << "Problem sending data" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Problem sending leds data";
+ return;
+ }
+ }
+@@ -87,7 +91,7 @@ void g13_set_key_color(libusb_device_handle *handle, int red, int green, int blu
+
+ error = libusb_control_transfer(handle, LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_INTERFACE, 9, 0x307, 0, usb_data, 5, 1000);
+ if(error != 5) {
+- cerr << "Problem sending data" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Problem sending color data";
+ return;
+ }
+ }
+@@ -100,8 +104,18 @@ void send_event(int file, int type, int code, int val) {
+ event.type = type;
+ event.code = code;
+ event.value = val;
+- write(file, &event, sizeof(event));
++
++ const int result = write(file, &event, sizeof(event));
++
++ if (result != sizeof(event)) {
++ if (result == -1) {
++ BOOST_LOG_TRIVIAL(error) << "Problem writing uinput event: result=" << result << ", error=" << strerror(errno);
++ } else {
++ BOOST_LOG_TRIVIAL(error) << "Problem writing uinput event: result=" << result;
++ }
++ }
+ }
++
+ void g13_parse_joystick(unsigned char *buf, g13_keypad *g13) {
+ int stick_x = buf[1];
+ int stick_y = buf[2];
+@@ -146,7 +160,7 @@ void g13_parse_key(int key, unsigned char *byte, g13_keypad *g13) {
+ const std::list<int>& keys = g13->keymap->mapping(key);
+
+ for (std::list<int>::const_iterator it = keys.begin(); it!= keys.end(); it++) {
+- // std::cout << *it << ": " << g13->is_set(key) << std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "parsekey:" << *it << ": " << g13->is_set(key);
+ send_event(g13->uinput_file, EV_KEY, *it, g13->is_set(key));
+ }
+
+@@ -204,7 +218,7 @@ void g13_parse_keys(unsigned char *buf, g13_keypad *g13) {
+ void g13_init_lcd(libusb_device_handle *handle) {
+ int error = libusb_control_transfer(handle, 0, 9, 1, 0, null, 0, 1000);
+ if(error) {
+- cerr << "Error when initialising lcd endpoint" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error when initialising lcd endpoint";
+ }
+ }
+ void g13_deregister(g13_keypad *g13) {
+@@ -217,22 +231,22 @@ void discover_g13s(libusb_device **devs, ssize_t count, vector<g13_keypad*>& g13
+ libusb_device_descriptor desc;
+ int r = libusb_get_device_descriptor(devs[i], &desc);
+ if(r < 0) {
+- cout << "Failed to get device descriptor" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Failed to get device descriptor";
+ return;
+ }
+ if(desc.idVendor == G13_VENDOR_ID && desc.idProduct == G13_PRODUCT_ID) {
+ libusb_device_handle *handle;
+ int r = libusb_open(devs[i], &handle);
+ if(r != 0) {
+- cerr << "Error opening G13 device" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error opening G13 device";
+ return;
+ }
+ if(libusb_kernel_driver_active(handle, 0) == 1)
+ if(libusb_detach_kernel_driver(handle, 0) == 0)
+- cout << "Kernel driver detached" << endl;
++ BOOST_LOG_TRIVIAL(info) << "Kernel driver detached";
+ r = libusb_claim_interface(handle, 0);
+ if(r < 0) {
+- cerr << "Cannot Claim Interface" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Cannot Claim Interface";
+ return;
+ }
+ g13s.push_back(new g13_keypad(handle, g13_count++));
+@@ -245,7 +259,7 @@ void discover_g13s(libusb_device **devs, ssize_t count, vector<g13_keypad*>& g13
+ void g13_write_lcd(libusb_context *ctx, libusb_device_handle *handle, unsigned char *data, size_t size) {
+ g13_init_lcd(handle);
+ if(size != G13_LCD_BUFFER_SIZE) {
+- cerr << "Invalid LCD data size " << size << ", should be " << G13_LCD_BUFFER_SIZE;
++ BOOST_LOG_TRIVIAL(error) << "Invalid LCD data size " << size << ", should be " << G13_LCD_BUFFER_SIZE;
+ return;
+ }
+ unsigned char buffer[G13_LCD_BUFFER_SIZE + 32];
+@@ -255,7 +269,7 @@ void g13_write_lcd(libusb_context *ctx, libusb_device_handle *handle, unsigned c
+ int bytes_written;
+ int error = libusb_interrupt_transfer(handle, LIBUSB_ENDPOINT_OUT | G13_LCD_ENDPOINT, buffer, G13_LCD_BUFFER_SIZE + 32, &bytes_written, 1000);
+ if(error)
+- cerr << "Error when transfering image: " << error << ", " << bytes_written << " bytes written" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error when transfering image: " << error << ", " << bytes_written << " bytes written";
+ }
+ int g13_create_fifo(g13_keypad *g13) {
+ mkfifo(g13->fifo_name(), 0666);
+@@ -268,16 +282,16 @@ int g13_create_uinput(g13_keypad *g13) {
+ : access("/dev/uinput", F_OK)==0 ? "/dev/uinput"
+ : 0;
+ if(!dev_uinput_fname) {
+- cerr << "Could not find an uinput device" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Could not find an uinput device";
+ return -1;
+ }
+ if(access(dev_uinput_fname, W_OK) != 0) {
+- cerr << dev_uinput_fname << " doesn't grant write permissions" << endl;
++ BOOST_LOG_TRIVIAL(error) << dev_uinput_fname << " doesn't grant write permissions";
+ return -1;
+ }
+ int ufile = open(dev_uinput_fname, O_WRONLY | O_NDELAY);
+ if(ufile <= 0) {
+- cerr << "Could not open uinput" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Could not open uinput";
+ return -1;
+ }
+ memset(&uinp, 0, sizeof(uinp));
+@@ -310,12 +324,12 @@ int g13_create_uinput(g13_keypad *g13) {
+
+ int retcode = write(ufile, &uinp, sizeof(uinp));
+ if(retcode < 0) {
+- cerr << "Could not write to uinput device (" << retcode << ")" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Could not write to uinput device (" << retcode << ")";
+ return -1;
+ }
+ retcode = ioctl(ufile, UI_DEV_CREATE);
+ if(retcode) {
+- cerr << "Error creating uinput device for G13" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error creating uinput device for G13";
+ return -1;
+ }
+ return ufile;
+@@ -372,7 +386,7 @@ int g13_read_keys(g13_keypad *g13) {
+ errors[LIBUSB_ERROR_NO_MEM] = "LIBUSB_ERROR_NO_MEM";
+ errors[LIBUSB_ERROR_NOT_SUPPORTED] = "LIBUSB_ERROR_NOT_SUPPORTED";
+ errors[LIBUSB_ERROR_OTHER ] = "LIBUSB_ERROR_OTHER ";
+- cerr << "Error while reading keys: " << error << " (" << errors[error] << ")" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error while reading keys: " << error << " (" << errors[error] << ")";
+ // cerr << "Stopping daemon" << endl;
+ // return -1;
+ }
+@@ -395,8 +409,8 @@ void g13_destroy_uinput(g13_keypad *g13) {
+ libusb_context *ctx = null;
+ vector<g13_keypad*> g13s;
+
+-void cleanup(int n = 0) {
+- // cout << "cleaning up" << endl;
++void cleanup() {
++ BOOST_LOG_TRIVIAL(info) << "cleanup called";
+ for(int i = 0; i < g13s.size(); i++) {
+ g13_destroy_uinput(g13s[i]);
+ g13_destroy_fifo(g13s[i]);
+@@ -422,20 +436,20 @@ void g13_read_commands(g13_keypad *g13) {
+ unsigned char buf[1024*1024];
+ memset(buf, 0, 1024*1024);
+ ret = read(g13->fifo, buf, 1024*1024);
+- // std::cout << "INFO: read " << ret << " characters" << std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "INFO: read " << ret << " characters";
+ if(ret == 960) { // TODO probably image, for now, don't test, just assume image
+ g13->image(buf, ret);
+ } else {
+ std::string buffer = reinterpret_cast<const char*>(buf);
+ std::vector<std::string> lines;
+ boost::split(lines, buffer, boost::is_any_of("\n\r"));
+- // std::cout << "INFO: lines: " << lines.size() << std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "INFO: lines: " << lines.size();
+ BOOST_FOREACH(std::string const &cmd, lines) {
+ std::vector<std::string> command;
+ boost::split(command, cmd, boost::is_any_of("#"));
+- // std::cout << "INFO: command [" << command.size() << "]: " << command[0] << " (" << command[0].size() << ")" << std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "INFO: command [" << command.size() << "]: " << command[0] << " (" << command[0].size() << ")";
+ if(command.size() > 0 && command[0] != std::string("")) {
+- cout << "command: " << command[0] << endl;
++ BOOST_LOG_TRIVIAL(info) << "command: " << command[0];
+ g13->command(command[0].c_str());
+ }
+ }
+@@ -585,65 +599,74 @@ void init_keynames() {
+ }
+ void display_keys() {
+ typedef std::map<std::string,int> mapType;
+- std::cout << "Known keys on G13:" << std::endl;
++ BOOST_LOG_TRIVIAL(info) << "Known keys on G13:";
+ BOOST_FOREACH(const mapType::value_type &item, name_to_key) {
+- std::cout << item.first << " ";
++ BOOST_LOG_TRIVIAL(info) << " " << item.first;
+ }
+- std::cout << "STICK_LEFT " << "STICK_RIGHT " << "STICK_UP " << "STICK_DOWN ";
+- std::cout << std::endl;
+- std::cout << "Known keys to map to:" << std::endl;
++
++ BOOST_LOG_TRIVIAL(info) << "STICK_LEFT " << "STICK_RIGHT " << "STICK_UP " << "STICK_DOWN";
++
++ BOOST_LOG_TRIVIAL(info) << "Known keys to map to:";
+ BOOST_FOREACH(const mapType::value_type &item, input_name_to_key) {
+- std::cout << item.first << " ";
++ BOOST_LOG_TRIVIAL(info) << " " << item.first;
+ }
+- std::cout << std::endl;
+-
+ }
++
+ int main(int argc, char *argv[]) {
++ std::unique_ptr<g13logging> logger(new g13logging(argc, argv));
++
+ init_keynames();
+ display_keys();
+ g13_count = 0;
+ string filename;
+- if(argc == 2) {
++ if(argc >= 2) {
+ filename = argv[1];
+- cout << "Setting logo: " << filename << endl;
++ BOOST_LOG_TRIVIAL(info) << "Setting logo: " << filename;
+ }
+ libusb_device **devs;
+ ssize_t cnt;
+ int ret;
+ ret = libusb_init(&ctx);
+ if(ret < 0) {
+- cout << "Initialization error: " << ret << endl;
++ BOOST_LOG_TRIVIAL(error) << "Initialization error: " << ret;
+ return 1;
+ }
+ libusb_set_debug(ctx, 3);
+ cnt = libusb_get_device_list(ctx, &devs);
+ if(cnt < 0) {
+- cout << "Error while getting device list" << endl;
++ BOOST_LOG_TRIVIAL(error) << "Error while getting device list";
+ return 1;
+ }
+ discover_g13s(devs, cnt, g13s);
+ libusb_free_device_list(devs, 1);
+- cout << "Found " << g13s.size() << " G13s" << endl;
++ BOOST_LOG_TRIVIAL(info) << "Found " << g13s.size() << " G13s";
+ if(g13s.size() == 0) {
++ BOOST_LOG_TRIVIAL(error) << "No G13 found - exiting";
+ return 1;
+ }
+ for(int i = 0; i < g13s.size(); i++) {
+ register_g13(ctx, g13s[i]);
+ }
+ signal(SIGINT, set_stop);
+- if(g13s.size() > 0 && argc == 2) {
++ if(g13s.size() > 0 && argc >= 2) {
+ g13_write_lcd_file(ctx, g13s[0], filename);
+ }
++
++ BOOST_LOG_TRIVIAL(info) << "Entering event loop";
+ do {
+- if(g13s.size() > 0)
+- for(int i = 0; i < g13s.size(); i++) {
+- int status = g13_read_keys(g13s[i]);
+- g13_read_commands(g13s[i]);
+- if(status < 0)
+- running = false;
+- }
++ for(int i = 0; i < g13s.size(); i++) {
++ int status = g13_read_keys(g13s[i]);
++ g13_read_commands(g13s[i]);
++ if(status < 0)
++ running = false;
++ }
+ } while(running);
++
++ BOOST_LOG_TRIVIAL(info) << "Cleaning up";
+ cleanup();
++
++ BOOST_LOG_TRIVIAL(info) << "Exiting";
++ return 0;
+ }
+
+ void g13_keypad::image(unsigned char *data, int size) {
+@@ -691,13 +714,13 @@ void g13_keypad::command(char const *str) {
+ } else if(key_name == "STICK_DOWN") {
+ this->stick_keys[STICK_DOWN] = bind;
+ } else {
+- cerr << "unknown g13 key: " << keyname << endl;
++ BOOST_LOG_TRIVIAL(error) << "unknown g13 key: " << keyname;
+ }
+ } else {
+- cerr << "unknown key: " << binding << endl;
++ BOOST_LOG_TRIVIAL(error) << "unknown key: " << binding;
+ }
+
+ } else {
+- cerr << "unknown command: <" << str << ">" << endl;
++ BOOST_LOG_TRIVIAL(error) << "unknown command: <" << str << ">";
+ }
+ }
+diff --git a/g13logging.cc b/g13logging.cc
+new file mode 100644
+index 0000000..5f7607e
+--- /dev/null
++++ b/g13logging.cc
+@@ -0,0 +1,77 @@
++#include <fstream>
++#include <boost/log/attributes.hpp>
++#include <boost/log/trivial.hpp>
++#include <boost/log/expressions.hpp>
++#include <boost/log/utility/setup.hpp>
++#include <boost/log/utility/setup/console.hpp>
++#include <boost/log/expressions/formatters/stream.hpp>
++#include <boost/log/support/date_time.hpp>
++#include "g13logging.h"
++
++namespace expr = boost::log::expressions;
++
++static const char* param = "--log-settings=";
++
++g13logging::g13logging(int argc, char* argv[])
++{
++ init(argc, argv);
++}
++
++g13logging::~g13logging()
++{
++ BOOST_LOG_TRIVIAL(debug) << "g13logging dtor";
++}
++
++void
++g13logging::init()
++{
++ boost::log::add_console_log(
++ std::clog,
++ boost::log::keywords::filter = boost::log::trivial::severity > boost::log::trivial::debug,
++ boost::log::keywords::format = (
++ expr::stream << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << ": "
++ << boost::log::trivial::severity << ", " << expr::smessage
++ )
++ );
++
++ register_attributes();
++}
++
++void
++g13logging::init(const std::string& filename)
++{
++ std::ifstream s(filename.c_str());
++
++ boost::log::init_from_stream(s);
++
++ register_attributes();
++}
++
++void
++g13logging::register_attributes()
++{
++ boost::log::add_common_attributes(); // add LineID and TimeStamp
++ boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
++}
++
++int
++g13logging::init(int argc, char* argv[])
++{
++ for (int i=1; i<argc; i++) {
++ if (std::strncmp(argv[i], param, strlen(param)) == 0) {
++ const std::string filename(argv[i]+strlen(param));
++
++ init(filename);
++
++ BOOST_LOG_TRIVIAL(info) << "Logging initialised from " << filename;
++
++ return 0;
++ }
++ }
++
++ init();
++
++ BOOST_LOG_TRIVIAL(info) << "Logging initialised (default configuration)";
++
++ return 0;
++}
+diff --git a/g13logging.h b/g13logging.h
+new file mode 100644
+index 0000000..6cd8d16
+--- /dev/null
++++ b/g13logging.h
+@@ -0,0 +1,29 @@
++#ifndef _g13logging_
++#define _g13logging_ 1
++
++class g13logging {
++public:
++
++ // ctor
++ g13logging(int argc, char* argv[]);
++
++ // dtor
++ virtual ~g13logging();
++
++protected:
++
++ // setup up either default logging or from config file
++ virtual int init(int argc, char* argv[]);
++ virtual void init();
++ virtual void init(const std::string& filename);
++
++ virtual void register_attributes();
++
++private:
++
++ // disabled
++ g13logging();
++
++};
++
++#endif // _g13logging_
+diff --git a/g13map.cc b/g13map.cc
+index 9b43526..f88a3ca 100644
+--- a/g13map.cc
++++ b/g13map.cc
+@@ -1,5 +1,6 @@
+ #include <iostream>
+ #include <boost/algorithm/string.hpp>
++#include <boost/log/trivial.hpp>
+ #include <cassert>
+ #include <linux/uinput.h>
+ #include "g13map.h"
+@@ -8,13 +9,13 @@ g13map::g13map(const int g13_num_keys) :
+ m_bind(g13_num_keys),
+ m_keya(1)
+ {
+- std::cout << "g13map ctor"<< std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "g13map ctor";
+ m_keya.push_back(KEY_A); // from <linux/uinput.h>
+ }
+
+ g13map::~g13map()
+ {
+- std::cout << "g13map dtor"<< std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "g13map dtor";
+ }
+
+ bool
+@@ -31,14 +32,14 @@ g13map::bind(const int g13key, const char* cmd,
+ boost::split(tok, cmd, boost::is_any_of(" "));
+
+ for (int i=2; i<tok.size(); i++) {
+- std::cout << "g13map::bind " << i << " <" << tok[i] << ">" << std::endl;
++ BOOST_LOG_TRIVIAL(debug) << "g13map::bind " << i << " <" << tok[i] << ">";
+
+ if (tok[i].size() < 1 || tok[i][0] == '#')
+ break;
+ else if (lut.count(tok[i])==1)
+ m_bind[g13key].push_back(lut.at(tok[i]));
+ else {
+- std::cerr << "Keyboard key not found for: " << tok[i] << std::endl;
++ BOOST_LOG_TRIVIAL(error) << "Keyboard key not found for: " << tok[i];
+ return false;
+ }
+ }
+@@ -57,7 +58,7 @@ g13map::mapping(const int g13key) const
+ return m_bind[g13key];
+
+ else {
+- std::cerr << "Bad G13 key: " << g13key << std::endl;
++ BOOST_LOG_TRIVIAL(error) << "Bad G13 key: " << g13key;
+ return m_keya;
+ }
+ }
diff --git a/app-misc/g13/g13-9999.ebuild b/app-misc/g13/g13-9999.ebuild
index 99171e7..86b12f7 100644
--- a/app-misc/g13/g13-9999.ebuild
+++ b/app-misc/g13/g13-9999.ebuild
@@ -38,8 +38,8 @@ pkg_setup() {
src_prepare () {
epatch "${FILESDIR}/add-modifiers.patch"
+ epatch "${FILESDIR}/add-logging.patch"
sed -i -e 's:/tmp/:/run/:' "g13.h"
- sed -i -e 's:g++:$(CXX) $(CXXFLAGS) $(LDFLAGS):' "Makefile"
sed -i '/MODE/G' "91-g13.rules"
epatch_user
}