2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.linuxinput.internal.evdev4j.jnr;
15 import static org.openhab.binding.linuxinput.internal.evdev4j.Utils.constantFromInt;
16 import static org.openhab.binding.linuxinput.internal.evdev4j.jnr.Utils.trimEnd;
18 import java.util.Optional;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.linuxinput.internal.evdev4j.Utils;
23 import jnr.constants.Constant;
24 import jnr.ffi.LibraryLoader;
25 import jnr.ffi.Runtime;
26 import jnr.ffi.Struct;
27 import jnr.ffi.annotations.IgnoreError;
28 import jnr.ffi.annotations.In;
29 import jnr.ffi.annotations.Out;
30 import jnr.ffi.byref.PointerByReference;
31 import jnr.ffi.mapper.FunctionMapper;
34 * JNR library for libdevdev library (libevdev.h).
36 * @author Thomas Weißschuh - Initial contribution
40 public interface EvdevLibrary {
41 static EvdevLibrary load() {
42 FunctionMapper evdevFunctionMapper = (functionName, context) -> "libevdev_" + trimEnd("_", functionName);
43 return LibraryLoader.create(EvdevLibrary.class).library("evdev").mapper(evdevFunctionMapper).load();
46 static Handle makeHandle(EvdevLibrary lib) {
47 return new Handle(Runtime.getRuntime(lib));
50 class Handle extends Struct {
51 public Handle(Runtime runtime) {
66 public int getValue() {
71 final class InputEvent extends Struct {
72 public UnsignedLong sec = new UnsignedLong();
73 public UnsignedLong usec = new UnsignedLong();
74 public Unsigned16 type = new Unsigned16();
75 public Unsigned16 code = new Unsigned16();
76 public Signed32 value = new Signed32();
78 public InputEvent(Runtime runtime) {
83 int new_from_fd(int fd, @Out PointerByReference handle);
85 void free(@In Handle handle);
87 int grab(@In Handle handle, int grab);
89 int next_event(@In Handle handle, int flags, @Out InputEvent event);
91 String event_type_get_name(int type);
93 String event_code_get_name(int type, int code);
95 String event_value_get_name(int type, int code, int value);
97 boolean has_event_type(@In Handle handle, int type);
99 int enable_event_type(@In Handle handle, int type);
101 int event_type_get_max(int type);
103 int disable_event_type(@In Handle handle, int type);
105 boolean has_event_code(@In Handle handle, int type, int code);
107 int enable_event_code(@In Handle handle, int type, int code);
109 int disable_event_code(@In Handle handle, int type, int code);
111 String get_name(@In Handle handle);
113 void set_name(@In Handle handle, String name);
115 String get_phys(@In Handle handle);
117 String get_uniq(@In Handle handle);
119 int get_id_product(@In Handle handle);
121 int get_id_vendor(@In Handle handle);
123 int get_id_bustype(@In Handle handle);
125 int get_id_version(@In Handle handle);
127 int get_driver_version(@In Handle handle);
129 @SuppressWarnings("unused")
134 public static final int SYNC = 1;
135 public static final int NORMAL = 2;
136 public static final int FORCE_SYNC = 4;
137 public static final int BLOCKING = 8;
140 class KeyEventValue {
141 private KeyEventValue() {
144 public static final int UP = 0;
145 public static final int DOWN = 1;
146 public static final int REPEAT = 2;
149 enum Type implements Constant {
171 public static Optional<Type> fromInt(int i) {
172 return constantFromInt(Type.values(), i);
176 public int intValue() {
181 public long longValue() {
186 public boolean defined() {
191 enum BusType implements Constant {
222 public static Optional<BusType> fromInt(int i) {
223 return Utils.constantFromInt(BusType.values(), i);
227 public int intValue() {
232 public long longValue() {
237 public boolean defined() {