|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Patrick Ziegler and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials are made available under the |
| 5 | + * terms of the Eclipse Public License 2.0 which is available at |
| 6 | + * https://www.eclipse.org/legal/epl-2.0. |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + * |
| 10 | + * Contributors: |
| 11 | + * Patrick Ziegler - initial API and implementation |
| 12 | + *******************************************************************************/ |
| 13 | +package org.eclipse.wb.internal.os.linux.gtk3; |
| 14 | + |
| 15 | +import java.lang.foreign.Arena; |
| 16 | +import java.lang.foreign.FunctionDescriptor; |
| 17 | +import java.lang.foreign.Linker; |
| 18 | +import java.lang.foreign.MemorySegment; |
| 19 | +import java.lang.foreign.SymbolLookup; |
| 20 | +import java.lang.foreign.ValueLayout; |
| 21 | +import java.lang.invoke.MethodHandle; |
| 22 | + |
| 23 | +public final class GTK3 { |
| 24 | + private static class InstanceHolder { |
| 25 | + private static final Linker linker = Linker.nativeLinker(); |
| 26 | + private static final SymbolLookup gtk = SymbolLookup.libraryLookup("libgtk-3.so", Arena.ofAuto()); |
| 27 | + |
| 28 | + private static MethodHandle createHandle(String name, FunctionDescriptor descriptor) { |
| 29 | + MemorySegment symbol = gtk.find(name).orElseThrow(UnsatisfiedLinkError::new); |
| 30 | + return InstanceHolder.linker.downcallHandle(symbol, descriptor); |
| 31 | + } |
| 32 | + |
| 33 | + static final MethodHandle gtk_get_major_version = createHandle("gtk_get_major_version", |
| 34 | + FunctionDescriptor.of(ValueLayout.JAVA_INT)); |
| 35 | + |
| 36 | + static final MethodHandle gtk_get_minor_version = createHandle("gtk_get_minor_version", |
| 37 | + FunctionDescriptor.of(ValueLayout.JAVA_INT)); |
| 38 | + |
| 39 | + static final MethodHandle gtk_get_micro_version = createHandle("gtk_get_micro_version", |
| 40 | + FunctionDescriptor.of(ValueLayout.JAVA_INT)); |
| 41 | + } |
| 42 | + |
| 43 | + public static int gtk_get_major_version() throws Throwable { |
| 44 | + return (int) InstanceHolder.gtk_get_major_version.invoke(); |
| 45 | + } |
| 46 | + |
| 47 | + public static int gtk_get_minor_version() throws Throwable { |
| 48 | + return (int) InstanceHolder.gtk_get_minor_version.invoke(); |
| 49 | + } |
| 50 | + |
| 51 | + public static int gtk_get_micro_version() throws Throwable { |
| 52 | + return (int) InstanceHolder.gtk_get_micro_version.invoke(); |
| 53 | + } |
| 54 | +} |
0 commit comments