3 #include <android/log.h>
5 #include "com_iotivity_jar_CALeInterface.h"
7 #define TAG PCF("CA_LE_SERVER")
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__)
13 static jobject gContext;
15 //FIXME getting context
16 void CALENetworkMonitorJNISetContext(JNIEnv *env, jobject context)
18 OIC_LOG_V(DEBUG, TAG, "CALENetworkMonitorJNISetContext");
21 OIC_LOG_V(DEBUG, TAG, "context is null");
23 gContext = (*env)->NewGlobalRef(env, context);
27 void CALeNetworkMonitorJniInit(JNIEnv *env, JavaVM *jvm)
29 OIC_LOG_V(DEBUG, TAG, "CALeNetworkMonitorJniInit");
33 void CALEStartNetworkMonitor(JNIEnv *env, jobject obj)
35 OIC_LOG_V(DEBUG, TAG, "CALEStartNetworkMonitor");
37 jclass jni_cls_CALeInterface = (*env)->FindClass(env, "com/iotivity/jar/CALeInterface");
38 if (!jni_cls_CALeInterface)
40 OIC_LOG_V(DEBUG, TAG, "Could not get CALeInterface class");
44 jmethodID jni_mid_getActionStateIntentFilter = (*env)->GetStaticMethodID(env,
45 jni_cls_CALeInterface, "getActionStateIntentFilter",
46 "()Landroid/content/IntentFilter;");
47 if (!jni_mid_getActionStateIntentFilter)
49 OIC_LOG_V(DEBUG, TAG, "Could not get getActionStateIntentFilter method");
53 jobject jni_obj_intentFilter = (*env)->CallStaticObjectMethod(env, jni_cls_CALeInterface,
54 jni_mid_getActionStateIntentFilter);
55 if (!jni_obj_intentFilter)
57 OIC_LOG_V(DEBUG, TAG, "Could not get jni_obj_intentFilter");
61 jclass jni_cls_context = (*env)->FindClass(env, "Landroid/contect/Context");
64 OIC_LOG_V(DEBUG, TAG, "Could not get jni_cls_context class");
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)
72 OIC_LOG_V(DEBUG, TAG, "Could not get jni_mid_registerReceiver method");
76 jmethodID jni_obj_registerReceiver = (*env)->CallObjectMethod(env, gContext, jni_mid_registerReceiver, obj, jni_obj_intentFilter);
77 if (!jni_obj_registerReceiver)
79 OIC_LOG_V(DEBUG, TAG, "Could not get jni_obj_registerReceiver method");
84 JNIEXPORT void JNICALL
85 Java_com_iotivity_jar_CALeInterface_CALeStateChangedCallback
86 (JNIEnv *env, jobject obj, jint status)
88 // STATE_ON:12, STATE_OFF:10
89 OIC_LOG_V(DEBUG, TAG, "CALeInterface - State Changed Callback(%d)", status);