Ocean
Loading...
Searching...
No Matches
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
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 */
29extern "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 */
40extern "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 */
50extern "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 */
60extern "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 */
70extern "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 */
80extern "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 */
90extern "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 */
100extern "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 */
110extern "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 */
119extern "C" jstring Java_com_meta_ocean_base_BaseJni_popMessages(JNIEnv* env, jobject javaThis);
120
121/**
122 * Java native interface function to check if the native library is compiled in debug mode.
123 * @param env The JNI environment
124 * @param javaThis The JNI object
125 * @return True, if the library is compiled with debug settings (OCEAN_DEBUG is defined)
126 * @ingroup basejni
127 */
128extern "C" jboolean Java_com_meta_ocean_base_BaseJni_isDebug(JNIEnv* env, jobject javaThis);
129
130/**
131 * Exits the application by invoking the exit() command.
132 * Beware: Commonly Android decides whether an application will be terminated or not so that this function should be a workaround only.
133 * @param env The JNI environment
134 * @param javaThis The JNI object
135 * @param exitValue The exit value to be used
136 * @ingroup basejni
137 */
138extern "C" void Java_com_meta_ocean_base_BaseJni_exit(JNIEnv* env, jobject javaThis, jint exitValue);
139
140namespace Ocean
141{
142
143namespace JNI
144{
145
146/**
147 * This class implements a base native interface.
148 * @ingroup basejni
149 */
150class OCEAN_BASE_JNI_EXPORT BaseJni
151{
152 public:
153
154 /**
155 * Initializes the Ocean framework.
156 * Several individual message output types can be specified and combined:
157 * - "STANDARD": To write all messages to the standard output (e.g., std::cout on desktop platforms, or Android logcat on Android platforms).
158 * - "QUEUED": To queue all messages and to explicitly pop the messages later (e.g., to display messages in a debug window).
159 * - <filename>: To write all messages to a define file.
160 * @param messageOutputType The type of the message output to be used, empty to use 'STANDARD'
161 * @return True, if succeeded
162 */
163 static bool initialize(const std::string& messageOutputType);
164
165 /**
166 * Initializes the Ocean framework.
167 * @param messageOutputType The type of the message output to be used.
168 * @param outputFile The name of the file to which messages will be written, 'messageOutputType' must contain 'OUTPUT_FILE', empty otherwise
169 * @return True, if succeeded
170 */
171 static bool initialize(const Messenger::MessageOutput messageOutputType, const std::string& outputFile);
172
173 /**
174 * Forces a specific number of processor cores.
175 * @param cores CPU cores to be forced during initialization
176 * @return True, if succeeded
177 */
178 static bool forceProcessorCoreNumber(const unsigned int cores);
179
180 /**
181 * Sets or changes the maximal capacity of the worker pool.
182 * @param capacity The maximal number of worker objects the worker pool may provide
183 * @return True, if succeeded
184 */
185 static bool setWorkerPoolCapacity(const unsigned int capacity);
186
187 /**
188 * Java native interface function to forward a debug message to the framework.
189 * @param message The debug message to forward
190 */
191 static void debug(const std::string& message);
192
193 /**
194 * Java native interface function to forward an information message to the framework.
195 * @param message The information message to forward
196 */
197 static void information(const std::string& message);
198
199 /**
200 * Java native interface function to forward a warning message to the framework.
201 * @param message The warning message to forward
202 */
203 static void warning(const std::string& message);
204
205 /**
206 * Java native interface function to forward an error message to the framework.
207 * @param message The error message to forward
208 */
209 static void error(const std::string& message);
210
211 /**
212 * Pops all messages that a currently waiting in the message queue.
213 * @return The messages that have been popped.
214 */
215 static std::string popMessages();
216};
217
218}
219
220}
221
222#endif // META_OCEAN_BASE_JNI_BASE_JNI_H
This class implements a base native interface.
Definition BaseJni.h:151
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_isDebug(JNIEnv *env, jobject javaThis)
Java native interface function to check if the native library is compiled in debug mode.
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