1 /* ****************************************************************
3 * Copyright 2016 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 ******************************************************************/
21 #include "camanagerleinterface.h"
22 #include "cabtpairinginterface.h"
23 #include "cautilinterface.h"
24 #include "cainterfacecontroller.h"
28 #define TAG "OIC_CA_COMMON_UTILS"
30 static CAAdapterStateChangedCB g_adapterStateCB = NULL;
31 static CAConnectionStateChangedCB g_connStateCB = NULL;
33 static void CAManagerAdapterMonitorHandler(CATransportAdapter_t adapter,
34 CANetworkStatus_t status)
36 if (CA_INTERFACE_DOWN == status)
40 g_adapterStateCB(adapter, false);
41 OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
44 else if (CA_INTERFACE_UP == status)
48 g_adapterStateCB(adapter, true);
49 OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
54 static void CAManagerConnectionMonitorHandler(const CAEndpoint_t *info, bool isConnected)
56 if (!info || !info->addr)
58 OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
66 g_connStateCB(info->adapter, info->addr, isConnected);
67 OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer");
74 g_connStateCB(info->adapter, info->addr, isConnected);
75 OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer");
80 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
81 CAConnectionStateChangedCB connStateCB)
83 OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
85 g_adapterStateCB = adapterStateCB;
86 g_connStateCB = connStateCB;
88 CASetNetworkMonitorCallbacks(CAManagerAdapterMonitorHandler,
89 CAManagerConnectionMonitorHandler);
93 CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
95 OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
97 #if defined(__ANDROID__) && defined(LE_ADAPTER)
98 return CASetLEClientAutoConnectionDeviceInfo(address);
101 return CA_NOT_SUPPORTED;
105 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address)
107 OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
109 #if defined(__ANDROID__) && defined(LE_ADAPTER)
110 return CAUnsetLEClientAutoConnectionDeviceInfo(address);
113 return CA_NOT_SUPPORTED;
119 * initialize client connection manager
120 * @param[in] env JNI interface pointer.
121 * @param[in] jvm invocation inferface for JAVA virtual machine.
122 * @param[in] context application context.
124 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context)
126 OIC_LOG(DEBUG, TAG, "CAUtilClientInitialize");
128 CAResult_t res = CA_STATUS_OK;
130 if (CA_STATUS_OK != CAManagerLEClientInitialize(env, jvm, context))
132 OIC_LOG(ERROR, TAG, "CAManagerLEClientInitialize has failed");
133 res = CA_STATUS_FAILED;
138 if (CA_STATUS_OK != CABTPairingInitialize(env, jvm, context))
140 OIC_LOG(ERROR, TAG, "CABTPairingInitialize has failed");
141 res = CA_STATUS_FAILED;
148 * terminate client connection manager
149 * @param[in] env JNI interface pointer.
151 CAResult_t CAUtilClientTerminate(JNIEnv *env)
153 OIC_LOG(DEBUG, TAG, "CAUtilClientTerminate");
155 return CAManagerLEClientTerminate(env);
157 OIC_LOG(DEBUG, TAG, "it is not supported");
159 return CA_NOT_SUPPORTED;
164 CAResult_t CAUtilStartScan(JNIEnv *env)
167 return CABTPairingStartScan(env);
169 OIC_LOG(DEBUG, TAG, "it is not supported");
171 return CA_NOT_SUPPORTED;
175 CAResult_t CAUtilStopScan(JNIEnv *env)
178 return CABTPairingStopScan(env);
180 OIC_LOG(DEBUG, TAG, "it is not supported");
182 return CA_NOT_SUPPORTED;
186 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device)
189 return CABTPairingCreateBond(env, device);
191 OIC_LOG(DEBUG, TAG, "it is not supported");
194 return CA_NOT_SUPPORTED;
198 void CAUtilSetFoundDeviceListener(jobject listener)
201 CABTPairingSetFoundDeviceListener(listener);