(logo) Evfilter library documentation

Home | FAQ | Filters | Profile | Filter API | Library API

Library API

void evf_filter_free(struct evf_filter *filter)

Filter destructor.

const char *evf_filter_get_name(struct evf_filter *filter)

const char *evf_filter_get_desc(struct evf_filter *filter)

Returns filter name and description.

void evf_filters_free(struct evf_filter *root)

Destroys, i.e. calls evf_filter_free(), on each filter in a list.

struct evf_filter *evf_filters_last(struct evf_filter *root)

Returns a pointer to the last filter in a list.

struct evf_filter *evf_filters_append(struct evf_filter *root,
                                      struct evf_filter *filters)

Appends linked list filters to the end of the list root.

uinput API

The uinput library wraps kernel interface to create an input device in userspace.

int evf_uinput_create(struct uinput_user_dev *ui_dev_info)

Creates an userspace input device, returns a file descriptor.

void evf_uinput_destroy(int fd)

Destroys userspace input device.

// SPDX-License-Identifier: GPL-2.1-or-later
/*
 * Copyright (C) 2008-2020 Cyril Hrubis <metan@ucw.cz>
 */

/*

  This is test for evf_uinput interface for user input kernel interface, beware
  that this sends enter keys and if our xserver listens for event input devices
  by default you end up with enter pressing each second.

 */

#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include "evf_uinput.h"

static int sig_flag = 1;

static void sighandler(int sig __attribute__ ((unused)))
{
        sig_flag = 0;
}

static void pack_event(struct input_event *ev, int type, int code, int value)
{
        gettimeofday(&ev->time, NULL);
        ev->type = type;
        ev->code = code;
        ev->value = value;
}

int main(void)
{
        int fd;
        struct uinput_user_dev dev;
        struct input_event ev;

        memset(&dev, 0, sizeof (dev));
        strcpy(dev.name, "test");

        fd = evf_uinput_create(&dev);

        if (fd < 0) {
                fprintf(stderr,
                        "Failed to create uinput: %s\n", strerror(errno));
                return 1;
        }

        signal(SIGQUIT, sighandler);
        signal(SIGTERM, sighandler);
        signal(SIGINT, sighandler);

        while (sig_flag) {
                sleep(1);

                /* send enter key down */
                pack_event(&ev, EV_KEY, KEY_ENTER, 1);
                write(fd, &ev, sizeof (ev));

                /* send sync */
                pack_event(&ev, EV_SYN, SYN_REPORT, 0);
                write(fd, &ev, sizeof (ev));

                /* send enter key up */
                pack_event(&ev, EV_KEY, KEY_ENTER, 0);
                write(fd, &ev, sizeof (ev));

                /* send sync */
                pack_event(&ev, EV_SYN, SYN_REPORT, 0);
                write(fd, &ev, sizeof (ev));
        }

        evf_uinput_destroy(fd);
        printf("Got signal, exiting...\n");

        return 0;
}

 


Copyright © Cyril (metan) Hrubis 2009-2020