/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include <xbt/log.h>
+#include <xbt/str.h>
+#include <xbt/sysdep.h>
+
+#include <simgrid/msg.h>
+#include <simgrid/s4u/host.hpp>
+
#include "jmsg.h"
#include "jmsg_host.h"
#include "jmsg_task.h"
#include "jmsg_process.h"
#include "jxbt_utilities.h"
-#include <simgrid/msg.h>
-
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
static jmethodID jtask_method_Comm_constructor;
jdouble jflopsAmount, jdouble jbytesAmount)
{
msg_task_t task; /* the native task to create */
- const char *name = NULL; /* the name of the task */
+ const char *name = nullptr; /* the name of the task */
if (jflopsAmount < 0) {
jxbt_throw_illegal(env, bprintf("Task flopsAmount (%f) cannot be negative", (double) jflopsAmount));
}
/* create the task */
- task = MSG_task_create(name, (double) jflopsAmount, (double) jbytesAmount, NULL);
+ task = MSG_task_create(name, (double) jflopsAmount, (double) jbytesAmount, nullptr);
if (jname)
env->ReleaseStringUTFChars(jname, name);
/* sets the task name */
/* get the C string from the java string */
name = env->GetStringUTFChars(jname, 0);
- task = MSG_parallel_task_create(name, host_count, hosts, computeDurations, messageSizes, NULL);
+ task = MSG_parallel_task_create(name, host_count, hosts, computeDurations, messageSizes, nullptr);
env->ReleaseStringUTFChars(jname, name);
/* sets the task name */
if (!task) {
jxbt_throw_notbound(env, "task", jtask);
- return NULL;
+ return nullptr;
}
return env->NewStringUTF(MSG_task_get_name(task));
if (!task) {
jxbt_throw_notbound(env, "task", jtask);
- return NULL;
+ return nullptr;
}
process = MSG_task_get_sender(task);
- if (process == NULL) {
- return NULL;
+ if (process == nullptr) {
+ return nullptr;
}
return (jobject) native_to_java_process(process);
}
if (!task) {
jxbt_throw_notbound(env, "task", jtask);
- return NULL;
+ return nullptr;
}
host = MSG_task_get_source(task);
- if (host == NULL) {
- return NULL;
+ if (host == nullptr) {
+ return nullptr;
}
if (!host->extension(JAVA_HOST_LEVEL)) {
jxbt_throw_jni(env, "MSG_task_get_source() failed");
- return NULL;
+ return nullptr;
}
return (jobject) host->extension(JAVA_HOST_LEVEL);
JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls, jstring jalias, jdouble jtimeout,
jobject jhost)
{
- msg_error_t rv;
- msg_task_t *task = xbt_new(msg_task_t,1);
- *task = NULL;
+ msg_task_t task = nullptr;
- msg_host_t host = NULL;
+ msg_host_t host = nullptr;
jobject jtask_global, jtask_local;
- const char *alias;
if (jhost) {
host = jhost_get_native(env, jhost);
if (!host) {
jxbt_throw_notbound(env, "host", jhost);
- return NULL;
+ return nullptr;
}
}
- alias = env->GetStringUTFChars(jalias, 0);
- rv = MSG_task_receive_ext(task, alias, (double) jtimeout, host);
+ const char *alias = env->GetStringUTFChars(jalias, 0);
+ msg_error_t rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
if (env->ExceptionOccurred())
- return NULL;
+ return nullptr;
if (rv != MSG_OK) {
jmsg_throw_status(env,rv);
- return NULL;
+ return nullptr;
}
- jtask_global = (jobject) MSG_task_get_data(*task);
+ jtask_global = (jobject) MSG_task_get_data(task);
/* Convert the global ref into a local ref so that the JVM can free the stuff */
jtask_local = env->NewLocalRef(jtask_global);
env->DeleteGlobalRef(jtask_global);
- MSG_task_set_data(*task, NULL);
+ MSG_task_set_data(task, nullptr);
env->ReleaseStringUTFChars(jalias, alias);
- xbt_free(task);
-
return (jobject) jtask_local;
}
jclass comm_class;
//pointer to store the task object pointer.
msg_task_t *task = xbt_new(msg_task_t,1);
- *task = NULL;
+ *task = nullptr;
/* There should be a cache here */
comm_class = env->FindClass("org/simgrid/msg/Comm");
if (!comm_class) {
jxbt_throw_native(env,bprintf("fieldID or methodID or class not found."));
- return NULL;
+ return nullptr;
}
jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
if (!jcomm) {
jxbt_throw_native(env,bprintf("Can't create a Comm object."));
- return NULL;
+ return nullptr;
}
mailbox = env->GetStringUTFChars(jmailbox, 0);
{
msg_error_t rv;
msg_task_t *task = xbt_new(msg_task_t,1);
- *task = NULL;
+ *task = nullptr;
- msg_host_t host = NULL;
+ msg_host_t host = nullptr;
jobject jtask_global, jtask_local;
const char *alias;
if (!host) {
jxbt_throw_notbound(env, "host", jhost);
- return NULL;
+ return nullptr;
}
}
alias = env->GetStringUTFChars(jalias, 0);
rv = MSG_task_receive_ext_bounded(task, alias, (double) jtimeout, host, (double) rate);
if (env->ExceptionOccurred())
- return NULL;
+ return nullptr;
if (rv != MSG_OK) {
jmsg_throw_status(env,rv);
- return NULL;
+ return nullptr;
}
jtask_global = (jobject) MSG_task_get_data(*task);
/* Convert the global ref into a local ref so that the JVM can free the stuff */
jtask_local = env->NewLocalRef(jtask_global);
env->DeleteGlobalRef(jtask_global);
- MSG_task_set_data(*task, NULL);
+ MSG_task_set_data(*task, nullptr);
env->ReleaseStringUTFChars(jalias, alias);
jclass comm_class;
//pointer to store the task object pointer.
msg_task_t *task = xbt_new(msg_task_t,1);
- *task = NULL;
+ *task = nullptr;
/* There should be a cac hee */
comm_class = env->FindClass("org/simgrid/msg/Comm");
if (!comm_class) {
jxbt_throw_native(env,bprintf("fieldID or methodID or class not found."));
- return NULL;
+ return nullptr;
}
jobject jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
if (!jcomm) {
jxbt_throw_native(env,bprintf("Can't create a Comm object."));
- return NULL;
+ return nullptr;
}
mailbox = env->GetStringUTFChars(jmailbox, 0);
comm_class = env->FindClass("org/simgrid/msg/Comm");
- if (!comm_class) return NULL;
+ if (!comm_class) return nullptr;
jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
mailbox = env->GetStringUTFChars(jmailbox, 0);
env->ReleaseStringUTFChars(jmailbox, mailbox);
env->DeleteLocalRef(jcomm);
jxbt_throw_notbound(env, "task", jtask);
- return NULL;
+ return nullptr;
}
MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
comm = MSG_task_isend(task,mailbox);
env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
- env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(NULL));
+ env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(nullptr));
env->SetBooleanField(jcomm, jtask_field_Comm_receiving, JNI_FALSE);
env->ReleaseStringUTFChars(jmailbox, mailbox);
comm_class = env->FindClass("org/simgrid/msg/Comm");
- if (!comm_class) return NULL;
+ if (!comm_class) return nullptr;
jcomm = env->NewObject(comm_class, jtask_method_Comm_constructor);
mailbox = env->GetStringUTFChars(jmailbox, 0);
env->ReleaseStringUTFChars(jmailbox, mailbox);
env->DeleteLocalRef(jcomm);
jxbt_throw_notbound(env, "task", jtask);
- return NULL;
+ return nullptr;
}
MSG_task_set_data(task, (void *) env->NewGlobalRef(jtask));
comm = MSG_task_isend_bounded(task,mailbox,maxrate);
env->SetLongField(jcomm, jtask_field_Comm_bind, (jlong) (uintptr_t)(comm));
- env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(NULL));
+ env->SetLongField(jcomm, jtask_field_Comm_taskBind, (jlong) (uintptr_t)(nullptr));
env->SetBooleanField(jcomm, jtask_field_Comm_receiving, JNI_FALSE);
env->ReleaseStringUTFChars(jmailbox, mailbox);
/* Destroy the global ref so that the JVM can free the stuff */
env->DeleteGlobalRef(jtask_global);
- MSG_task_set_data(task, NULL);
+ MSG_task_set_data(task, nullptr);
MSG_task_destroy(task);
}
return (jboolean) rv;
}
-JNIEXPORT jint JNICALL Java_org_simgrid_msg_Task_listenFromHost(JNIEnv * env, jclass cls, jstring jalias, jobject jhost)
-{
- int rv;
- const char *alias;
-
- msg_host_t host = jhost_get_native(env, jhost);
-
- if (!host) {
- jxbt_throw_notbound(env, "host", jhost);
- return -1;
- }
- alias = env->GetStringUTFChars(jalias, 0);
- rv = MSG_task_listen_from_host(alias, host);
- env->ReleaseStringUTFChars(jalias, alias);
-
- return (jint) rv;
-}
-
JNIEXPORT jint JNICALL Java_org_simgrid_msg_Task_listenFrom(JNIEnv * env, jclass cls, jstring jalias)
{
int rv;