Merge "Provide callback support to battery monitor frwk when BT is disabled" into...
[platform/core/connectivity/bluetooth-frwk.git] / include / bt-internal-types.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 /* This is infrastructral, shared function for all bt-* / *.c files. */
19
20 #include <dlfcn.h>
21
22 #include "bt-internal-types.h"
23
24 bool is_battery_monitor_enabled = false;
25
26 tizen_profile_t profile = _PROFILE_UNKNOWN;
27
28 bt_plugin_info_t *headed_plugin_info = NULL;
29
30 void bluetooth_plugin_init()
31 {
32         headed_plugin_info = g_malloc0(sizeof(bt_plugin_info_t));
33         if (!headed_plugin_info)
34                 return;
35
36         /* check ARCH 64 or 32*/
37         if (!access(FILEPATH_ARCH_64, 0))
38                 headed_plugin_info->handle_headed = dlopen(HEADED_PLUGIN_FILEPATH64, RTLD_NOW);
39         else
40                 headed_plugin_info->handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
41
42         if (!headed_plugin_info->handle_headed) {
43                 headed_plugin_info->plugin_headed_enabled = FALSE;
44                 return;
45         }
46
47         headed_plugin_info->headed_plugin = dlsym(headed_plugin_info->handle_headed, "headed_plugin");
48         if (!headed_plugin_info->headed_plugin) {
49                 dlclose(headed_plugin_info->handle_headed);
50                 headed_plugin_info->plugin_headed_enabled = FALSE;
51                 return;
52         }
53
54         headed_plugin_info->plugin_headed_enabled = TRUE;
55 }
56
57 void bluetooth_plugin_deinit()
58 {
59         if (!headed_plugin_info->plugin_headed_enabled) {
60                 g_free(headed_plugin_info);
61                 headed_plugin_info = NULL;
62                 return;
63         }
64
65         dlclose(headed_plugin_info->handle_headed);
66         headed_plugin_info->plugin_headed_enabled = FALSE;
67         g_free(headed_plugin_info);
68         headed_plugin_info = NULL;
69 }
70