Imported Upstream version 1.1.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / util / src / cautilinterface.c
1 /* ****************************************************************
2  *
3  * Copyright 2016 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 "camanagerleinterface.h"
22 #include "cabtpairinginterface.h"
23 #include "cautilinterface.h"
24
25 #include "cacommon.h"
26 #include "logger.h"
27
28 #define TAG "OIC_CA_COMMON_UTILS"
29
30 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
31                                            CAConnectionStateChangedCB connStateCB)
32 {
33     OIC_LOG(DEBUG, TAG, "CARegisterNetworkMonitorHandler");
34
35 #ifdef LE_ADAPTER
36     CASetLENetworkMonitorCallbacks(adapterStateCB, connStateCB);
37     return CA_STATUS_OK;
38 #else
39     (void)adapterStateCB;
40     (void)connStateCB;
41     return CA_NOT_SUPPORTED;
42 #endif
43
44 }
45
46 CAResult_t CASetAutoConnectionDeviceInfo(const char *address)
47 {
48     OIC_LOG(DEBUG, TAG, "CASetAutoConnectionDeviceInfo");
49
50 #ifdef LE_ADAPTER
51     return CASetLEClientAutoConnectionDeviceInfo(address);
52 #else
53     (void)address;
54     return CA_NOT_SUPPORTED;
55 #endif
56 }
57
58 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char *address)
59 {
60     OIC_LOG(DEBUG, TAG, "CAUnsetAutoConnectionDeviceInfo");
61
62 #ifdef LE_ADAPTER
63     return CAUnsetLEClientAutoConnectionDeviceInfo(address);
64 #else
65     (void)address;
66     return CA_NOT_SUPPORTED;
67 #endif
68 }
69
70 #ifdef __ANDROID__
71 /**
72  * initialize client connection manager
73  * @param[in]   env                   JNI interface pointer.
74  * @param[in]   jvm                   invocation inferface for JAVA virtual machine.
75  * @param[in]   context               application context.
76  */
77 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context)
78 {
79     OIC_LOG(DEBUG, TAG, "CAUtilClientInitialize");
80
81     CAResult_t res = CA_STATUS_OK;
82 #ifdef LE_ADAPTER
83     if (CA_STATUS_OK != CAManagerLEClientInitialize(env, jvm, context))
84     {
85         OIC_LOG(ERROR, TAG, "CAManagerLEClientInitialize has failed");
86         res = CA_STATUS_FAILED;
87     }
88 #endif
89
90 #ifdef EDR_ADAPTER
91     if (CA_STATUS_OK != CABTPairingInitialize(env, jvm, context))
92     {
93         OIC_LOG(ERROR, TAG, "CABTPairingInitialize has failed");
94         res = CA_STATUS_FAILED;
95     }
96 #endif
97     return res;
98 }
99
100 /**
101  * terminate client connection manager
102  * @param[in]   env                   JNI interface pointer.
103  */
104 CAResult_t CAUtilClientTerminate(JNIEnv *env)
105 {
106     OIC_LOG(DEBUG, TAG, "CAUtilClientTerminate");
107 #ifdef LE_ADAPTER
108     return CAManagerLEClientTerminate(env);
109 #else
110     OIC_LOG(DEBUG, TAG, "it is not supported");
111     (void)env;
112     return CA_NOT_SUPPORTED;
113 #endif
114 }
115
116 // BT pairing
117 CAResult_t CAUtilStartScan(JNIEnv *env)
118 {
119 #ifdef EDR_ADAPTER
120     return CABTPairingStartScan(env);
121 #else
122     OIC_LOG(DEBUG, TAG, "it is not supported");
123     (void)env;
124     return CA_NOT_SUPPORTED;
125 #endif
126 }
127
128 CAResult_t CAUtilStopScan(JNIEnv *env)
129 {
130 #ifdef EDR_ADAPTER
131     return CABTPairingStopScan(env);
132 #else
133     OIC_LOG(DEBUG, TAG, "it is not supported");
134     (void)env;
135     return CA_NOT_SUPPORTED;
136 #endif
137 }
138
139 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device)
140 {
141 #ifdef EDR_ADAPTER
142     return CABTPairingCreateBond(env, device);
143 #else
144     OIC_LOG(DEBUG, TAG, "it is not supported");
145     (void)env;
146     (void)device;
147     return CA_NOT_SUPPORTED;
148 #endif
149 }
150
151 void CAUtilSetFoundDeviceListener(jobject listener)
152 {
153 #ifdef EDR_ADAPTER
154     CABTPairingSetFoundDeviceListener(listener);
155 #else
156     (void)listener;
157 #endif
158 }
159 #endif