Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid into no_simix_global
[simgrid.git] / src / bindings / java / JavaContext.hpp
1 /* Context switching within the JVM.                                        */
2
3 /* Copyright (c) 2009-2021. The SimGrid Team. All rights reserved.          */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef SIMGRID_JAVA_JAVA_CONTEXT_HPP
9 #define SIMGRID_JAVA_JAVA_CONTEXT_HPP
10
11 #include <functional>
12 #include <jni.h>
13
14 #include "simgrid/simix.h"
15 #include "src/kernel/context/ContextThread.hpp"
16
17 #include "jmsg.hpp"
18
19 namespace simgrid {
20 namespace kernel {
21 namespace context {
22
23 class JavaContext;
24 class JavacontextFactory;
25
26 class JavaContext : public simgrid::kernel::context::SerialThreadContext {
27 public:
28   // The java process instance bound with the msg process structure:
29   jobject jprocess_ = nullptr;
30   // JNI interface pointer associated to this thread:
31   JNIEnv* jenv_           = nullptr;
32
33   friend class JavaContextFactory;
34   JavaContext(std::function<void()>&& code, smx_actor_t actor);
35
36   void start_hook() override;
37   void stop_hook() override;
38 };
39
40 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
41 public:
42   JavaContextFactory();
43   ~JavaContextFactory() override;
44   Context* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
45   void run_all() override;
46 };
47
48 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
49 XBT_PRIVATE void java_main_jprocess(jobject process);
50
51 }}} // namespace simgrid::kernel::context
52
53 #endif /* SIMGRID_JAVA_JAVA_CONTEXT_HPP */