comparison Plugin/JavaEnvironment.h @ 5:c8f19e93ff99

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Oct 2023 08:49:07 +0200
parents
children 1c407ba1d311
comparison
equal deleted inserted replaced
4:9032ffb3a7d5 5:c8f19e93ff99
1 /**
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6 /**
7 * Java plugin for Orthanc
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
9 *
10 * This program is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, either version 3 of the
13 * License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/
23
24
25 #pragma once
26
27 #include "JavaVirtualMachine.h"
28
29 #include <orthanc/OrthancCPlugin.h>
30
31 #include <vector>
32
33
34 class JavaEnvironment : public NonCopyable
35 {
36 private:
37 JavaVM *jvm_;
38 JNIEnv *env_;
39
40 public:
41 JavaEnvironment(JNIEnv* env);
42
43 JavaEnvironment(JavaVirtualMachine& jvm);
44
45 ~JavaEnvironment();
46
47 JNIEnv& GetValue();
48
49 void CheckException();
50
51 void ThrowException(const std::string& fqn,
52 const std::string& message);
53
54 void ThrowOrthancException(const std::string& message);
55
56 void ThrowOrthancException(OrthancPluginErrorCode code);
57
58 static void ThrowOrthancException(JNIEnv* env,
59 const std::string& message);
60
61 static void ThrowOrthancException(JNIEnv* env,
62 OrthancPluginErrorCode code);
63
64 void RegisterNatives(const std::string& fqn,
65 const std::vector<JNINativeMethod>& methods);
66
67 void RunGarbageCollector();
68
69 jclass FindClass(const std::string& fqn);
70
71 jclass GetObjectClass(jobject obj);
72
73 jmethodID GetMethodID(jclass c,
74 const std::string& method,
75 const std::string& signature);
76
77 jobject ConstructJavaWrapper(const std::string& fqn,
78 void* nativeObject);
79
80 jbyteArray ConstructByteArray(const size_t size,
81 const void* data);
82
83 jbyteArray ConstructByteArray(const std::string& data)
84 {
85 return ConstructByteArray(data.size(), data.c_str());
86 }
87
88 jobject ConstructEnumValue(const std::string& fqn,
89 int value);
90 };