* (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
*
*/
-#include <stdlib.h>
-// 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 ##################################################################
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;
// 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)
ORTEDomain *d;
const char *topic;
const char *typeName;
- char *buffer;
+ void *buffer;
NtpTime persistence;
int strength;
int flag_ok = 0;
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");
p = ORTEPublicationCreate(d,
topic,
typeName,
- (void *) buffer,
+ buffer,
&persistence,
strength,
sendCallBack, // BUDE NULL!!
- j_instance,
+ NULL,
NULL);
if(p == 0)
{
//
if (flag_ok == 0)
{
- // free memory
- if(buffer != 0) free(buffer);
return 0;
}
- return ((jint) p);
+ return ((jlong) p);
}