Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
java: obey our coding standard
[simgrid.git] / src / bindings / java / JavaContext.hpp
index 164732a..2724033 100644 (file)
@@ -1,5 +1,6 @@
-/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Context switching within the JVM.                                        */
+
+/* Copyright (c) 2009-2018. 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. */
@@ -7,40 +8,38 @@
 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
 
+#include <functional>
 #include <jni.h>
 
-#include <xbt/misc.h>
-#include <simgrid/simix.h>
-#include <xbt/xbt_os_thread.h>
-
+#include "simgrid/simix.h"
 #include "src/simix/smx_private.hpp"
+#include "xbt/xbt_os_thread.h"
 
-#include "jmsg.h"
-#include "jmsg_process.h"
+#include "jmsg.hpp"
 
 namespace simgrid {
-namespace java {
+namespace kernel {
+namespace context {
 
 class JavaContext;
 class JavacontextFactory;
 
-class JavaContext : public simgrid::simix::Context {
+class JavaContext : public simgrid::kernel::context::Context {
 public:
   // The java process instance bound with the msg process structure:
-  jobject jprocess = nullptr;
+  jobject jprocess_ = nullptr;
   // JNI interface pointer associated to this thread:
-  JNIEnv *jenv = nullptr;
-  xbt_os_thread_t thread = nullptr;
-  // Sempahore used to schedule/yield the process:
-  xbt_os_sem_t begin = nullptr;
+  JNIEnv* jenv_           = nullptr;
+  xbt_os_thread_t thread_ = nullptr;
+  // Sempahore used to schedule/yield to the process:
+  xbt_os_sem_t begin_ = nullptr;
   // Semaphore used to schedule/unschedule the process:
-  xbt_os_sem_t end = nullptr;
-public:
+  xbt_os_sem_t end_ = nullptr;
+
   friend class JavaContextFactory;
-  JavaContext(xbt_main_func_t code,
-          int argc, char **argv,
+  JavaContext(std::function<void()> code,
           void_pfn_smxprocess_t cleanup_func,
-          smx_process_t process);
+          smx_actor_t process);
   ~JavaContext() override;
   void stop() override;
   void suspend() override;
@@ -49,22 +48,19 @@ private:
   static void* wrapper(void *data);
 };
 
-class JavaContextFactory : public simgrid::simix::ContextFactory {
+class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
 public:
   JavaContextFactory();
   ~JavaContextFactory() override;
   JavaContext* self() override;
-  JavaContext* create_context(
-    xbt_main_func_t, int, char **, void_pfn_smxprocess_t,
-    smx_process_t process
-    ) override;
+  JavaContext* create_context(std::function<void()> code,
+    void_pfn_smxprocess_t, smx_actor_t process) override;
   void run_all() override;
 };
 
-XBT_PRIVATE simgrid::simix::ContextFactory* java_factory();
-XBT_PRIVATE int java_main(int argc, char *argv[]);
+XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
+XBT_PRIVATE void java_main_jprocess(jobject process);
 
-}
-}
+}}} // namespace simgrid::kernel::context
 
 #endif                          /* !_XBT_CONTEXT_JAVA_H */