Ocean
BaseJni.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_BASE_JNI_BASE_JNI_H
9 #define META_OCEAN_BASE_JNI_BASE_JNI_H
10 
11 #include "ocean/base/jni/JNI.h"
12 
13 #include "ocean/base/Messenger.h"
14 
15 #include <jni.h>
16 
17 /**
18  * Java native interface function to initialize the Ocean Framework.
19  * Several individual message output types can be specified and combined:
20  * - "OUTPUT_STANDARD": To write all messages to the standard output (e.g., std::cout on desktop platforms, or Android logcat on Android platforms).
21  * - "OUTPUT_QUEUED": To queue all messages and to explicitly pop the messages later (e.g., to display messages in a debug window).
22  * - "<filename>": To write all messages to a define file.
23  * @param env The JNI environment, must be valid
24  * @param javaThis The JNI Base object
25  * @param messageOutputType The type of the message output to be used, empty to use 'OUTPUT_STANDARD'
26  * @return True, if succeeded
27  * @ingroup basejni
28  */
29 extern "C" jboolean Java_com_meta_ocean_base_BaseJni_initialize(JNIEnv* env, jobject javaThis, jstring messageOutputType);
30 
31 /**
32  * Java native interface function to initialize the Ocean Framework.
33  * @param env The JNI environment, must be valid
34  * @param javaThis The JNI Base object
35  * @param messageOutputType The type of the message output to be used.
36  * @param outputFile The name of the file to which messages will be written, 'messageOutputType' must contain 'OUTPUT_FILE', empty otherwise
37  * @return True, if succeeded
38  * @ingroup basejni
39  */
40 extern "C" jboolean Java_com_meta_ocean_base_BaseJni_initializeWithMessageOutput(JNIEnv* env, jobject javaThis, jint messageOutputType, jstring outputFile);
41 
42 /**
43  * Java native interface function to set the current activity.
44  * @param env The JNI environment, must be valid
45  * @param javaThis The JNI Base object
46  * @param activity The current activity to be set or updated, can be nullptr to remove the previously set activity
47  * @return True, if succeeded
48  * @ingroup basejni
49  */
50 extern "C" jboolean Java_com_meta_ocean_base_BaseJni_setCurrentActivity(JNIEnv* env, jobject javaThis, jobject activity);
51 
52 /**
53  * Forces a specific number of processor cores.
54  * @param env The JNI environment
55  * @param javaThis The JNI object
56  * @param cores CPU cores to be forced during initialization
57  * @return True, if succeeded
58  * @ingroup basejni
59  */
60 extern "C" jboolean Java_com_meta_ocean_base_BaseJni_forceProcessorCoreNumber(JNIEnv* env, jobject javaThis, jint cores);
61 
62 /**
63  * Sets or changes the maximal capacity of the worker pool.
64  * @param env The JNI environment
65  * @param javaThis The JNI object
66  * @param capacity The maximal number of worker objects the worker pool may provide
67  * @return True, if succeeded
68  * @ingroup basejni
69  */
70 extern "C" jboolean Java_com_meta_ocean_base_BaseJni_setWorkerPoolCapacity(JNIEnv* env, jobject javaThis, jint capacity);
71 
72 /**
73  * Java native interface function to forward a debug message to the framework.
74  * @param env The JNI environment
75  * @param javaThis The JNI object
76  * @param message The debug message to forward
77  * @ingroup basejni
78  * @see Java_com_meta_ocean_base_BaseJni_information().
79  */
80 extern "C" void Java_com_meta_ocean_base_BaseJni_debug(JNIEnv* env, jobject javaThis, jstring message);
81 
82 /**
83  * Java native interface function to forward an information message to the framework.
84  * @param env The JNI environment
85  * @param javaThis The JNI object
86  * @param message The information message to forward
87  * @ingroup basejni
88  * @see Java_com_meta_ocean_NativeInterface_warning(), Java_com_meta_ocean_NativeInterface_error().
89  */
90 extern "C" void Java_com_meta_ocean_base_BaseJni_information(JNIEnv* env, jobject javaThis, jstring message);
91 
92 /**
93  * Java native interface function to forward an information message to the framework.
94  * @param env The JNI environment
95  * @param javaThis The JNI object
96  * @param message The warning message to forward
97  * @ingroup basejni
98  * @see Java_com_meta_ocean_NativeInterface_information(), Java_com_meta_ocean_NativeInterface_error().
99  */
100 extern "C" void Java_com_meta_ocean_base_BaseJni_warning(JNIEnv* env, jobject javaThis, jstring message);
101 
102 /**
103  * Java native interface function to forward an information message to the framework.
104  * @param env The JNI environment
105  * @param javaThis The JNI object
106  * @param message The error message to forward
107  * @ingroup basejni
108  * @see Java_com_meta_ocean_NativeInterface_information(), Java_com_meta_ocean_NativeInterface_warning().
109  */
110 extern "C" void Java_com_meta_ocean_base_BaseJni_error(JNIEnv* env, jobject javaThis, jstring message);
111 
112 /**
113  * Pops all messages that a currently waiting in the message queue.
114  * @param env The JNI environment
115  * @param javaThis The JNI object
116  * @return The messages that have been popped.
117  * @ingroup basejni
118  */
119 extern "C" jstring Java_com_meta_ocean_base_BaseJni_popMessages(JNIEnv* env, jobject javaThis);
120 
121 /**
122  * Exits the application by invoking the exit() command.
123  * Beware: Commonly Android decides whether an application will be terminated or not so that this function should be a workaround only.
124  * @param env The JNI environment
125  * @param javaThis The JNI object
126  * @param exitValue The exit value to be used
127  * @ingroup basejni
128  */
129 extern "C" void Java_com_meta_ocean_base_BaseJni_exit(JNIEnv* env, jobject javaThis, jint exitValue);
130 
131 namespace Ocean
132 {
133 
134 namespace JNI
135 {
136 
137 /**
138  * This class implements a base native interface.
139  * @ingroup basejni
140  */
141 class OCEAN_BASE_JNI_EXPORT BaseJni
142 {
143  public:
144 
145  /**
146  * Initializes the Ocean framework.
147  * Several individual message output types can be specified and combined:
148  * - "STANDARD": To write all messages to the standard output (e.g., std::cout on desktop platforms, or Android logcat on Android platforms).
149  * - "QUEUED": To queue all messages and to explicitly pop the messages later (e.g., to display messages in a debug window).
150  * - <filename>: To write all messages to a define file.
151  * @param messageOutputType The type of the message output to be used, empty to use 'STANDARD'
152  * @return True, if succeeded
153  */
154  static bool initialize(const std::string& messageOutputType);
155 
156  /**
157  * Initializes the Ocean framework.
158  * @param messageOutputType The type of the message output to be used.
159  * @param outputFile The name of the file to which messages will be written, 'messageOutputType' must contain 'OUTPUT_FILE', empty otherwise
160  * @return True, if succeeded
161  */
162  static bool initialize(const Messenger::MessageOutput messageOutputType, const std::string& outputFile);
163 
164  /**
165  * Forces a specific number of processor cores.
166  * @param cores CPU cores to be forced during initialization
167  * @return True, if succeeded
168  */
169  static bool forceProcessorCoreNumber(const unsigned int cores);
170 
171  /**
172  * Sets or changes the maximal capacity of the worker pool.
173  * @param capacity The maximal number of worker objects the worker pool may provide
174  * @return True, if succeeded
175  */
176  static bool setWorkerPoolCapacity(const unsigned int capacity);
177 
178  /**
179  * Java native interface function to forward a debug message to the framework.
180  * @param message The debug message to forward
181  */
182  static void debug(const std::string& message);
183 
184  /**
185  * Java native interface function to forward an information message to the framework.
186  * @param message The information message to forward
187  */
188  static void information(const std::string& message);
189 
190  /**
191  * Java native interface function to forward a warning message to the framework.
192  * @param message The warning message to forward
193  */
194  static void warning(const std::string& message);
195 
196  /**
197  * Java native interface function to forward an error message to the framework.
198  * @param message The error message to forward
199  */
200  static void error(const std::string& message);
201 
202  /**
203  * Pops all messages that a currently waiting in the message queue.
204  * @return The messages that have been popped.
205  */
206  static std::string popMessages();
207 };
208 
209 }
210 
211 }
212 
213 #endif // META_OCEAN_BASE_JNI_BASE_JNI_H
This class implements a base native interface.
Definition: BaseJni.h:142
static std::string popMessages()
Pops all messages that a currently waiting in the message queue.
static bool initialize(const std::string &messageOutputType)
Initializes the Ocean framework.
static bool setWorkerPoolCapacity(const unsigned int capacity)
Sets or changes the maximal capacity of the worker pool.
static void warning(const std::string &message)
Java native interface function to forward a warning message to the framework.
static void error(const std::string &message)
Java native interface function to forward an error message to the framework.
static void debug(const std::string &message)
Java native interface function to forward a debug message to the framework.
static bool forceProcessorCoreNumber(const unsigned int cores)
Forces a specific number of processor cores.
static bool initialize(const Messenger::MessageOutput messageOutputType, const std::string &outputFile)
Initializes the Ocean framework.
static void information(const std::string &message)
Java native interface function to forward an information message to the framework.
MessageOutput
Definition of different message output types.
Definition: Messenger.h:120
jboolean Java_com_meta_ocean_base_BaseJni_setWorkerPoolCapacity(JNIEnv *env, jobject javaThis, jint capacity)
Sets or changes the maximal capacity of the worker pool.
jstring Java_com_meta_ocean_base_BaseJni_popMessages(JNIEnv *env, jobject javaThis)
Pops all messages that a currently waiting in the message queue.
void Java_com_meta_ocean_base_BaseJni_exit(JNIEnv *env, jobject javaThis, jint exitValue)
Exits the application by invoking the exit() command.
jboolean Java_com_meta_ocean_base_BaseJni_initialize(JNIEnv *env, jobject javaThis, jstring messageOutputType)
Java native interface function to initialize the Ocean Framework.
jboolean Java_com_meta_ocean_base_BaseJni_forceProcessorCoreNumber(JNIEnv *env, jobject javaThis, jint cores)
Forces a specific number of processor cores.
jboolean Java_com_meta_ocean_base_BaseJni_initializeWithMessageOutput(JNIEnv *env, jobject javaThis, jint messageOutputType, jstring outputFile)
Java native interface function to initialize the Ocean Framework.
void Java_com_meta_ocean_base_BaseJni_information(JNIEnv *env, jobject javaThis, jstring message)
Java native interface function to forward an information message to the framework.
void Java_com_meta_ocean_base_BaseJni_debug(JNIEnv *env, jobject javaThis, jstring message)
Java native interface function to forward a debug message to the framework.
void Java_com_meta_ocean_base_BaseJni_error(JNIEnv *env, jobject javaThis, jstring message)
Java native interface function to forward an information message to the framework.
jboolean Java_com_meta_ocean_base_BaseJni_setCurrentActivity(JNIEnv *env, jobject javaThis, jobject activity)
Java native interface function to set the current activity.
void Java_com_meta_ocean_base_BaseJni_warning(JNIEnv *env, jobject javaThis, jstring message)
Java native interface function to forward an information message to the framework.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15