Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Const for sonar.
[simgrid.git] / src / bindings / java / jmsg_process.cpp
index cfb82d645ac048db99fe6c4d1da51eada6643a18..7f6ee40993470f4d8453d23bff22996231e17895 100644 (file)
@@ -1,6 +1,6 @@
 /* Functions related to the java process instances.                         */
 
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
 
 /* 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. */
@@ -22,7 +22,7 @@ jfieldID jprocess_field_Process_name;
 jfieldID jprocess_field_Process_pid;
 jfieldID jprocess_field_Process_ppid;
 
-jobject jprocess_from_native(const simgrid::s4u::Actor* process)
+jobject jprocess_from_native(const_sg_actor_t process)
 {
   const simgrid::kernel::context::JavaContext* context =
       static_cast<simgrid::kernel::context::JavaContext*>(process->get_impl()->context_.get());
@@ -44,7 +44,7 @@ msg_process_t jprocess_to_native(jobject jprocess, JNIEnv* env)
   return (msg_process_t)(intptr_t)env->GetLongField(jprocess, jprocess_field_Process_bind);
 }
 
-void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env)
+void jprocess_bind(jobject jprocess, const_sg_actor_t process, JNIEnv* env)
 {
   env->SetLongField(jprocess, jprocess_field_Process_bind, (intptr_t)process);
 }
@@ -70,13 +70,14 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv* env, jobject
   jobject jprocess = jprocess_ref(jprocess_arg, env);
 
   /* Actually build the MSG process */
-  jstring jname         = (jstring)env->GetObjectField(jprocess, jprocess_field_Process_name);
-  const char* name      = env->GetStringUTFChars(jname, 0);
-  simgrid::simix::ActorCode function = [jprocess]() { simgrid::kernel::context::java_main_jprocess(jprocess); };
-  smx_actor_t self                   = SIMIX_process_self();
-  sg_host_t host                     = jhost_get_native(env, jhost);
-  smx_actor_t actor                  = simgrid::kernel::actor::simcall([name, function, host, self] {
-    return simgrid::kernel::actor::ActorImpl::create(std::move(name), std::move(function), nullptr, host, nullptr, self)
+  jstring jname     = (jstring)env->GetObjectField(jprocess, jprocess_field_Process_name);
+  const char* name  = env->GetStringUTFChars(jname, 0);
+  auto actor_code   = [jprocess]() { simgrid::kernel::context::java_main_jprocess(jprocess); };
+  smx_actor_t self  = SIMIX_process_self();
+  sg_host_t host    = jhost_get_native(env, jhost);
+  smx_actor_t actor = simgrid::kernel::actor::simcall([name, actor_code, host, self] {
+    return simgrid::kernel::actor::ActorImpl::create(std::move(name), std::move(actor_code), nullptr, host, nullptr,
+                                                     self)
         .get();
   });
   MSG_process_yield();
@@ -110,7 +111,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_killAll(JNIEnv* env, jclass
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jclass cls, jint pid)
 {
-  msg_process_t process = MSG_process_from_PID(pid);
+  auto const* process = MSG_process_from_PID(pid);
 
   if (not process) {
     jxbt_throw_process_not_found(env, std::string("PID = ") + std::to_string(static_cast<int>(pid)));
@@ -129,12 +130,12 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID(JNIEnv * env, jcl
 
 JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_nativeGetPID(JNIEnv* env, jobject jprocess)
 {
-  msg_process_t process = jprocess_to_native(jprocess, env);
+  const_sg_actor_t process = jprocess_to_native(jprocess, env);
   return MSG_process_get_PID(process);
 }
 
 JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject jname) {
-  msg_process_t process = jprocess_to_native(jprocess, env);
+  const_sg_actor_t process = jprocess_to_native(jprocess, env);
 
   if (not process) {
     jxbt_throw_notbound(env, "process", jprocess);