forked from drath/libratbag
Add implementation of ratbag_new_from_fd and ratbag_unref
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
@@ -25,6 +25,12 @@
|
||||
#define LIBRATBAG_PRIVATE_H
|
||||
|
||||
#include "libratbag.h"
|
||||
|
||||
struct ratbag {
|
||||
int evdev_fd;
|
||||
int refcount;
|
||||
};
|
||||
|
||||
void ratbag_device_init(struct ratbag *rb, int fd);
|
||||
|
||||
void
|
||||
|
||||
@@ -23,8 +23,11 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <linux/input.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libratbag-private.h"
|
||||
#include "libratbag-util.h"
|
||||
@@ -76,6 +79,57 @@ log_msg(struct libratbag *libratbag,
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void
|
||||
ratbag_device_init(struct ratbag *rb, int fd)
|
||||
{
|
||||
rb->evdev_fd = fd;
|
||||
rb->refcount = 1;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag*
|
||||
ratbag_new_from_fd(struct libratbag *libratbag, int fd)
|
||||
{
|
||||
int rc;
|
||||
struct input_id ids;
|
||||
struct ratbag *ratbag = NULL;
|
||||
|
||||
if (!libratbag) {
|
||||
fprintf(stderr, "libratbag is NULL\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ratbag = zalloc(sizeof(*ratbag));
|
||||
if (!ratbag)
|
||||
return NULL;
|
||||
|
||||
rc = ioctl(fd, EVIOCGID, &ids);
|
||||
if (rc < 0)
|
||||
goto out_err;
|
||||
|
||||
ratbag_device_init(ratbag, fd);
|
||||
|
||||
return ratbag;
|
||||
|
||||
out_err:
|
||||
free(ratbag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct ratbag *
|
||||
ratbag_unref(struct ratbag *ratbag)
|
||||
{
|
||||
if (ratbag == NULL)
|
||||
return NULL;
|
||||
|
||||
assert(ratbag->refcount > 0);
|
||||
ratbag->refcount--;
|
||||
if (ratbag->refcount > 0)
|
||||
return ratbag;
|
||||
|
||||
free(ratbag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT struct libratbag *
|
||||
libratbag_create_context(void)
|
||||
{
|
||||
|
||||
@@ -5,6 +5,8 @@ global:
|
||||
libratbag_create_context;
|
||||
libratbag_ref;
|
||||
libratbag_unref;
|
||||
ratbag_new_from_fd;
|
||||
ratbag_unref;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user