Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
f1e05703781b54c0430f62f31cbcb29feb2aaba4
[simgrid.git] / src / bindings / java / JavaContext.hpp
1 /* Context switching within the JVM.                                        */
2
3 /* Copyright (c) 2009-2019. 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 #include "src/simix/smx_private.hpp"
17
18 #include "jmsg.hpp"
19
20 namespace simgrid {
21 namespace kernel {
22 namespace context {
23
24 class JavaContext;
25 class JavacontextFactory;
26
27 class JavaContext : public simgrid::kernel::context::SerialThreadContext {
28 public:
29   // The java process instance bound with the msg process structure:
30   jobject jprocess_ = nullptr;
31   // JNI interface pointer associated to this thread:
32   JNIEnv* jenv_           = nullptr;
33
34   friend class JavaContextFactory;
35   JavaContext(std::function<void()> code,
36           void_pfn_smxprocess_t cleanup_func,
37           smx_actor_t process);
38
39   void start_hook() override;
40   void stop_hook() override;
41 };
42
43 class JavaContextFactory : public simgrid::kernel::context::ContextFactory {
44 public:
45   JavaContextFactory();
46   ~JavaContextFactory() override;
47   JavaContext* create_context(std::function<void()> code,
48     void_pfn_smxprocess_t, smx_actor_t process) override;
49   void run_all() override;
50 };
51
52 XBT_PRIVATE simgrid::kernel::context::ContextFactory* java_factory();
53 XBT_PRIVATE void java_main_jprocess(jobject process);
54
55 }}} // namespace simgrid::kernel::context
56
57 #endif                          /* !_XBT_CONTEXT_JAVA_H */