summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rcm-server-evdev.c94
-rw-r--r--rcm-server-evdev.h8
-rw-r--r--rcm-server-keymap.c20
-rw-r--r--rcm-server-keymap.h4
-rw-r--r--rcm-server-lirc.c34
-rw-r--r--rcm-server-lirc.h4
-rw-r--r--rcm-server-main.c97
-rw-r--r--rcm-server-main.h6
-rw-r--r--rcm-server-udev.c137
-rw-r--r--rcm-server-udev.h2
10 files changed, 203 insertions, 203 deletions
diff --git a/rcm-server-evdev.c b/rcm-server-evdev.c
index e39ef3d..a49e3aa 100644
--- a/rcm-server-evdev.c
+++ b/rcm-server-evdev.c
@@ -47,12 +47,15 @@ evdev_get_protocol_name(__u16 protocol)
}
static const char *
-evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode)
+evdev_guess_protocol(struct rc_device *rcdev, uint64_t scancode, uint32_t keycode)
{
struct rc_keymap_entry rke;
unsigned i;
- if (!device || device->evdev_fd < 0)
+ if (!rcdev)
+ return NULL;
+
+ if (rcdev->evdev_fd < 0)
return NULL;
for (i = 0; ; i++) {
@@ -60,7 +63,7 @@ evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode)
rke.len = RKE_SIZE;
rke.index = i;
rke.flags = INPUT_KEYMAP_BY_INDEX;
- if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke))
+ if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke))
break;
if (rke.rc.scancode != scancode)
@@ -76,7 +79,7 @@ evdev_guess_protocol(struct device *device, uint64_t scancode, uint32_t keycode)
}
int
-evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol,
+evdev_get_mapping(struct rc_device *rcdev, unsigned index, unsigned *ret_protocol,
uint64_t *ret_scancode, struct linux_input_keycode **ret_lik)
{
struct rc_keymap_entry rke;
@@ -87,7 +90,7 @@ evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol,
rke.index = index;
rke.flags = INPUT_KEYMAP_BY_INDEX;
- if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke))
+ if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke))
return 0;
lik = get_linux_keycode_by_value(rke.keycode);
@@ -103,7 +106,7 @@ evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol,
}
int
-evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode,
+evdev_set_mapping(struct rc_device *rcdev, unsigned protocol, uint64_t scancode,
struct linux_input_keycode *lik)
{
struct rc_keymap_entry rke;
@@ -119,7 +122,7 @@ evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode,
else
rke.keycode = KEY_RESERVED;
- if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
+ if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
r = -errno;
printf("EVIOCSKEYCODE_V2 failed (%s)\n", strerror(errno));
}
@@ -128,7 +131,7 @@ evdev_set_mapping(struct device *device, unsigned protocol, uint64_t scancode,
}
static int
-evdev_clear_keymap(struct device *device)
+evdev_clear_keymap(struct rc_device *rcdev)
{
struct rc_keymap_entry rke;
unsigned count = 0;
@@ -140,7 +143,7 @@ evdev_clear_keymap(struct device *device)
rke.len = RKE_SIZE;
rke.index = 0;
rke.flags = INPUT_KEYMAP_BY_INDEX;
- if (ioctl(device->evdev_fd, EVIOCGKEYCODE_V2, &rke)) {
+ if (ioctl(rcdev->evdev_fd, EVIOCGKEYCODE_V2, &rke)) {
printf("done (%u entries removed)\n", count);
break;
}
@@ -151,7 +154,7 @@ evdev_clear_keymap(struct device *device)
*/
rke.keycode = KEY_RESERVED;
- if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
+ if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
r = -errno;
printf("failed (%s)\n", strerror(errno));
break;
@@ -163,7 +166,7 @@ evdev_clear_keymap(struct device *device)
}
static void
-set_keycode_new(struct device *device, __u16 protocol, __u64 scancode, __u32 keycode)
+set_keycode_new(struct rc_device *rcdev, __u16 protocol, __u64 scancode, __u32 keycode)
{
struct rc_keymap_entry rke;
@@ -176,21 +179,21 @@ set_keycode_new(struct device *device, __u16 protocol, __u64 scancode, __u32 key
printf("Setting keycode (new ioctl) 0x%08llX (0x%02X) to 0x%02X\n",
rke.rc.scancode, rke.rc.protocol, rke.keycode);
- if (ioctl(device->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
+ if (ioctl(rcdev->evdev_fd, EVIOCSKEYCODE_V2, &rke)) {
printf("Unable to call SETKEYCODE2 ioctl\n");
exit(EXIT_FAILURE);
}
}
static int
-evdev_set_keymap(struct device *device, struct keymap *keymap)
+evdev_set_keymap(struct rc_device *rcdev, struct keymap *keymap)
{
unsigned i;
printf("\tSetting up keymap: %s\n", keymap->name);
for (i = 0; i < keymap->keycode_count; i++)
- set_keycode_new(device,
+ set_keycode_new(rcdev,
keymap->keycodes[i].protocol,
keymap->keycodes[i].scancode,
keymap->keycodes[i].lik->value);
@@ -202,7 +205,7 @@ evdev_set_keymap(struct device *device, struct keymap *keymap)
static int
evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
- struct device *device = userdata;
+ struct rc_device *rcdev = userdata;
struct input_event ev;
static struct linux_input_keycode *keycode = NULL;
static bool pressed = false;
@@ -212,13 +215,12 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
static bool protocol_recv = false;
int r;
- if (fd != device->evdev_fd)
- fprintf(stderr, "evdev fd mismatch: %i != %i\n", device->evdev_fd, fd);
+ if (fd != rcdev->evdev_fd)
+ fprintf(stderr, "evdev fd mismatch: %i != %i\n", rcdev->evdev_fd, fd);
if (revents & EPOLLHUP) {
fprintf(stderr, "evdev connection closed!\n");
- close(fd);
- device->evdev_fd = -1;
+ evdev_close(rcdev);
return 0;
}
@@ -230,7 +232,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
do {
char buf[100];
- r = libevdev_next_event(device->evdev_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
+ r = libevdev_next_event(rcdev->evdev_dev, LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (r != LIBEVDEV_READ_STATUS_SUCCESS)
continue;
@@ -239,8 +241,8 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
libevdev_event_code_get_name(ev.type, ev.code),
ev.value, ev.value);
- sd_bus_emit_signal(device->mgr->bus,
- device->path,
+ sd_bus_emit_signal(rcdev->mgr->bus,
+ rcdev->path,
"org.gnome.RemoteControlManager.Device",
"Event",
"s", buf);
@@ -286,7 +288,7 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
/* FIXME: protocol reporting will change */
if (scancode_recv) {
if (!protocol_recv) {
- protocol_name = evdev_guess_protocol(device, scancode, keycode ? keycode->value : KEY_RESERVED);
+ protocol_name = evdev_guess_protocol(rcdev, scancode, keycode ? keycode->value : KEY_RESERVED);
printf(" protocol %s (guessed)", protocol_name);
} else {
protocol_name = evdev_get_protocol_name(protocol);
@@ -304,16 +306,16 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
printf("\n");
if (scancode_recv && protocol_name)
- sd_bus_emit_signal(device->mgr->bus,
- device->path,
+ sd_bus_emit_signal(rcdev->mgr->bus,
+ rcdev->path,
"org.gnome.RemoteControlManager.Device",
"KeyPressed",
"sts", protocol_name, scancode,
keycode ? keycode->name : "KEY_RESERVED");
else if (keycode && !pressed)
- sd_bus_emit_signal(device->mgr->bus,
- device->path,
+ sd_bus_emit_signal(rcdev->mgr->bus,
+ rcdev->path,
"org.gnome.RemoteControlManager.Device",
"KeyReleased",
"s", keycode->name);
@@ -335,45 +337,45 @@ evdev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
}
int
-evdev_setup(struct device *device, const char *path)
+evdev_setup(struct rc_device *rcdev, const char *path)
{
int r;
struct keymap *keymap;
/* FIXME: Fixup error handling */
- if (!device)
+ if (!rcdev)
return -EINVAL;
- if (device->evdev_fd >= 0) {
+ if (rcdev->evdev_fd >= 0) {
printf("Multiple evdev devices!?\n");
return 0;
}
- device->evdev_fd = open(path, O_RDONLY | O_NONBLOCK);
- r = libevdev_new_from_fd(device->evdev_fd, &device->evdev_dev);
+ rcdev->evdev_fd = open(path, O_RDONLY | O_NONBLOCK);
+ r = libevdev_new_from_fd(rcdev->evdev_fd, &rcdev->evdev_dev);
if (r < 0) {
printf("Failed to open evdev device %s: %s\n", path, strerror(-r));
- close(device->evdev_fd);
+ evdev_close(rcdev);
return r;
}
- device->input_name = strdup(libevdev_get_name(device->evdev_dev));
+ rcdev->input_name = strdup(libevdev_get_name(rcdev->evdev_dev));
printf("Performing evdev setup for device %s (%s)\n",
- device->path, libevdev_get_name(device->evdev_dev));
- r = evdev_clear_keymap(device);
+ rcdev->path, libevdev_get_name(rcdev->evdev_dev));
+ r = evdev_clear_keymap(rcdev);
if (r < 0)
return r;
- list_for_each_entry(keymap, &device->keymaps, list)
- r = evdev_set_keymap(device, keymap);
+ list_for_each_entry(keymap, &rcdev->keymaps, list)
+ r = evdev_set_keymap(rcdev, keymap);
- if (sd_event_add_io(device->mgr->event, &device->evdev_ev,
- device->evdev_fd, EPOLLIN, evdev_read, device) < 0) {
+ if (sd_event_add_io(rcdev->mgr->event, &rcdev->evdev_ev,
+ rcdev->evdev_fd, EPOLLIN, evdev_read, rcdev) < 0) {
printf("Failed to add event source for evdev device %s: %s\n",
path, strerror(errno));
r = -errno;
- evdev_close(device);
+ evdev_close(rcdev);
return r;
}
@@ -381,15 +383,15 @@ evdev_setup(struct device *device, const char *path)
}
void
-evdev_close(struct device *device)
+evdev_close(struct rc_device *rcdev)
{
- if (!device)
+ if (!rcdev)
return;
- if (device->evdev_fd < 0)
+ if (rcdev->evdev_fd < 0)
return;
- close(device->evdev_fd);
- device->evdev_fd = -1;
+ close(rcdev->evdev_fd);
+ rcdev->evdev_fd = -1;
}
diff --git a/rcm-server-evdev.h b/rcm-server-evdev.h
index a2f4283..80d985f 100644
--- a/rcm-server-evdev.h
+++ b/rcm-server-evdev.h
@@ -1,15 +1,15 @@
#ifndef foorcmserverevdevhfoo
#define foorcmserverevdevhfoo
-int evdev_set_mapping(struct device *device, unsigned protocol,
+int evdev_set_mapping(struct rc_device *rcdev, unsigned protocol,
uint64_t scancode, struct linux_input_keycode *lik);
-int evdev_get_mapping(struct device *device, unsigned index, unsigned *ret_protocol,
+int evdev_get_mapping(struct rc_device *rcdev, unsigned index, unsigned *ret_protocol,
uint64_t *ret_scancode, struct linux_input_keycode **ret_lik);
-int evdev_setup(struct device *device, const char *path);
+int evdev_setup(struct rc_device *rcdev, const char *path);
-void evdev_close(struct device *device);
+void evdev_close(struct rc_device *rcdev);
#endif
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index 84e8f7c..5374dda 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -343,7 +343,7 @@ out:
}
static int
-keymaps_load_dir(struct device *device, int pfd, const char *path)
+keymaps_load_dir(struct rc_device *rcdev, int pfd, const char *path)
{
_cleanup_closedir_ DIR *dir = NULL;
int dfd;
@@ -365,12 +365,12 @@ keymaps_load_dir(struct device *device, int pfd, const char *path)
case DT_REG:
case DT_LNK:
case DT_UNKNOWN:
- keymap = find_keymap_by_id(device, dent->d_name);
+ keymap = find_keymap_by_id(rcdev, dent->d_name);
if (keymap)
continue;
keymap = keymap_read(dfd, path, dent->d_name);
if (keymap)
- list_add(&keymap->list, &device->keymaps);
+ list_add(&keymap->list, &rcdev->keymaps);
break;
default:
break;
@@ -381,12 +381,12 @@ keymaps_load_dir(struct device *device, int pfd, const char *path)
}
int
-keymaps_load(struct device *device)
+keymaps_load(struct rc_device *rcdev)
{
- char pdpath[strlen("per-device/") + strlen(device->name) + 1];
+ char pdpath[strlen("per-device/") + strlen(rcdev->name) + 1];
_cleanup_close_ int dfd;
- sprintf(pdpath, "per-device/%s", device->name);
+ sprintf(pdpath, "per-device/%s", rcdev->name);
/* FIXME: This is just a temporary location */
dfd = open("./keymaps", O_PATH | O_DIRECTORY);
@@ -394,9 +394,9 @@ keymaps_load(struct device *device)
return -errno;
printf("Loading per-device keymaps...\n");
- keymaps_load_dir(device, dfd, pdpath);
+ keymaps_load_dir(rcdev, dfd, pdpath);
printf("Loading default keymaps...\n");
- keymaps_load_dir(device, dfd, "default");
+ keymaps_load_dir(rcdev, dfd, "default");
return 0;
}
@@ -503,11 +503,11 @@ keymap_free(struct keymap *keymap)
}
struct keymap *
-find_keymap_by_id(struct device *dev, const char *id)
+find_keymap_by_id(struct rc_device *rcdev, const char *id)
{
struct keymap *keymap;
- list_for_each_entry(keymap, &dev->keymaps, list)
+ list_for_each_entry(keymap, &rcdev->keymaps, list)
if (!strcmp(keymap->id, id))
return keymap;
diff --git a/rcm-server-keymap.h b/rcm-server-keymap.h
index 8da6bb6..be66582 100644
--- a/rcm-server-keymap.h
+++ b/rcm-server-keymap.h
@@ -19,11 +19,11 @@ struct keymap {
struct keycode keycodes[];
};
-struct keymap *find_keymap_by_id(struct device *dev, const char *id);
+struct keymap *find_keymap_by_id(struct rc_device *rcdev, const char *id);
struct keymap *keymap_read(int dfd, const char *path, const char *filename);
-int keymaps_load(struct device *device);
+int keymaps_load(struct rc_device *rcdev);
int keymap_write(struct keymap *keymap);
diff --git a/rcm-server-lirc.c b/rcm-server-lirc.c
index 4342cc1..3abcc32 100644
--- a/rcm-server-lirc.c
+++ b/rcm-server-lirc.c
@@ -30,16 +30,16 @@ lirc_write(int fd, const uint32_t *v, unsigned count)
static int
lirc_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
- struct device *device = userdata;
+ struct rc_device *rcdev = userdata;
uint8_t buf[100];
ssize_t bytes_read;
- if (fd != device->lirc_fd)
- fprintf(stderr, "lirc fd mismatch: %i != %i\n", device->lirc_fd, fd);
+ if (fd != rcdev->lirc_fd)
+ fprintf(stderr, "lirc fd mismatch: %i != %i\n", rcdev->lirc_fd, fd);
if (revents & EPOLLHUP) {
fprintf(stderr, "lirc connection closed!\n");
- lirc_close(device);
+ lirc_close(rcdev);
return 0;
}
@@ -55,30 +55,30 @@ lirc_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
}
int
-lirc_setup(struct device *device, const char *path)
+lirc_setup(struct rc_device *rcdev, const char *path)
{
int r;
- if (!device)
+ if (!rcdev)
return -EINVAL;
- if (device->lirc_fd >= 0) {
+ if (rcdev->lirc_fd >= 0) {
printf("Multiple lirc devices!?\n");
return 0;
}
- device->lirc_fd = open(path, O_RDWR | O_NONBLOCK);
- if (device->lirc_fd < 0) {
+ rcdev->lirc_fd = open(path, O_RDWR | O_NONBLOCK);
+ if (rcdev->lirc_fd < 0) {
printf("Failed to open lirc device %s: %s\n", path, strerror(errno));
return -errno;
}
- if (sd_event_add_io(device->mgr->event, &device->lirc_ev,
- device->lirc_fd, EPOLLIN, lirc_read, device) < 0) {
+ if (sd_event_add_io(rcdev->mgr->event, &rcdev->lirc_ev,
+ rcdev->lirc_fd, EPOLLIN, lirc_read, rcdev) < 0) {
printf("Failed to add event source for lirc device %s: %s\n",
path, strerror(errno));
r = -errno;
- lirc_close(device);
+ lirc_close(rcdev);
return r;
}
@@ -86,15 +86,15 @@ lirc_setup(struct device *device, const char *path)
}
void
-lirc_close(struct device *device)
+lirc_close(struct rc_device *rcdev)
{
- if (!device)
+ if (!rcdev)
return;
- if (device->lirc_fd < 0)
+ if (rcdev->lirc_fd < 0)
return;
- close(device->lirc_fd);
- device->lirc_fd = -1;
+ close(rcdev->lirc_fd);
+ rcdev->lirc_fd = -1;
}
diff --git a/rcm-server-lirc.h b/rcm-server-lirc.h
index 08bb2cb..3a12f94 100644
--- a/rcm-server-lirc.h
+++ b/rcm-server-lirc.h
@@ -3,9 +3,9 @@
void lirc_write(int fd, const uint32_t *v, unsigned count);
-void lirc_close(struct device *device);
+int lirc_setup(struct rc_device *rcdev, const char *path);
-int lirc_setup(struct device *device, const char *path);
+void lirc_close(struct rc_device *rcdev);
#endif
diff --git a/rcm-server-main.c b/rcm-server-main.c
index 33ef8a7..5cb5ebe 100644
--- a/rcm-server-main.c
+++ b/rcm-server-main.c
@@ -20,14 +20,14 @@
#include "rcm-server-lirc.h"
#include "rcm-server-kdb.h"
-static struct device *
+static struct rc_device *
find_device_by_path(struct manager *mgr, const char *path)
{
- struct device *dev;
+ struct rc_device *rcdev;
- list_for_each_entry(dev, &mgr->devices, list)
- if (!strcmp(dev->path, path))
- return dev;
+ list_for_each_entry(rcdev, &mgr->rc_devs, list)
+ if (!strcmp(rcdev->path, path))
+ return rcdev;
return NULL;
}
@@ -38,26 +38,26 @@ property_get(sd_bus *bus, const char *path, const char *interface,
sd_bus_error *error)
{
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
- dev = find_device_by_path(mgr, path);
- if (!dev) {
+ rcdev = find_device_by_path(mgr, path);
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
return -EINVAL;
}
if (!strcmp(property, "SysName"))
- return sd_bus_message_append(reply, "s", dev->name);
+ return sd_bus_message_append(reply, "s", rcdev->name);
else if (!strcmp(property, "Description"))
- return sd_bus_message_append(reply, "s", dev->input_name);
+ return sd_bus_message_append(reply, "s", rcdev->input_name);
else if (!strcmp(property, "DriverName"))
- return sd_bus_message_append(reply, "s", dev->driver_name);
+ return sd_bus_message_append(reply, "s", rcdev->driver_name);
else if (!strcmp(property, "KernelKeymapName"))
- return sd_bus_message_append(reply, "s", dev->keymap_name);
+ return sd_bus_message_append(reply, "s", rcdev->keymap_name);
else if (!strcmp(property, "HardwareType"))
return sd_bus_message_append(reply, "s", "ir");
else if (!strcmp(property, "Error"))
- return sd_bus_message_append(reply, "s", dev->error);
+ return sd_bus_message_append(reply, "s", rcdev->error);
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidProperty", "Sorry, invalid property");
return -EINVAL;
@@ -216,20 +216,20 @@ method_getkernelmappings(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
unsigned protocol_numeric;
uint64_t scancode;
struct linux_input_keycode *lik;
unsigned i = 0;
int r;
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev) {
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
return -EINVAL;
}
- if (dev->evdev_fd < 0) {
+ if (rcdev->evdev_fd < 0) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.EvdevError", "Evdev device not available");
r = -EINVAL;
goto out;
@@ -243,7 +243,7 @@ method_getkernelmappings(sd_bus_message *m, void *userdata, sd_bus_error *error)
if (r < 0)
goto out;
- while ((r = evdev_get_mapping(dev, i, &protocol_numeric, &scancode, &lik)) > 0) {
+ while ((r = evdev_get_mapping(rcdev, i, &protocol_numeric, &scancode, &lik)) > 0) {
r = sd_bus_message_append(reply, "a{sv}", 3,
"protocol", "s", rc_protocols[protocol_numeric],
"scancode", "t", scancode,
@@ -276,20 +276,20 @@ method_setkernelmappings(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
unsigned protocol;
uint64_t scancode;
struct linux_input_keycode *keycode;
int r;
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev) {
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
r = -EINVAL;
goto out;
}
- if (dev->evdev_fd < 0) {
+ if (rcdev->evdev_fd < 0) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.EvdevError", "Evdev device not available");
r = -EINVAL;
goto out;
@@ -303,7 +303,7 @@ method_setkernelmappings(sd_bus_message *m, void *userdata, sd_bus_error *error)
printf("%s kernel mapping %s:0x%08lx:%s\n",
keycode ? "Setting" : "Unsetting", rc_protocols[protocol],
scancode, keycode ? keycode->name : "<na>");
- evdev_set_mapping(dev, protocol, scancode, keycode);
+ evdev_set_mapping(rcdev, protocol, scancode, keycode);
}
if (r < 0)
@@ -324,12 +324,12 @@ method_listkeymaps(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
struct keymap *keymap;
int r;
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev) {
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
return -EINVAL;
}
@@ -342,8 +342,8 @@ method_listkeymaps(sd_bus_message *m, void *userdata, sd_bus_error *error)
if (r < 0)
goto out;
- list_for_each_entry(keymap, &dev->keymaps, list) {
- printf("Listing keymaps for %s: %s\n", dev->name, keymap->name);
+ list_for_each_entry(keymap, &rcdev->keymaps, list) {
+ printf("Listing keymaps for %s: %s\n", rcdev->name, keymap->name);
r = sd_bus_message_append(reply, "s", keymap->id);
if (r < 0)
goto out;
@@ -368,14 +368,14 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
struct keymap *keymap;
const char *id;
int r;
unsigned i;
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev) {
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
return -EINVAL;
}
@@ -386,7 +386,7 @@ method_getkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error)
return r;
}
- keymap = find_keymap_by_id(dev, id);
+ keymap = find_keymap_by_id(rcdev, id);
if (!keymap) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidKeymap", "Sorry, unknown keymap");
return -EINVAL;
@@ -726,7 +726,7 @@ static int
method_setkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
struct keymap *old_keymap;
struct keymap *new_keymap;
const char *id;
@@ -734,15 +734,15 @@ method_setkeymap(sd_bus_message *m, void *userdata, sd_bus_error *error)
uint16_t cols, rows;
int r;
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev)
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev)
return sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
r = method_setkeymap_parse_dbus_msg(m, NULL, &id, &keycode_count, &cols, &rows);
if (r < 0)
goto out;
- old_keymap = find_keymap_by_id(dev, id);
+ old_keymap = find_keymap_by_id(rcdev, id);
if (!old_keymap)
return sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidKeymap", "Sorry, unknown keymap");
@@ -788,7 +788,7 @@ method_transmit(sd_bus_message *m, void *userdata, sd_bus_error *error)
{
_cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
struct manager *mgr = userdata;
- struct device *dev;
+ struct rc_device *rcdev;
const void *v;
size_t l;
int r;
@@ -796,8 +796,8 @@ method_transmit(sd_bus_message *m, void *userdata, sd_bus_error *error)
size_t count;
printf("Transmit method called\n");
- dev = find_device_by_path(mgr, sd_bus_message_get_path(m));
- if (!dev) {
+ rcdev = find_device_by_path(mgr, sd_bus_message_get_path(m));
+ if (!rcdev) {
sd_bus_error_set_const(error, "org.gnome.RemoteControlManager.InvalidDevice", "Sorry, invalid device");
return -EINVAL;
}
@@ -812,8 +812,7 @@ method_transmit(sd_bus_message *m, void *userdata, sd_bus_error *error)
values = v;
count = l / sizeof(uint32_t);
- lirc_write(dev->lirc_fd, values, count);
-
+ lirc_write(rcdev->lirc_fd, values, count);
return sd_bus_reply_method_return(m, NULL);
@@ -846,18 +845,18 @@ enumerator(sd_bus *bus, const char *path, void *userdata, char ***retnodes, sd_b
{
_cleanup_strv_free_ char **nodes = NULL;
struct manager *mgr = userdata;
- struct device *device;
+ struct rc_device *rcdev;
int i = 0;
if (!path)
return 0;
- nodes = zmalloc((mgr->num_devices + 1) * sizeof(char *));
+ nodes = zmalloc((mgr->num_rc_devs + 1) * sizeof(char *));
if (!nodes)
return -ENOMEM;
- list_for_each_entry(device, &mgr->devices, list) {
- nodes[i] = strdup(device->path);
+ list_for_each_entry(rcdev, &mgr->rc_devs, list) {
+ nodes[i] = strdup(rcdev->path);
if (!nodes[i])
return -ENOMEM;
i++;
@@ -881,9 +880,9 @@ free_manager(struct manager *mgr) {
sd_event_unref(mgr->event);
udev_close(mgr);
- while (!list_empty(&mgr->devices)) {
- struct device *dev = list_first_entry(&mgr->devices, typeof(*dev), list);
- device_free(dev);
+ while (!list_empty(&mgr->rc_devs)) {
+ struct rc_device *rcdev = list_first_entry(&mgr->rc_devs, typeof(*rcdev), list);
+ rc_device_free(rcdev);
}
free(mgr);
}
@@ -926,7 +925,7 @@ main(int argc, char **argv)
fprintf(stderr, "Failed to allocate memory: %m\n");
goto finish;
}
- list_init(&mgr->devices);
+ list_init(&mgr->rc_devs);
r = sd_event_default(&mgr->event);
if (r < 0) {
diff --git a/rcm-server-main.h b/rcm-server-main.h
index 12907fc..79d9b72 100644
--- a/rcm-server-main.h
+++ b/rcm-server-main.h
@@ -1,7 +1,7 @@
#ifndef foorcmserverhfoo
#define foorcmserverhfoo
-struct device {
+struct rc_device {
char *name;
char *path;
char *input_name;
@@ -25,8 +25,8 @@ struct manager {
struct udev *udev;
struct udev_monitor *udev_mon;
sd_event_source *udev_ev;
- struct list_head devices;
- unsigned num_devices;
+ struct list_head rc_devs;
+ unsigned num_rc_devs;
void *db;
int db_ifd;
sd_event_source *db_ifd_ev;
diff --git a/rcm-server-udev.c b/rcm-server-udev.c
index 77fb403..fec809d 100644
--- a/rcm-server-udev.c
+++ b/rcm-server-udev.c
@@ -16,57 +16,57 @@
#include "rcm-server-udev.h"
void
-device_free(struct device *device)
+rc_device_free(struct rc_device *rcdev)
{
- if (!device)
+ if (!rcdev)
return;
- list_del(&device->list);
- lirc_close(device);
- evdev_close(device);
+ list_del(&rcdev->list);
+ lirc_close(rcdev);
+ evdev_close(rcdev);
- free(device->path);
- free(device->input_name);
- free(device->driver_name);
- free(device->keymap_name);
- free(device->dev_name);
+ free(rcdev->path);
+ free(rcdev->input_name);
+ free(rcdev->driver_name);
+ free(rcdev->keymap_name);
+ free(rcdev->dev_name);
- while (!list_empty(&device->keymaps)) {
- struct keymap *keymap = list_first_entry(&device->keymaps, typeof(*keymap), list);
+ while (!list_empty(&rcdev->keymaps)) {
+ struct keymap *keymap = list_first_entry(&rcdev->keymaps, typeof(*keymap), list);
list_del(&keymap->list);
free(keymap->name);
free(keymap);
}
- free(device);
+ free(rcdev);
}
static void
-device_remove(struct manager *mgr, struct udev_device *udev)
+udev_device_remove(struct manager *mgr, struct udev_device *udev)
{
const char *name;
- struct device *device;
+ struct rc_device *rcdev;
name = udev_device_get_sysname(udev);
printf("Asked to remove device %s\n", name);
- list_for_each_entry(device, &mgr->devices, list) {
- if (strcmp(device->name, name))
+ list_for_each_entry(rcdev, &mgr->rc_devs, list) {
+ if (strcmp(rcdev->name, name))
continue;
- sd_bus_emit_object_removed(mgr->bus, device->path);
- device_free(device);
- mgr->num_devices--;
+ sd_bus_emit_object_removed(mgr->bus, rcdev->path);
+ rc_device_free(rcdev);
+ mgr->num_rc_devs--;
break;
}
}
static void
-device_add(struct manager *mgr, struct udev_device *udev)
+udev_device_add(struct manager *mgr, struct udev_device *udev)
{
const char *name;
const char *str;
char *path;
- struct device *device;
+ struct rc_device *rcdev;
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
int r;
@@ -77,29 +77,28 @@ device_add(struct manager *mgr, struct udev_device *udev)
return;
}
- device = malloc(sizeof(*device));
- if (!device) {
+ rcdev = malloc(sizeof(*rcdev));
+ if (!rcdev) {
fprintf(stderr, "malloc failed: %m\n");
free(path);
return;
}
- list_init(&device->keymaps);
- device->mgr = mgr;
- device->path = path;
- device->name = device->path + strlen("/org/gnome/RemoteControlManager/");
- device->evdev_fd = -1;
- device->lirc_fd = -1;
- device->error = NULL;
- device->input_name = NULL;
- device->driver_name = NULL;
- device->keymap_name = NULL;
- device->dev_name = NULL;
-
- if (keymaps_load(device) < 0) {
+ list_init(&rcdev->keymaps);
+ rcdev->mgr = mgr;
+ rcdev->path = path;
+ rcdev->name = rcdev->path + strlen("/org/gnome/RemoteControlManager/");
+ rcdev->evdev_fd = -1;
+ rcdev->lirc_fd = -1;
+ rcdev->error = NULL;
+ rcdev->input_name = NULL;
+ rcdev->driver_name = NULL;
+ rcdev->keymap_name = NULL;
+ rcdev->dev_name = NULL;
+
+ if (keymaps_load(rcdev) < 0) {
fprintf(stderr, "failed to load keymaps: %m\n");
- free(path);
- free(device);
+ rc_device_free(rcdev);
return;
}
@@ -141,18 +140,18 @@ device_add(struct manager *mgr, struct udev_device *udev)
}
if (!strcmp(subsys, "input")) {
- r = evdev_setup(device, devnode);
+ r = evdev_setup(rcdev, devnode);
if (r < 0) {
printf("Failed to setup evdev: %s\n", devnode);
- device->error = "Error: Failed to setup evdev";
+ rcdev->error = "Error: Failed to setup evdev";
goto next;
}
} else if (!strcmp(subsys, "lirc")) {
- r = lirc_setup(device, devnode);
+ r = lirc_setup(rcdev, devnode);
if (r < 0) {
printf("Failed to setup lirc: %s\n", devnode);
- device->error = "Error: Failed to setup lirc";
+ rcdev->error = "Error: Failed to setup lirc";
goto next;
}
@@ -175,11 +174,11 @@ next:
for (token = strtok(tmp, "\n"); token; token = strtok(NULL, "\n")) {
if (!strncmp(token, "DRV_NAME=", strlen("DRV_NAME=")))
- device->driver_name = strdup(token + strlen("DRV_NAME="));
+ rcdev->driver_name = strdup(token + strlen("DRV_NAME="));
else if (!strncmp(token, "NAME=", strlen("NAME=")))
- device->keymap_name = strdup(token + strlen("NAME="));
+ rcdev->keymap_name = strdup(token + strlen("NAME="));
else if (!strncmp(token, "DEVNAME=", strlen("DEVNAME=")))
- device->dev_name = strdup(token + strlen("DEVNAME="));
+ rcdev->dev_name = strdup(token + strlen("DEVNAME="));
else if (!strncmp(token, "MAJOR=", strlen("MAJOR=")))
continue;
else if (!strncmp(token, "MINOR=", strlen("MINOR=")))
@@ -195,19 +194,19 @@ next:
printf("\tSubsystem : %s\n", udev_device_get_subsystem(udev));
printf("\tDevtype : %s\n", udev_device_get_devtype(udev));
printf("\tAction : %s\n", udev_device_get_action(udev));
- printf("\tName : %s\n", device->name);
- printf("\tInput name: %s\n", device->input_name);
- printf("\tDriver : %s\n", device->driver_name);
- printf("\tKernel map: %s\n", device->keymap_name);
- printf("\tDev name : %s\n", device->dev_name);
- printf("\tevdev fd : %i\n", device->evdev_fd);
- printf("\tLIRC fd : %i\n", device->lirc_fd);
- printf("\tDBUS path : %s\n", device->path);
+ printf("\tName : %s\n", rcdev->name);
+ printf("\tInput name: %s\n", rcdev->input_name);
+ printf("\tDriver : %s\n", rcdev->driver_name);
+ printf("\tKernel map: %s\n", rcdev->keymap_name);
+ printf("\tDev name : %s\n", rcdev->dev_name);
+ printf("\tevdev fd : %i\n", rcdev->evdev_fd);
+ printf("\tLIRC fd : %i\n", rcdev->lirc_fd);
+ printf("\tDBUS path : %s\n", rcdev->path);
printf("\tProtocols : %s\n",
udev_device_get_sysattr_value(udev, "protocols"));
- list_add(&device->list, &mgr->devices);
- mgr->num_devices++;
+ list_add(&rcdev->list, &mgr->rc_devs);
+ mgr->num_rc_devs++;
sd_bus_emit_object_added(mgr->bus, path);
}
@@ -216,7 +215,7 @@ static int
udev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
{
struct manager *mgr = userdata;
- struct udev_device *dev;
+ struct udev_device *udev_dev;
if (revents & EPOLLHUP) {
fprintf(stderr, "udev connection closed!\n");
@@ -228,13 +227,13 @@ udev_read(sd_event_source *s, int fd, uint32_t revents, void *userdata)
return 0;
}
- while ((dev = udev_monitor_receive_device(mgr->udev_mon))) {
- printf("Read device: %s\n", udev_device_get_syspath(dev));
- if (!strcmp(udev_device_get_action(dev), "add"))
- device_add(mgr, dev);
- else if (!strcmp(udev_device_get_action(dev), "remove"))
- device_remove(mgr, dev);
- udev_device_unref(dev);
+ while ((udev_dev = udev_monitor_receive_device(mgr->udev_mon))) {
+ printf("Read device: %s\n", udev_device_get_syspath(udev_dev));
+ if (!strcmp(udev_device_get_action(udev_dev), "add"))
+ udev_device_add(mgr, udev_dev);
+ else if (!strcmp(udev_device_get_action(udev_dev), "remove"))
+ udev_device_remove(mgr, udev_dev);
+ udev_device_unref(udev_dev);
}
return 1;
@@ -245,7 +244,7 @@ udev_setup(struct manager *mgr)
{
struct udev_enumerate *enumerate;
struct udev_list_entry *devices, *dev_list_entry;
- struct udev_device *dev;
+ struct udev_device *udev_dev;
mgr->udev = udev_new();
if (!mgr->udev)
@@ -269,15 +268,15 @@ udev_setup(struct manager *mgr)
continue;
}
- dev = udev_device_new_from_syspath(mgr->udev, path);
- if (!dev) {
+ udev_dev = udev_device_new_from_syspath(mgr->udev, path);
+ if (!udev_dev) {
printf("Failed to create udev device\n");
continue;
}
- device_add(mgr, dev);
+ udev_device_add(mgr, udev_dev);
- udev_device_unref(dev);
+ udev_device_unref(udev_dev);
}
udev_enumerate_unref(enumerate);
diff --git a/rcm-server-udev.h b/rcm-server-udev.h
index aea638f..ba90752 100644
--- a/rcm-server-udev.h
+++ b/rcm-server-udev.h
@@ -1,7 +1,7 @@
#ifndef foorcmserverudevhfoo
#define foorcmserverudevhfoo
-void device_free(struct device *device);
+void rc_device_free(struct rc_device *rcdev);
int udev_setup(struct manager *mgr);