Fix incorrect usages of OIC_LOG_V macro.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / android / calenwmonitor.c
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 #include <jni.h>
22 #include <stdio.h>
23 #include <android/log.h>
24 #include "logger.h"
25 #include "calenwmonitor.h"
26 #include "caleutils.h"
27 #include "com_iotivity_jar_caleinterface.h"
28
29 #define TAG PCF("CA_LE_MONITOR")
30
31 static JavaVM *g_jvm;
32 static jobject g_context;
33 static CALENetStateChantedCallback g_networkChangeCb = NULL;
34
35 //getting context
36 void CALENetworkMonitorJNISetContext(JNIEnv *env, jobject context)
37 {
38     OIC_LOG(DEBUG, TAG, "CALENetworkMonitorJNISetContext");
39
40     if (context == NULL)
41     {
42         OIC_LOG(DEBUG, TAG, "context is null");
43     }
44
45     g_context = (*env)->NewGlobalRef(env, context);
46 }
47
48 //getting jvm
49 void CALeNetworkMonitorJniInit(JNIEnv *env, JavaVM *jvm)
50 {
51     OIC_LOG(DEBUG, TAG, "CALeNetworkMonitorJniInit");
52     g_jvm = jvm;
53 }
54
55 void CALESetNetStateCallback(CALENetStateChantedCallback callback)
56 {
57     OIC_LOG(DEBUG, TAG, "CALESetNetStateCallback");
58     g_networkChangeCb = callback;
59 }
60
61 JNIEXPORT void JNICALL
62 Java_com_iotivity_jar_caleinterface_CALeStateChangedCallback(JNIEnv *env, jobject obj, jint status)
63 {
64     // STATE_ON:12, STATE_OFF:10
65     OIC_LOG(DEBUG, TAG, "CALeInterface - Network State Changed");
66
67     if (g_networkChangeCb == NULL)
68     {
69         OIC_LOG(DEBUG, TAG, "g_networkChangeCb is null", status);
70     }
71
72     jstring jni_address = CALEGetLocalDeviceAddress(env);
73     const char* localAddress = (*env)->GetStringUTFChars(env, jni_address, NULL);
74
75     g_networkChangeCb(localAddress, status);
76 }
77