// Path: stubs-server/src/main/java/org/freedesktop/wayland/server/jaccall/wl_listener.java
// @Struct({
//                 @Field(name = "link",
//                        type = CType.STRUCT,
//                        dataType = wl_list.class),
//                 @Field(name = "notify$",
//                        type = CType.POINTER,
//                        dataType = wl_notify_func_t.class)
//         })
// public final class wl_listener extends wl_listener_Jaccall_StructType {
// }
// 
// Path: stubs-server/src/main/java/org/freedesktop/wayland/server/jaccall/wl_notify_func_t.java
// @Functor
// public interface wl_notify_func_t {
//     void invoke(@Ptr(wl_listener.class) long listener,
//                 @Ptr(void.class) long data);
// }
// 
// Path: stubs-shared/src/main/java/org/freedesktop/wayland/util/ObjectCache.java
// public class ObjectCache {
//     private static final Map<Long, Object> MAPPED_OBJECTS = new HashMap<>();
// 
//     /**
//      * Retrieve a POJO that is mapped to a native pointer. This method should be used to easily retrieve a POJO with a
//      * native context. This method will only return a POJO if it was previously cached with a call to {@link #store(long, Object)}
//      *
//      * @param pointer The pointer of the associated object.
//      * @param <T>     The type of the POJO to cast.
//      *
//      * @return The cached object.
//      */
//     public static <T> T from(final long pointer) {
//         if (pointer == 0L) {
//             return null;
//         }
//         return (T) MAPPED_OBJECTS.get(pointer);
//     }
// 
//     /**
//      * Maps a native pointer to a POJO. This method should be used to easily store a POJO with a native context.
//      *
//      * @param pointer The pointer of the associated object.
//      * @param object  The object to cache.
//      */
//     public static void store(final long pointer,
//                              final Object object) {
//         final Object oldValue = MAPPED_OBJECTS.put(pointer,
//                                                    object);
//         if (oldValue != null) {
//             //put it back!
//             MAPPED_OBJECTS.put(pointer,
//                                oldValue);
//             throw new IllegalStateException(String.format("Can not re-map existing pointer.\n" +
//                                                           "Pointer=%s\n" +
//                                                           "old value=%s" +
//                                                           "\nnew value=%s",
//                                                           pointer,
//                                                           oldValue,
//                                                           object));
//         }
//     }
// 
//     /**
//      * Remove a mapped POJO. This method should be used when the native context of the POJO is no longer valid.
//      *
//      * @param pointer The pointer of the associated object.
//      */
//     public static <T> T remove(final long pointer) {
//         return (T) MAPPED_OBJECTS.remove(pointer);
//     }
// }


import org.freedesktop.jaccall.Pointer;
import org.freedesktop.wayland.server.jaccall.Pointerwl_notify_func_t;
import org.freedesktop.wayland.server.jaccall.WaylandServerCore;
import org.freedesktop.wayland.server.jaccall.wl_listener;
import org.freedesktop.wayland.server.jaccall.wl_notify_func_t;
import org.freedesktop.wayland.util.ObjectCache;
import static org.freedesktop.jaccall.Pointer.ref;
//Copyright 2015 Erik De Rijcke
//
//Licensed under the Apache License,Version2.0(the"License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing,software
//distributed under the License is distributed on an"AS IS"BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
package org.freedesktop.wayland.server;



/**
 * A single listener for Wayland signals
 * <p/>
 * {@code Listener} provides the means to listen for {@code wl_signal} notifications. Many
 * Wayland objects use {@code Listener} for notification of significant events like
 * object destruction.
 * <p/>
 * Clients should create {@code Listener} objects manually and can register them as
 * listeners to signals using #wl_signal_add, assuming the signal is
 * directly accessible. For opaque structs like wl_event_loop, adding a
 * listener should be done through provided accessor methods. A listener can
 * only listen to one signal at a time.
 */
abstract class Listener {

    private static final Pointer<wl_notify_func_t> WL_NOTIFY_FUNC = Pointerwl_notify_func_t.nref((wl_notify_func_t) (listenerPointer, data) -> {
        final Listener listener = ObjectCache.from(listenerPointer);
        listener.handle();
    });

    public final Pointer<wl_listener> pointer;

