API change , Retransmission Callback on expiry , remove glib source for dynamic linking
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / calenwmonitor.c
1 #include <jni.h>
2 #include <stdio.h>
3 #include <android/log.h>
4 #include "logger.h"
5 #include "com_iotivity_jar_CALeInterface.h"
6
7 #define TAG PCF("CA_LE_SERVER")
8
9 #define  LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
10 #define  LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
11
12 static JavaVM *g_jvm;
13 static jobject gContext;
14
15 //FIXME getting context
16 void CALENetworkMonitorJNISetContext(JNIEnv *env, jobject context)
17 {
18     OIC_LOG_V(DEBUG, TAG, "CALENetworkMonitorJNISetContext");
19
20     if(context == NULL)
21         OIC_LOG_V(DEBUG, TAG, "context is null");
22
23     gContext = (*env)->NewGlobalRef(env, context);
24 }
25
26 //FIXME getting jvm
27 void CALeNetworkMonitorJniInit(JNIEnv *env, JavaVM *jvm)
28 {
29     OIC_LOG_V(DEBUG, TAG, "CALeNetworkMonitorJniInit");
30     g_jvm = jvm;
31 }
32
33 void CALEStartNetworkMonitor(JNIEnv *env, jobject obj)
34 {
35     OIC_LOG_V(DEBUG, TAG, "CALEStartNetworkMonitor");
36
37     jclass jni_cls_CALeInterface = (*env)->FindClass(env, "com/iotivity/jar/CALeInterface");
38     if (!jni_cls_CALeInterface)
39     {
40         OIC_LOG_V(DEBUG, TAG, "Could not get CALeInterface class");
41         return;
42     }
43
44     jmethodID jni_mid_getActionStateIntentFilter = (*env)->GetStaticMethodID(env,
45             jni_cls_CALeInterface, "getActionStateIntentFilter",
46             "()Landroid/content/IntentFilter;");
47     if (!jni_mid_getActionStateIntentFilter)
48     {
49         OIC_LOG_V(DEBUG, TAG, "Could not get getActionStateIntentFilter method");
50         return;
51     }
52
53     jobject jni_obj_intentFilter = (*env)->CallStaticObjectMethod(env, jni_cls_CALeInterface,
54             jni_mid_getActionStateIntentFilter);
55     if (!jni_obj_intentFilter)
56     {
57         OIC_LOG_V(DEBUG, TAG, "Could not get jni_obj_intentFilter");
58         return;
59     }
60
61     jclass jni_cls_context = (*env)->FindClass(env, "Landroid/contect/Context");
62     if (!jni_cls_context)
63     {
64         OIC_LOG_V(DEBUG, TAG, "Could not get jni_cls_context class");
65         return;
66     }
67
68     jmethodID jni_mid_registerReceiver = (*env)->GetMethodID(env, jni_cls_context, "registerReceiver",
69                 "(Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)Landroid/content/Intent;");
70     if (!jni_mid_registerReceiver)
71     {
72         OIC_LOG_V(DEBUG, TAG, "Could not get jni_mid_registerReceiver method");
73         return;
74     }
75
76     jmethodID jni_obj_registerReceiver = (*env)->CallObjectMethod(env, gContext, jni_mid_registerReceiver, obj, jni_obj_intentFilter);
77     if (!jni_obj_registerReceiver)
78     {
79         OIC_LOG_V(DEBUG, TAG, "Could not get jni_obj_registerReceiver method");
80         return;
81     }
82 }
83
84 JNIEXPORT void JNICALL
85 Java_com_iotivity_jar_CALeInterface_CALeStateChangedCallback
86 (JNIEnv *env, jobject obj, jint status)
87 {
88     // STATE_ON:12, STATE_OFF:10
89     OIC_LOG_V(DEBUG, TAG, "CALeInterface - State Changed Callback(%d)", status);
90 }