Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge remote-tracking branch 'upstream/master' into issue95
[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 "src/kernel/context/ContextThread.hpp"
15
16 #include "jmsg.hpp"
17
18 namespace simgrid {
19 namespace kernel {
20 namespace context {
21
22 class JavaContext;
23 class JavacontextFactory;
24
25 class JavaContext : public SerialThreadContext {
26 public:
27   // The java process instance bound with the msg process structure:
28   jobject jprocess_ = nullptr;
29   // JNI interface pointer associated to this thread:
30   JNIEnv* jenv_           = nullptr;
31
32   friend class JavaContextFactory;
33   JavaContext(std::function<void()>&& code, actor::ActorImpl* actor);
34
35   void start_hook() override;
36   void stop_hook() override;
37 };
38
39 class JavaContextFactory : public ContextFactory {
40 public:
41   JavaContextFactory();
42   ~JavaContextFactory() override;
43   Context* create_context(std::function<void()>&& code, actor::ActorImpl* actor) override;
44   void run_all() override;
45 };
46
47 XBT_PRIVATE ContextFactory* java_factory();
48 XBT_PRIVATE void java_main_jprocess(jobject process);
49
50 } // namespace context
51 } // namespace kernel
52 } // namespace simgrid
53
54 #endif /* SIMGRID_JAVA_JAVA_CONTEXT_HPP */