089492ba43080389472d86aba1004b01f36ac95d
[platform/core/ml/beyond.git] / subprojects / libbeyond-android / src / main / jni / discovery / beyond-discovery_jni.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __BEYOND_ANDROID_DISCOVERY_JNI_H__
18 #define __BEYOND_ANDROID_DISCOVERY_JNI_H__
19
20 #include "NativeInterface.h"
21
22 #include <beyond/platform/beyond_platform.h>
23 #include <beyond/private/beyond_private.h>
24
25 #include <android/looper.h>
26 #include <jni.h>
27
28 class DiscoveryNativeInterface : public NativeInterface {
29 public:
30     void *GetBeyonDInstance(void) override;
31
32 public:
33     static int RegisterNativeInterface(JNIEnv *env);
34
35 private:
36     DiscoveryNativeInterface(void);
37     virtual ~DiscoveryNativeInterface(void);
38
39 private:
40     static void initializeEventObject(JNIEnv *env, jclass klass);
41     static void initializeInfo(JNIEnv *env, jclass klass);
42     jobject NewEventObject(JNIEnv *env, jobject thiz, void *eventData);
43
44 private:
45     static void Java_com_samsung_android_beyond_discovery_Discovery_initialize(JNIEnv *env, jclass klass);
46     static jlong Java_com_samsung_android_beyond_discovery_Discovery_create(JNIEnv *env, jobject thiz, jobjectArray args);
47     static void Java_com_samsung_android_beyond_discovery_Discovery_destroy(JNIEnv *env, jclass klass, jlong instance);
48     static jint Java_com_samsung_android_beyond_discovery_Discovery_configure_object(JNIEnv *env, jobject thiz, jlong instance, jchar type, jobject obj);
49     static jint Java_com_samsung_android_beyond_discovery_Discovery_configure(JNIEnv *env, jobject thiz, jlong instance, jchar type, jstring jsonConfig);
50     static jint Java_com_samsung_android_beyond_discovery_Discovery_activate(JNIEnv *env, jobject thiz, jlong instance);
51     static jint Java_com_samsung_android_beyond_discovery_Discovery_deactivate(JNIEnv *env, jobject thiz, jlong instance);
52     static jint Java_com_samsung_android_beyond_discovery_Discovery_setItem(JNIEnv *env, jobject thiz, jlong instance, jstring key, jbyteArray value);
53     static jint Java_com_samsung_android_beyond_discovery_Discovery_removeItem(JNIEnv *env, jobject thiz, jlong instance, jstring key);
54     static jint Java_com_samsung_android_beyond_discovery_Discovery_configure(JNIEnv *env, jobject thiz, jlong inst, jchar type, jobject obj);
55     static jint Java_com_samsung_android_beyond_discovery_Discovery_setEventListener(JNIEnv *env, jobject thiz, jlong instance, jboolean flag);
56
57 private:
58     static int Discovery_eventHandler(int fd, int events, void *data);
59
60 private: // JNI Cache
61     struct EventObject {
62         jclass klass;
63         jmethodID constructor;
64         jfieldID eventType;
65         jfieldID eventData;
66     };
67
68     struct Info {
69         jclass klass;
70         jmethodID constructor;
71         jfieldID name;
72         jfieldID host;
73         jfieldID port;
74         jfieldID uuid;
75     };
76
77 private: // JNI Cache
78     static EventObject eventObject;
79     static jfieldID eventListener;
80     static Info infoObject;
81
82 private:
83     int InvokeEventListener(JNIEnv *env, jobject thiz, int eventType, void *eventData);
84     int AttachEventLoop(void);
85
86 private:
87     beyond::Discovery *discovery;
88     ALooper *looper;
89     JavaVM *jvm;
90     jobject thiz;
91 };
92
93 #endif // __BEYOND_ANDROID_DISCOVERY_JNI_H__