1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
23 #include <android/log.h>
25 #include "calenwmonitor.h"
26 #include "caleutils.h"
27 #include "com_iotivity_jar_caleinterface.h"
29 #define TAG PCF("CA_LE_MONITOR")
32 static jobject g_context;
33 static CALENetStateChantedCallback g_networkChangeCb = NULL;
36 void CALENetworkMonitorJNISetContext(JNIEnv *env, jobject context)
38 OIC_LOG(DEBUG, TAG, "CALENetworkMonitorJNISetContext");
42 OIC_LOG(DEBUG, TAG, "context is null");
45 g_context = (*env)->NewGlobalRef(env, context);
49 void CALeNetworkMonitorJniInit(JNIEnv *env, JavaVM *jvm)
51 OIC_LOG(DEBUG, TAG, "CALeNetworkMonitorJniInit");
55 void CALESetNetStateCallback(CALENetStateChantedCallback callback)
57 OIC_LOG(DEBUG, TAG, "CALESetNetStateCallback");
58 g_networkChangeCb = callback;
61 JNIEXPORT void JNICALL
62 Java_com_iotivity_jar_caleinterface_CALeStateChangedCallback(JNIEnv *env, jobject obj, jint status)
64 // STATE_ON:12, STATE_OFF:10
65 OIC_LOG(DEBUG, TAG, "CALeInterface - Network State Changed");
67 if (g_networkChangeCb == NULL)
69 OIC_LOG(DEBUG, TAG, "g_networkChangeCb is null", status);
72 jstring jni_address = CALEGetLocalDeviceAddress(env);
73 const char* localAddress = (*env)->GetStringUTFChars(env, jni_address, NULL);
75 g_networkChangeCb(localAddress, status);