1 11 package org.eclipse.swt.internal; 12 13 14 25 26 public class Callback { 27 28 Object object; 29 String method, signature; 30 int argCount; 31 int address, errorResult; 32 boolean isStatic, isArrayBased; 33 34 static final String PTR_SIGNATURE = C.PTR_SIZEOF == 4 ? "I" : "J"; static final String SIGNATURE_0 = getSignature(0); 36 static final String SIGNATURE_1 = getSignature(1); 37 static final String SIGNATURE_2 = getSignature(2); 38 static final String SIGNATURE_3 = getSignature(3); 39 static final String SIGNATURE_4 = getSignature(4); 40 static final String SIGNATURE_N = "(["+PTR_SIGNATURE+")"+PTR_SIGNATURE; 42 53 public Callback (Object object, String method, int argCount) { 54 this (object, method, argCount, false); 55 } 56 57 71 public Callback (Object object, String method, int argCount, boolean isArrayBased) { 72 this (object, method, argCount, isArrayBased, 0); 73 } 74 75 91 public Callback (Object object, String method, int argCount, boolean isArrayBased, int errorResult) { 92 93 94 this.object = object; 95 this.method = method; 96 this.argCount = argCount; 97 this.isStatic = object instanceof Class ; 98 this.isArrayBased = isArrayBased; 99 this.errorResult = errorResult; 100 101 102 if (isArrayBased) { 103 signature = SIGNATURE_N; 104 } else { 105 switch (argCount) { 106 case 0: signature = SIGNATURE_0; break; case 1: signature = SIGNATURE_1; break; case 2: signature = SIGNATURE_2; break; case 3: signature = SIGNATURE_3; break; case 4: signature = SIGNATURE_4; break; default: 112 signature = getSignature(argCount); 113 } 114 } 115 116 117 address = bind (this, object, method, signature, argCount, isStatic, isArrayBased, errorResult); 118 } 119 120 134 static native synchronized int bind (Callback callback, Object object, String method, String signature, int argCount, boolean isStatic, boolean isArrayBased, int errorResult); 135 136 142 public void dispose () { 143 if (object == null) return; 144 unbind (this); 145 object = method = signature = null; 146 address = 0; 147 } 148 149 155 public int getAddress () { 156 return address; 157 } 158 159 164 public static native String getPlatform (); 165 166 177 public static native int getEntryCount (); 178 179 static String getSignature(int argCount) { 180 String signature = "("; for (int i = 0; i < argCount; i++) signature += PTR_SIGNATURE; 182 signature += ")" + PTR_SIGNATURE; return signature; 184 } 185 186 198 public static final native synchronized void setEnabled (boolean enable); 199 200 212 public static final native synchronized boolean getEnabled (); 213 214 222 static final void ignoreCallbacks (boolean ignore) { 223 setEnabled (!ignore); 224 } 225 226 234 public static final native synchronized void reset (); 235 236 241 static final native synchronized void unbind (Callback callback); 242 243 } 244 | Popular Tags |