    public Listener() {
        this.pointer = Pointer.malloc(wl_listener.SIZE,
// Path: stubs-server/src/main/java/org/freedesktop/wayland/server/jaccall/wl_listener.java
// @Struct({
//                 @Field(name = "link",
//                        type = CType.STRUCT,
//                        dataType = wl_list.class),
//                 @Field(name = "notify$",
//                        type = CType.POINTER,
//                        dataType = wl_notify_func_t.class)
//         })
// public final class wl_listener extends wl_listener_Jaccall_StructType {
// }
// 
// Path: stubs-server/src/main/java/org/freedesktop/wayland/server/jaccall/wl_notify_func_t.java
// @Functor
// public interface wl_notify_func_t {
//     void invoke(@Ptr(wl_listener.class) long listener,
//                 @Ptr(void.class) long data);
// }
// 
// Path: stubs-shared/src/main/java/org/freedesktop/wayland/util/ObjectCache.java
// public class ObjectCache {
//     private static final Map<Long, Object> MAPPED_OBJECTS = new HashMap<>();
// 
//     /**
//      * Retrieve a POJO that is mapped to a native pointer. This method should be used to easily retrieve a POJO with a
//      * native context. This method will only return a POJO if it was previously cached with a call to {@link #store(long, Object)}
//      *
//      * @param pointer The pointer of the associated object.
//      * @param <T>     The type of the POJO to cast.
//      *
//      * @return The cached object.
//      */
//     public static <T> T from(final long pointer) {
//         if (pointer == 0L) {
//             return null;
//         }
//         return (T) MAPPED_OBJECTS.get(pointer);
//     }
// 
//     /**
//      * Maps a native pointer to a POJO. This method should be used to easily store a POJO with a native context.
//      *
//      * @param pointer The pointer of the associated object.
//      * @param object  The object to cache.
//      */
//     public static void store(final long pointer,
//                              final Object object) {
//         final Object oldValue = MAPPED_OBJECTS.put(pointer,
//                                                    object);
//         if (oldValue != null) {
//             //put it back!
//             MAPPED_OBJECTS.put(pointer,
//                                oldValue);
//             throw new IllegalStateException(String.format("Can not re-map existing pointer.\n" +
//                                                           "Pointer=%s\n" +
//                                                           "old value=%s" +
//                                                           "\nnew value=%s",
//                                                           pointer,
//                                                           oldValue,
//                                                           object));
//         }
//     }
// 
//     /**
//      * Remove a mapped POJO. This method should be used when the native context of the POJO is no longer valid.
//      *
//      * @param pointer The pointer of the associated object.
//      */
//     public static <T> T remove(final long pointer) {
//         return (T) MAPPED_OBJECTS.remove(pointer);
//     }
// }


// Path: stubs-server/src/main/java/org/freedesktop/wayland/server/Listener.java
import org.freedesktop.jaccall.Pointer;
import org.freedesktop.wayland.server.jaccall.Pointerwl_notify_func_t;
import org.freedesktop.wayland.server.jaccall.WaylandServerCore;
import org.freedesktop.wayland.server.jaccall.wl_listener;
import org.freedesktop.wayland.server.jaccall.wl_notify_func_t;
import org.freedesktop.wayland.util.ObjectCache;
import static org.freedesktop.jaccall.Pointer.ref;

//Copyright 2015 Erik De Rijcke
//
//Licensed under the Apache License,Version2.0(the"License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing,software
//distributed under the License is distributed on an"AS IS"BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
package org.freedesktop.wayland.server;



/**
 * A single listener for Wayland signals
 * <p/>
 * {@code Listener} provides the means to listen for {@code wl_signal} notifications. Many
 * Wayland objects use {@code Listener} for notification of significant events like
 * object destruction.
 * <p/>
 * Clients should create {@code Listener} objects manually and can register them as
 * listeners to signals using #wl_signal_add, assuming the signal is
 * directly accessible. For opaque structs like wl_event_loop, adding a
 * listener should be done through provided accessor methods. A listener can
 * only listen to one signal at a time.
 */
abstract class Listener {

    private static final Pointer<wl_notify_func_t> WL_NOTIFY_FUNC = Pointerwl_notify_func_t.nref((wl_notify_func_t) (listenerPointer, data) -> {
        final Listener listener = ObjectCache.from(listenerPointer);
        listener.handle();
    });

    public final Pointer<wl_listener> pointer;

    public Listener() {
        this.pointer = Pointer.malloc(wl_listener.SIZE,
                                      wl_listener.class);