Java 类com.sun.jna.Callback 实例源码

项目:gstreamer1.x-java    文件:Bus.java   
/**
 * Connects a callback to a signal.
 * <p>
 * This differs to {@link GObject#connect} in that it hooks up Bus signals
 * to the sync callback, not the generic GObject signal mechanism.
 * 
 * @param signal the name of the signal to connect to.
 * @param listenerClass the class of the {@code listener}
 * @param listener the listener to associate with the {@code callback}
 * @param callback the callback to call when the signal is emitted.
 */
@Override
public synchronized <T> void connect(String signal, Class<T> listenerClass, T listener,
        final Callback callback) {
    if (listenerClass.getEnclosingClass() != Bus.class) {
        super.connect(signal, listenerClass, listener, callback);
        return;
    }
    MessageType type = MessageType.forName(signal);
    if (type == MessageType.UNKNOWN && "message".equals(signal)) {
        type = MessageType.ANY;
    }
    if (type == MessageType.UNKNOWN) {
        throw new IllegalArgumentException("Illegal signal: " + signal);
    }
    final Map<Class<?>, Map<Object, MessageProxy>> signals = getListenerMap();
    Map<Object, MessageProxy> m = signals.get(type);
    if (m == null) {
        m = new HashMap<Object, MessageProxy>();
        signals.put(listenerClass, m);
    }
    MessageProxy proxy = new MessageProxy(type, (BusCallback) callback);
    m.put(listener, proxy);
    messageProxies.add(proxy);

    addWatch();
}
项目:gst1-java-core    文件:Bus.java   
/**
 * Connects a callback to a signal.
 * <p>
 * This differs to {@link GObject#connect} in that it hooks up Bus signals
 * to the sync callback, not the generic GObject signal mechanism.
 * 
 * @param signal the name of the signal to connect to.
 * @param listenerClass the class of the {@code listener}
 * @param listener the listener to associate with the {@code callback}
 * @param callback the callback to call when the signal is emitted.
 */
