int oms::Source::addInput(Source* inputSource) { ossim_int32 connectionIdx = -1; if(inputSource&&inputSource->getNativePointer()&&getNativePointer()) { connectionIdx = getNativePointer()->connectMyInputTo(inputSource->getNativePointer()); } return (connectionIdx >= 0); }
/** * public native void close(); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_close(void) { rendezvous *rp; KNI_StartHandles(1); KNI_DeclareHandle(thisObj); KNI_GetThisPointer(thisObj); rp = getNativePointer(thisObj); /* ignore if closed twice */ if (rp != NULL) { if (rp->sender == JVM_CurrentIsolateID() && rp->msg != INVALID_REFERENCE_ID) { /* we're the sender, make sure to clean out our message */ SNI_DeleteReference(rp->msg); rp->msg = INVALID_REFERENCE_ID; } rp->state = CLOSED; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); setNativePointer(thisObj, NULL); rp_decref(rp); } KNI_EndHandles(); KNI_ReturnVoid(); }
/* * Class: com_me_lodea_jcap_JCapSession * Method: setFilter * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_com_me_lodea_jcap_JCapSession_setFilter (JNIEnv* const env, const jobject obj, const jstring filter) { const jcap_state* self; jstring ifaceString; const char* ifaceName; char errorbuf[PCAP_ERRBUF_SIZE]; bpf_u_int32 net; bpf_u_int32 mask; int pcapResult; const char* filterUTF8; struct bpf_program bpfProg; self = getNativePointer(env, obj); if (self == NULL) { return; } ifaceString = getInterfaceString(env, obj); if (ifaceString == NULL) { return; } ifaceName = (*env)->GetStringUTFChars( env, ifaceString, NULL); if (ifaceName == NULL) { return; } pcapResult = pcap_lookupnet((char*)ifaceName, &net, &mask, errorbuf); (*env)->ReleaseStringUTFChars(env, ifaceString, ifaceName); if (pcapResult < 0) { throwJCapException(env, errorbuf); return; } filterUTF8 = (*env)->GetStringUTFChars(env, filter, NULL); if (filterUTF8 == NULL) { return; } pcapResult = pcap_compile(self->handle, &bpfProg, (char*)filterUTF8, 1, mask); (*env)->ReleaseStringUTFChars(env, filter, filterUTF8); if (pcapResult < 0) { throwJCapException(env, pcap_geterr(self->handle)); return; } pcapResult = pcap_setfilter(self->handle, &bpfProg); if (pcapResult < 0) { throwJCapException(env, pcap_geterr(self->handle)); return; } pcap_freecode(&bpfProg); }
/* * Class: com_me_lodea_jcap_JCapSession * Method: pcapClose * Signature: ()V */ JNIEXPORT void JNICALL Java_com_me_lodea_jcap_JCapSession_pcapClose (JNIEnv* const env, jobject const obj) { jcap_state* const self = getNativePointer(env, obj); if (self == NULL) { return; } pcap_close(self->handle); free(self); }
/** * public native boolean isOpen(); */ KNIEXPORT KNI_RETURNTYPE_BOOLEAN Java_com_sun_midp_links_Link_isOpen(void) { rendezvous *rp; jboolean retval; KNI_StartHandles(1); KNI_DeclareHandle(thisObj); KNI_GetThisPointer(thisObj); rp = getNativePointer(thisObj); if (rp == NULL) { retval = KNI_FALSE; } else { retval = (rp->state != CLOSED); } KNI_EndHandles(); KNI_ReturnBoolean(retval); }
/** * public static native int getRefCount(Link link); */ KNIEXPORT KNI_RETURNTYPE_INT Java_com_sun_midp_links_Utils_getRefCount(void) { int retval; KNI_StartHandles(1); KNI_DeclareHandle(linkObj); KNI_GetParameterAsObject(1, linkObj); if (KNI_IsNullHandle(linkObj)) { retval = 0; } else { rendezvous *rp = getNativePointer(linkObj); if (rp == NULL) { retval = 0; } else { retval = rp->refcount; } } KNI_EndHandles(); KNI_ReturnInt(retval); }
/* * Class: com_me_lodea_jcap_JCapSession * Method: capture * Signature: (I)I */ JNIEXPORT jint JNICALL Java_com_me_lodea_jcap_JCapSession_capture (JNIEnv* const env, jobject const obj, jint const maxPackets) { int result; callback_args args; const jcap_state* const self = getNativePointer(env, obj); if (self == NULL) { return -1; } args.env = env; args.jcap = obj; args.eventClass = (*env)->FindClass(env, "com/me/lodea/jcap/PacketEvent"); if (args.eventClass == NULL) { return -1; } args.eventCtorID = (*env)->GetMethodID(env, args.eventClass, "<init>", "(Lcom/me/lodea/jcap/JCapSession;JILjava/nio/ByteBuffer;)V"); if (args.eventCtorID == NULL) { return -1; } args.fireMethodID = (*env)->GetMethodID(env, (*env)->GetObjectClass(env, obj), "firePacketEvent", "(Lcom/me/lodea/jcap/PacketEvent;)V"); if (args.fireMethodID == NULL) { return -1; } result = pcap_dispatch(self->handle, maxPackets, packet_callback, (u_char*)&args); if (result < 0) { throwJCapException(env, pcap_geterr(self->handle)); } return result; }
/** * private static native void setLinks0(int isolateid, Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_setLinks0(void) { int targetIsolate; int len; int i; int ok = 1; rendezvous *rp; rendezvous **newrppa = NULL; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, linkArray); if (KNI_IsNullHandle(linkArray)) { len = 0; } else { len = KNI_GetArrayLength(linkArray); } for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); if (rp == NULL || rp->state == CLOSED) { ok = 0; KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } if (ok && portals == NULL) { portals = (portal *)pcsl_mem_malloc(JVM_MaxIsolates() * sizeof(portal)); if (portals == NULL) { ok = 0; KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portals[i].count = -1; portals[i].rppa = NULL; } } } if (ok && len > 0) { newrppa = (rendezvous **)pcsl_mem_malloc(len * sizeof(rendezvous *)); if (newrppa == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); ok = 0; } } if (ok) { portal *pp = &portals[targetIsolate]; portal_free(pp); /* at this point the portal's count is zero and rppa is null */ if (len > 0) { for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); /* rp not null, checked above */ newrppa[i] = rp; rp_incref(rp); } pp->count = len; pp->rppa = newrppa; } else if (KNI_IsNullHandle(linkArray)) { pp->count = -1; pp->rppa = NULL; } else { /* len == 0 */ pp->count = 0; pp->rppa = NULL; } midp_thread_signal(LINK_PORTAL_SIGNAL, targetIsolate, 0); } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * private native void send0(LinkMessage msg) * throws ClosedLinkException, * InterruptedIOException, * IOException; */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_send0(void) { rendezvous *rp; KNI_StartHandles(3); KNI_DeclareHandle(thisObj); KNI_DeclareHandle(messageObj); KNI_DeclareHandle(otherMessageObj); KNI_GetThisPointer(thisObj); KNI_GetParameterAsObject(1, messageObj); rp = getNativePointer(thisObj); if (rp == NULL) { if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } } else if (JVM_CurrentIsolateID() != rp->sender) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { switch (rp->state) { case IDLE: rp->msg = SNI_AddStrongReference(messageObj); rp->state = SENDING; midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case RECEIVING: rp->msg = SNI_AddStrongReference(messageObj); rp->state = RENDEZVOUS; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case SENDING: case RENDEZVOUS: midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case DONE: getReference(rp->msg, "send0/DONE", otherMessageObj); if (KNI_IsSameObject(messageObj, otherMessageObj)) { /* it's our message, finish processing */ SNI_DeleteReference(rp->msg); rp->msg = INVALID_REFERENCE_ID; rp->state = IDLE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); if (rp->retcode != OK) { KNI_ThrowNew(midpIOException, NULL); } } else { /* somebody else's message, just go back to sleep */ midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); } break; case CLOSED: setNativePointer(thisObj, NULL); if (rp->msg != INVALID_REFERENCE_ID) { /* a message was stranded in the link; clean it out */ SNI_DeleteReference(rp->msg); rp->msg = INVALID_REFERENCE_ID; } rp_decref(rp); if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } break; } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * private native void receive0(LinkMessage msg, Link link) * throws ClosedLinkException, * InterruptedIOException, * IOException; */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_Link_receive0(void) { rendezvous *rp; KNI_StartHandles(4); KNI_DeclareHandle(thisObj); KNI_DeclareHandle(recvMessageObj); KNI_DeclareHandle(sendMessageObj); KNI_DeclareHandle(linkObj); KNI_GetThisPointer(thisObj); KNI_GetParameterAsObject(1, recvMessageObj); KNI_GetParameterAsObject(2, linkObj); rp = getNativePointer(thisObj); if (rp == NULL) { if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } } else if (JVM_CurrentIsolateID() != rp->receiver) { KNI_ThrowNew(midpIllegalArgumentException, NULL); } else { jboolean ok; switch (rp->state) { case IDLE: rp->state = RECEIVING; midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case SENDING: getReference(rp->msg, "receive0/SENDING", sendMessageObj); ok = copy(sendMessageObj, recvMessageObj, linkObj); if (ok) { rp->retcode = OK; } else { rp->retcode = ERROR; KNI_ThrowNew(midpIOException, NULL); } rp->state = DONE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); break; case RENDEZVOUS: getReference(rp->msg, "receive0/RENDEZVOUS", sendMessageObj); ok = copy(sendMessageObj, recvMessageObj, linkObj); if (ok) { rp->retcode = OK; } else { rp->retcode = ERROR; KNI_ThrowNew(midpIOException, NULL); } rp->state = DONE; midp_thread_signal(LINK_READY_SIGNAL, (int)rp, 0); break; case RECEIVING: case DONE: midp_thread_wait(LINK_READY_SIGNAL, (int)rp, NULL); break; case CLOSED: setNativePointer(thisObj, NULL); rp_decref(rp); if (SNI_GetReentryData(NULL) == NULL) { KNI_ThrowNew(midpClosedLinkException, NULL); } else { KNI_ThrowNew(midpInterruptedIOException, NULL); } break; } } KNI_EndHandles(); KNI_ReturnVoid(); }
/** * Copies the contents of fromMsg to the contents of toMsg. Both must be * instances of LinkMessage. The toLink object must be an instance of Link. * It's filled in if the contents of fromMsg are a Link. Returns KNI_TRUE if * successful, otherwise KNI_FALSE. */ static jboolean copy(jobject fromMsg, jobject toMsg, jobject toLink) { jboolean retval; KNI_StartHandles(6); KNI_DeclareHandle(byteArrayClass); KNI_DeclareHandle(stringClass); KNI_DeclareHandle(linkClass); KNI_DeclareHandle(fromContents); KNI_DeclareHandle(newString); KNI_DeclareHandle(newByteArray); KNI_FindClass("[B", byteArrayClass); KNI_FindClass("java/lang/String", stringClass); KNI_FindClass("com/sun/midp/links/Link", linkClass); getContents(fromMsg, fromContents); if (KNI_IsInstanceOf(fromContents, byteArrayClass)) { /* do a byte array copy */ jint fromOffset; jint fromLength; getRange(fromMsg, &fromOffset, &fromLength); SNI_NewArray(SNI_BYTE_ARRAY, fromLength, newByteArray); if (KNI_IsNullHandle(newByteArray)) { retval = KNI_FALSE; } else { KNI_GetRawArrayRegion(fromContents, fromOffset, fromLength, SNI_GetRawArrayPointer(newByteArray)); setContents(toMsg, newByteArray); setRange(toMsg, 0, fromLength); retval = KNI_TRUE; } } else if (KNI_IsInstanceOf(fromContents, stringClass)) { /* do a string copy */ jchar *buf; jsize slen = KNI_GetStringLength(fromContents); SNI_NewArray(SNI_BYTE_ARRAY, slen*sizeof(jchar), newByteArray); if (KNI_IsNullHandle(newByteArray)) { retval = KNI_FALSE; } else { buf = SNI_GetRawArrayPointer(newByteArray); KNI_GetStringRegion(fromContents, 0, slen, buf); KNI_NewString(buf, slen, newString); setContents(toMsg, newString); retval = KNI_TRUE; } } else if (KNI_IsInstanceOf(fromContents, linkClass)) { /* copy the link */ rendezvous *rp = getNativePointer(fromContents); setNativePointer(toLink, rp); rp_incref(rp); setContents(toMsg, toLink); retval = KNI_TRUE; } else { retval = KNI_FALSE; } KNI_EndHandles(); return retval; }
PurpleDnsQueryData * getNativeDnsData(JNIEnv *env, jobject object) { return (PurpleDnsQueryData*) getNativePointer(env, object); }