Beatmup
callback_task.cpp
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "callback_task.h"
20 
21 using namespace Beatmup;
22 
23 const char* CallbackTask::JAVA_CLASS_NAME = "Beatmup/Utils/Callback";
24 const char* CallbackTask::JAVA_METHOD_NAME = "run";
25 
26 
27 CallbackTask::CallbackTask(JNIEnv* jenv): callbackObject(nullptr) {
28  jenv->GetJavaVM(&jvm);
29  jclass cls = jenv->FindClass(JAVA_CLASS_NAME);
30  callbackMethodId = jenv->GetMethodID(cls, JAVA_METHOD_NAME, "()V");
31 }
32 
33 
35  if (callbackObject) {
36  JNIEnv *jenv;
37  jvm->AttachCurrentThread(&jenv, nullptr);
38  jenv->DeleteGlobalRef(callbackObject);
39  }
40 }
41 
42 
44  JNIEnv *jenv;
45  jvm->AttachCurrentThread(&jenv, nullptr);
46  jenv->CallVoidMethod(callbackObject, callbackMethodId);
47  return true;
48 }
49 
50 
52  if (callbackObject)
53  jenv->DeleteGlobalRef(callbackObject);
54  callbackObject = jenv->NewGlobalRef(obj);
55 }
static const char * JAVA_METHOD_NAME
called method name
Definition: callback_task.h:46
jmethodID callbackMethodId
Definition: callback_task.h:31
CallbackTask(JNIEnv *jenv)
static const char * JAVA_CLASS_NAME
callback object java class name
Definition: callback_task.h:45
bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
void setCallbackObject(JNIEnv *jenv, jobject obj)
Sets the object to be called.
Thread executing tasks.
Definition: parallelism.h:154
JNIEnv jclass
JNIEnv * jenv
JNIEnv jobject