summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile4
-rw-r--r--rcm-server-keymap.c121
-rw-r--r--rcm-server-keymap.h22
-rw-r--r--rcm-server.c170
-rw-r--r--rcm-server.h24
-rw-r--r--utils.h6
7 files changed, 178 insertions, 170 deletions
diff --git a/.gitignore b/.gitignore
index 1f9d16a..4ec5c0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.o
rcm-server
+*.swp
diff --git a/Makefile b/Makefile
index c514d8d..9b601f3 100644
--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,8 @@ INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
RCM_COMPILE = $(CC) $(RCM_CFLAGS)
RCM_LINK = $(CC) $(RCM_CFLAGS) $(RCM_LDFLAGS)
-RCM_SERVER_OBJ = rcm-server.o
-RCM_SERVER_HDR = utils.h
+RCM_SERVER_OBJ = rcm-server.o rcm-server-keymap.o
+RCM_SERVER_HDR = rcm-server.h rcm-server-keymap.h utils.h
DESTDIR ?=
prefix = /usr
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
new file mode 100644
index 0000000..a5c194e
--- /dev/null
+++ b/rcm-server-keymap.c
@@ -0,0 +1,121 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <unistd.h>
+
+#include "utils.h"
+#include "rcm-server.h"
+#include "rcm-server-keymap.h"
+
+struct keymap *
+find_keymap_by_name(struct device *dev, const char *name)
+{
+ struct keymap *keymap;
+
+ list_for_each_entry(keymap, &dev->keymaps, list)
+ if (!strcmp(keymap->name, name))
+ return keymap;
+
+ return NULL;
+}
+
+static struct keymap *
+keymap_read(int dfd, const char *name)
+{
+ int fd;
+ struct keymap *keymap;
+ unsigned i;
+
+ if (dfd < 0 || !name)
+ return NULL;
+
+ fd = openat(dfd, name, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ keymap = zmalloc(sizeof(*keymap) + (8 * 3) * sizeof(struct keycode));
+ if (!keymap) {
+ close(fd);
+ return NULL;
+ }
+
+ keymap->name = strdup(name);
+ if (!keymap->name) {
+ close(fd);
+ free(keymap);
+ return NULL;
+ }
+
+ keymap->cols = 3;
+ keymap->rows = 8;
+
+ for (i = 0; i < (keymap->cols * keymap->rows); i++) {
+ keymap->keycodes[i].name = "key-1-2";
+ keymap->keycodes[i].value = "KEY_COFFEE";
+ }
+ /* FIXME: Actually read the keymap :) */
+
+ close(fd);
+ return keymap;
+}
+
+static int
+keymaps_load_dir(struct device *device, const char *path)
+{
+ DIR *dir;
+ int dfd;
+ struct dirent *dent;
+ struct keymap *keymap;
+
+ dir = opendir(path);
+ if (!dir)
+ return -1;
+
+ dfd = dirfd(dir);
+ if (dfd < 0) {
+ closedir(dir);
+ return -1;
+ }
+
+ while ((dent = readdir(dir))) {
+ switch (dent->d_type) {
+ case DT_REG:
+ case DT_LNK:
+ case DT_UNKNOWN:
+ keymap = keymap_read(dfd, dent->d_name);
+ if (keymap)
+ list_add(&keymap->list, &device->keymaps);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (closedir(dir) < 0)
+ return -1;
+
+ return 0;
+}
+
+int
+keymaps_load(struct device *device)
+{
+ char pdpath[strlen("./keymaps/per-device/") + strlen(device->name) + 1];
+
+ sprintf(pdpath, "./keymaps/per-device/%s", device->name);
+
+ printf("Loading per-device keymaps...\n");
+ keymaps_load_dir(device, pdpath);
+ printf("Loading default keymaps...\n");
+ keymaps_load_dir(device, "./keymaps/default");
+
+ return 0;
+}
+
diff --git a/rcm-server-keymap.h b/rcm-server-keymap.h
new file mode 100644
index 0000000..f29c0af
--- /dev/null
+++ b/rcm-server-keymap.h
@@ -0,0 +1,22 @@
+#ifndef foorcmserverkeymaphfoo
+#define foorcmserverkeymaphfoo
+
+struct keycode {
+ char *name;
+ char *value;
+};
+
+struct keymap {
+ char *name;
+ uint16_t rows;
+ uint16_t cols;
+ struct list_head list;
+ struct keycode keycodes[];
+};
+
+struct keymap *find_keymap_by_name(struct device *dev, const char *name);
+
+int keymaps_load(struct device *device);
+
+#endif
+
diff --git a/rcm-server.c b/rcm-server.c
index fb5eba9..26620fc 100644
--- a/rcm-server.c
+++ b/rcm-server.c
@@ -7,44 +7,10 @@
#include <string.h>
#include <systemd/sd-bus.h>
#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
#include "utils.h"
-
-struct keycode {
- char *name;
- char *value;
-};
-
-struct keymap {
- char *name;
- uint16_t rows;
- uint16_t cols;
- struct list_head list;
- struct keycode keycodes[];
-};
-
-struct device {
- char *name;
- char *path;
- char *driver_name;
- char *keymap_name;
- struct list_head list;
- struct list_head keymaps;
-};
-
-struct manager {
- sd_bus *bus;
- sd_event *event;
- struct udev *udev;
- struct udev_monitor *udev_mon;
- sd_event_source *udev_ev;
- struct list_head devices;
- unsigned num_devices;
-};
+#include "rcm-server.h"
+#include "rcm-server-keymap.h"
static int
method_echostring(sd_bus_message *m, void *userdata, sd_bus_error *error)
@@ -141,18 +107,6 @@ out:
return sd_bus_error_set_errno(error, r);
}
-static struct keymap *
-find_keymap_by_name(struct device *dev, const char *name)
-{
- struct keymap *keymap;
-
- list_for_each_entry(keymap, &dev->keymaps, list)
- if (!strcmp(keymap->name, name))
- return keymap;
-
- return NULL;
-}
-
static int
method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
@@ -295,99 +249,6 @@ remove_device(struct manager *mgr, struct udev_device *udev)
}
}
-static struct keymap *
-keymap_read(int dfd, const char *name)
-{
- int fd;
- struct keymap *keymap;
- unsigned i;
-
- if (dfd < 0 || !name)
- return NULL;
-
- fd = openat(dfd, name, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- keymap = zmalloc(sizeof(*keymap) + (8 * 3) * sizeof(struct keycode));
- if (!keymap) {
- close(fd);
- return NULL;
- }
-
- keymap->name = strdup(name);
- if (!keymap->name) {
- close(fd);
- free(keymap);
- return NULL;
- }
-
- keymap->cols = 3;
- keymap->rows = 8;
-
- for (i = 0; i < (keymap->cols * keymap->rows); i++) {
- keymap->keycodes[i].name = "key-1-2";
- keymap->keycodes[i].value = "KEY_COFFEE";
- }
- /* FIXME: Actually read the keymap :) */
-
- close(fd);
- return keymap;
-}
-
-static int
-keymaps_load_dir(struct device *device, const char *path)
-{
- DIR *dir;
- int dfd;
- struct dirent *dent;
- struct keymap *keymap;
-
- dir = opendir(path);
- if (!dir)
- return -1;
-
- dfd = dirfd(dir);
- if (dfd < 0) {
- closedir(dir);
- return -1;
- }
-
- while ((dent = readdir(dir))) {
- switch (dent->d_type) {
- case DT_REG:
- case DT_LNK:
- case DT_UNKNOWN:
- keymap = keymap_read(dfd, dent->d_name);
- if (keymap)
- list_add(&keymap->list, &device->keymaps);
- break;
- default:
- break;
- }
- }
-
- if (closedir(dir) < 0)
- return -1;
-
- return 0;
-}
-
-static int
-keymaps_load(struct device *device)
-{
- char pdpath[strlen("./keymaps/per-device/") + strlen(device->name) + 1];
-
- sprintf(pdpath, "./keymaps/per-device/%s", device->name);
-
- printf("Loading per-device keymaps...\n");
- keymaps_load_dir(device, pdpath);
- printf("Loading default keymaps...\n");
- keymaps_load_dir(device, "./keymaps/default");
-
- return 0;
-}
-
static void
add_device(struct manager *mgr, struct udev_device *udev)
{
@@ -700,30 +561,3 @@ finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
-#if 0
-static gboolean
-on_irrx(RCIRDevice *object,
- GDBusMethodInvocation *invocation,
- gpointer user_data)
-{
- GVariantBuilder builder;
- GVariant *ret;
-
- printf("In on_irrx\n");
- g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
- g_variant_builder_add(&builder, "{sv}", "name",
- g_variant_new_string("apan"));
- g_variant_builder_add(&builder, "{sv}", "foo",
- g_variant_new_string("bar"));
-
- ret = g_variant_builder_end (&builder);
-
- rcirdevice_complete_get_irrxparameters(object,
- invocation,
- ret);
-
- return true;
-}
-
-#endif
-
diff --git a/rcm-server.h b/rcm-server.h
new file mode 100644
index 0000000..188ffab
--- /dev/null
+++ b/rcm-server.h
@@ -0,0 +1,24 @@
+#ifndef foorcmserverhfoo
+#define foorcmserverhfoo
+
+struct device {
+ char *name;
+ char *path;
+ char *driver_name;
+ char *keymap_name;
+ struct list_head list;
+ struct list_head keymaps;
+};
+
+struct manager {
+ sd_bus *bus;
+ sd_event *event;
+ struct udev *udev;
+ struct udev_monitor *udev_mon;
+ sd_event_source *udev_ev;
+ struct list_head devices;
+ unsigned num_devices;
+};
+
+#endif
+
diff --git a/utils.h b/utils.h
index 548d444..33cff05 100644
--- a/utils.h
+++ b/utils.h
@@ -1,3 +1,7 @@
+#ifndef fooutilshfoo
+#define fooutilshfoo
+
+#include <systemd/sd-bus.h>
struct list_head {
struct list_head *next;
@@ -102,3 +106,5 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message *, sd_bus_message_unref);
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_event_source *, sd_event_source_unref);
#define _cleanup_event_source_unref_ _cleanup_(sd_event_source_unrefp)
+#endif
+