@Override
public synchronized <T> void connect(String signal, Class<T> listenerClass, T listener,
        final Callback callback) {
    if (listenerClass.getEnclosingClass() != Bus.class) {
        super.connect(signal, listenerClass, listener, callback);
        return;
    }
    MessageType type = MessageType.forName(signal);
    if (type == MessageType.UNKNOWN && "message".equals(signal)) {
        type = MessageType.ANY;
    }
    if (type == MessageType.UNKNOWN) {
        throw new IllegalArgumentException("Illegal signal: " + signal);
    }
    final Map<Class<?>, Map<Object, MessageProxy>> signals = getListenerMap();
    Map<Object, MessageProxy> m = signals.get(type);
    if (m == null) {
        m = new HashMap<Object, MessageProxy>();
        signals.put(listenerClass, m);
    }
    MessageProxy proxy = new MessageProxy(type, (BusCallback) callback);
    m.put(listener, proxy);
    messageProxies.add(proxy);

    addWatch();
}
项目:rutoken-demobank-android    文件:Pkcs11.java   
NativeLong C_OpenSession
(
        NativeLong            slotID,        /* the slot's ID */
        NativeLong            flags,         /* from CK_SESSION_INFO */
        Pointer               pApplication,  /* passed to callback */
        Callback              Notify,        /* callback function */
        NativeLongByReference phSession      /* gets session handle */
);
项目:java-gobject    文件:GlibRuntime.java   
public static final GlibAPI.GDestroyNotify createDestroyNotify(Callback callback) {
    if (callback == null)
        return null;

    final CallbackData data = new CallbackData();
    GlibAPI.GDestroyNotify destroy = new GlibAPI.GDestroyNotify() {
        public void callback(Pointer ignored) {
            outstandingCallbacks.remove(data);
        }
    };
    data.callback = callback;
    data.destroy = destroy;
    outstandingCallbacks.add(data);
    return destroy;
}
项目:java-gobject    文件:GObject.java   
public synchronized long connect(String signal, Callback closure) {
    NativeLong connectID = GSignalAPI.gsignal.g_signal_connect_data(GObject.this, signal, closure, null, null, 0);
    if (connectID.intValue() == 0) {
        throw new IllegalArgumentException(String.format("Failed to connect signal '%s'", signal));
    }
    long id = connectID.longValue();
    signalHandlers.put(id, closure);
    return id;
}
项目:java-gobject    文件:GObject.java   
public synchronized long connectNotify(final String propName, final Callback callback) {
    /*
     * FIXME - need to hold this trampoline's lifecycle to the signal
     * connection
     */
    NotifyCallback trampoline = new NotifyCallback() {

        public void onNotify(GObject object, GParamSpec param, Pointer data) {
            Method[] methods = callback.getClass().getDeclaredMethods();
            if (methods.length != 1)
                throw new RuntimeException(String.format("Callback %s must declare exactly one method", callback
                        .getClass()));
            Method meth = methods[0];
            meth.setAccessible(true);
            Class<?>[] params = meth.getParameterTypes();
            if (params.length != 2)
                throw new RuntimeException(String.format("Callback %s entry must have exactly two parameters",
                        callback.getClass()));
            Object propValue = get(propName);
            try {
                methods[0].invoke(callback, new Object[] { object, propValue });
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    return connect("notify::" + propName, trampoline);
}
项目:java-gobject    文件:GObject.java   
public synchronized void disconnect(long id) {
    Callback cb = signalHandlers.get(id);
    if (cb == null)
        throw new IllegalArgumentException("Invalid signal handler id:" + id);
    GSignalAPI.gsignal.g_signal_handler_disconnect(GObject.this, new NativeLong(id));
    signalHandlers.remove(id);
}
项目:process    文件:PinnableCallback.java   
public static <C extends Callback> C pin(final C callback, final IPinListener<C> listener) {
  synchronized (pin_lock) {
    pinned.add(callback);
  }

  synchronized (listeners_lock) {
    if (listener != null) {
      listeners.put(callback, listener);
    }
  }

  return callback;
}
项目:process    文件:PinnableCallback.java   
@SuppressWarnings("unchecked")
public static <C extends Callback> C unpin(final C callback) {
  if (callback == null) {
    return null;
  }

  final IPinListener<C> listener;

  synchronized (pin_lock) {
    pinned.remove(callback);
  }

  synchronized (listeners_lock) {
    listener = (IPinListener<C>)listeners.remove(callback);
  }

  if (listener != null) {
    if (listener.unpinned(callback)) {
      if (callback instanceof PinnableCallback) {
        ((PinnableCallback)callback).dispose();
      }
    }
    //If the listener returns false, then we do not
    //explicitly call dispose on the callback -- the user will
    //need to take care of that himself.
  } else {
    if (callback instanceof PinnableCallback) {
      ((PinnableCallback)callback).dispose();
    }
  }

  return callback;
}
项目:intellij-ce-playground    文件:MacFileChooserDialogImpl.java   
private static void addFoundationMethod(@NotNull ID delegate, @NotNull String selector, @NotNull Callback callback, @NotNull String types) {
  if (!Foundation.addMethod(delegate, Foundation.createSelector(selector), callback, types)) {
    throw new RuntimeException("Unable to add method " + selector + " to objective-c delegate class!");
  }
}
项目:gstreamer1.x-java    文件:GSignalAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:gstreamer1.x-java    文件:GObjectAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:gstreamer1.x-java    文件:GObject.java   
protected NativeLong g_signal_connect(String signal, Callback callback) {
    logger.entering("GObject", "g_signal_connect", new Object[] { signal, callback });
    return GOBJECT_API.g_signal_connect_data(this, signal, callback, null, null, 0);
}
项目:gstreamer1.x-java    文件:GObject.java   
protected GCallback(NativeLong id, Callback cb) {
    this.id = id != null ? id : new NativeLong(0);
    this.cb = cb;
    this.connected = this.id.intValue() != 0;
}
项目:gstreamer1.x-java    文件:GObject.java   
protected SignalCallback(String signal, Callback cb) {
    super(g_signal_connect(signal, cb), cb);
    if (!connected) {
        throw new IllegalArgumentException(String.format("Failed to connect signal '%s'", signal));
    }
}
项目:gstreamer1.x-java    文件:GObject.java   
public <T> void connect(Class<T> listenerClass, T listener, Callback cb) {
    String signal = listenerClass.getSimpleName().toLowerCase().replaceAll("_", "-");
    connect(signal, listenerClass, listener, cb);
}
项目:gstreamer1.x-java    文件:GObject.java   
public synchronized <T> void connect(String signal, Class<T> listenerClass, T listener, Callback cb) {
    addCallback(listenerClass, listener, new SignalCallback(signal, cb));
}
项目:gst1-java-core    文件:GSignalAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:gst1-java-core    文件:GObjectAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:gst1-java-core    文件:GObject.java   
protected NativeLong g_signal_connect(String signal, Callback callback) {
    logger.entering("GObject", "g_signal_connect", new Object[] { signal, callback });
    return GOBJECT_API.g_signal_connect_data(this, signal, callback, null, null, 0);
}
项目:gst1-java-core    文件:GObject.java   
protected GCallback(NativeLong id, Callback cb) {
    this.id = id != null ? id : new NativeLong(0);
    this.cb = cb;
    this.connected = this.id.intValue() != 0;
}
项目:gst1-java-core    文件:GObject.java   
protected SignalCallback(String signal, Callback cb) {
    super(g_signal_connect(signal, cb), cb);
    if (!connected) {
        throw new IllegalArgumentException(String.format("Failed to connect signal '%s'", signal));
    }
}
项目:gst1-java-core    文件:GObject.java   
public <T> void connect(Class<T> listenerClass, T listener, Callback cb) {
    String signal = listenerClass.getSimpleName().toLowerCase().replaceAll("_", "-");
    connect(signal, listenerClass, listener, cb);
}
项目:gst1-java-core    文件:GObject.java   
public synchronized <T> void connect(String signal, Class<T> listenerClass, T listener, Callback cb) {
    Native.setCallbackThreadInitializer(cb, cbi);
    addCallback(listenerClass, listener, new SignalCallback(signal, cb));
}
项目:mr4c    文件:JnaUtils.java   
public static void protectCallback(Object scope, Callback cb) {
    s_cbProt.protect(scope,cb);
}
项目:java-gobject    文件:GSignalAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:java-gobject    文件:GObjectAPI.java   
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
项目:process    文件:PinnableCallback.java   
public static <C extends Callback> C pin(final C callback) {
  return pin(callback, null);
}
项目:process    文件:PinnableCallback.java   
public static <C extends Callback> void dispose(final Callback callback) {
  if (callback != null && (callback instanceof PinnableCallback)) {
    ((PinnableCallback)callback).dispose();
    return;
  }
}
项目:jchai3d    文件:JDriverSensoray626.java   
public void    S626_SetErrCallback          (long hbd,
CallbackFPTR_ERR Callback );
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_create_pool_ledger_config(int command_handle, String config_name, String config, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_open_pool_ledger(int command_handle, String config_name, String config, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_refresh_pool_ledger(int command_handle, int handle, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_close_pool_ledger(int command_handle, int handle, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_delete_pool_ledger_config(int command_handle, String config_name, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_create_wallet(int command_handle, String pool_name, String name, String xtype, String config, String credentials, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_open_wallet(int command_handle, String name, String runtime_config, String credentials, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_close_wallet(int command_handle, int handle, Callback cb);
项目:indy-sdk-java    文件:LibSovrin.java   
public int sovrin_delete_wallet(int command_handle, String name, String credentials, Callback cb);