本文整理匯總了Java中com.sun.jna.Callback類的典型用法代碼示例。如果您正苦於以下問題:Java Callback類的具體用法?Java Callback怎麽用?Java Callback使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Callback類屬於com.sun.jna包,在下文中一共展示了Callback類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connect
import com.sun.jna.Callback; //導入依賴的package包/類
/**
* 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();
}
示例2:
import com.sun.jna.Callback; //導入依賴的package包/類
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 */
);
示例3: createDestroyNotify
import com.sun.jna.Callback; //導入依賴的package包/類
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;
}
示例4: connect
import com.sun.jna.Callback; //導入依賴的package包/類
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;
}
示例5: connectNotify
import com.sun.jna.Callback; //導入依賴的package包/類
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);
}
示例6: disconnect
import com.sun.jna.Callback; //導入依賴的package包/類
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);
}
示例7: pin
import com.sun.jna.Callback; //導入依賴的package包/類
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;
}
示例8: unpin
import com.sun.jna.Callback; //導入依賴的package包/類
@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;
}
示例9: createDelegate
import com.sun.jna.Callback; //導入依賴的package包/類
private static ID createDelegate(String name, Pointer pointer, Callback callback) {
ID delegateClass = allocateObjcClassPair(getObjcClass("NSObject"), name);
if (!ID.NIL.equals(delegateClass)) {
if (!addMethod(delegateClass, pointer, callback, "[email protected]")) {
throw new RuntimeException("Cannot add observer method");
}
registerObjcClassPair(delegateClass);
}
return invoke(name, "new");
}
示例10: addFoundationMethod
import com.sun.jna.Callback; //導入依賴的package包/類
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!");
}
}
示例11: g_signal_connect_data
import com.sun.jna.Callback; //導入依賴的package包/類
NativeLong g_signal_connect_data(GObject obj, String signal, Callback callback, Pointer data,
GClosureNotify destroy_data, int connect_flags);
示例12: g_signal_connect
import com.sun.jna.Callback; //導入依賴的package包/類
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);
}
示例13: GCallback
import com.sun.jna.Callback; //導入依賴的package包/類
protected GCallback(NativeLong id, Callback cb) {
this.id = id != null ? id : new NativeLong(0);
this.cb = cb;
this.connected = this.id.intValue() != 0;
}
示例14: SignalCallback
import com.sun.jna.Callback; //導入依賴的package包/類
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));
}
}
示例15: connect
import com.sun.jna.Callback; //導入依賴的package包/類
public <T> void connect(Class<T> listenerClass, T listener, Callback cb) {
String signal = listenerClass.getSimpleName().toLowerCase().replaceAll("_", "-");
connect(signal, listenerClass, listener, cb);
}