X-Git-Url: https://rtime.felk.cvut.cz/gitweb/orte.git/blobdiff_plain/3b7435b13a7df0f58e75eeb0fca137ad0fff879c..51bf20f848625b4b9ec02dc016537945efc21a02:/orte/libjorte/JORTEPublicationCreate.c diff --git a/orte/libjorte/JORTEPublicationCreate.c b/orte/libjorte/JORTEPublicationCreate.c index c4595fc..b2b5876 100644 --- a/orte/libjorte/JORTEPublicationCreate.c +++ b/orte/libjorte/JORTEPublicationCreate.c @@ -7,6 +7,7 @@ * (by command 'javah -jni class_with_native_function') * * @author Lukas Pokorny (lukas_pokorny@centrum.cz) + * @author Martin Vajnar (martin.vajnar@gmail.com) * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz) * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org) * @author dedication to Kj @@ -25,13 +26,7 @@ * */ -#include -// origin orte headers -#include "orte.h" -// pregenerated header -#include "jorte/org_ocera_orte_Publication.h" -#include "jorte/jorte_protos_api.h" -#include "jorte/4all.h" +#include "jorte/jorte.h" // ### DOCASNE ################################################################## @@ -41,15 +36,13 @@ int counter = 0; void sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) { - char *instance=(char*)vinstance; printf(":c: zacatek sendCallBack()..\n"); switch (info->status) { case NEED_DATA: - printf(":c:PUB: Sampling publication, count %d\n", counter); + printf(":c:PUB: Sampling publication, count %d\n", counter++); printf(":c:PUB: !! DOCASNE - ZRUSIT!! - callback() u Publishera \n"); - sprintf(instance,"Hello Universe! (%d)",counter++); break; case CQL: //criticalQueueLevel break; @@ -61,14 +54,13 @@ sendCallBack(const ORTESendInfo *info,void *vinstance, void *sendCallBackParam) // native method -JNIEXPORT jint JNICALL +JNIEXPORT jlong JNICALL Java_org_ocera_orte_Publication_jORTEPublicationCreate (JNIEnv *env , jobject obj, - jint dom_handle, + jlong dom_handle, jstring j_topic, jstring j_type_name, - jint jbufflen, jobject j_instance, jobject j_persistence, jint j_strength) @@ -77,7 +69,7 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate ORTEDomain *d; const char *topic; const char *typeName; - char *buffer; + void *buffer; NtpTime persistence; int strength; int flag_ok = 0; @@ -118,8 +110,8 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate persistence = getNtpTime(env, j_persistence); // get strenght strength = (int) j_strength; - // create buffer - buffer = (char*) malloc((int32_t) jbufflen); + // get direct ByteBuffer pointer from Java + buffer = (*env)->GetDirectBufferAddress(env, j_instance); if(buffer == 0) { printf(":!c: buffer create failed! \n"); @@ -129,11 +121,11 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate p = ORTEPublicationCreate(d, topic, typeName, - (void *) buffer, + buffer, &persistence, strength, sendCallBack, // BUDE NULL!! - j_instance, + NULL, NULL); if(p == 0) { @@ -150,10 +142,8 @@ Java_org_ocera_orte_Publication_jORTEPublicationCreate // if (flag_ok == 0) { - // free memory - if(buffer != 0) free(buffer); return 0; } - return ((jint) p); + return ((jlong) p); }