Tizen 2.1 base
[platform/core/system/sync-agent.git] / src / framework / device / information.c
1 /*
2  * sync-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #include <string.h>
19
20 #include "utility/sync_util.h"
21 #include "device/information.h"
22 #include "device/information_internal.h"
23 #include "plugin/device_info_plugin.h"
24
25 #ifndef EXPORT_API
26 #define EXPORT_API __attribute__ ((visibility("default")))
27 #endif
28
29 #ifndef SYNC_AGENT_LOG
30 #undef LOG_TAG
31 #define LOG_TAG "AF_DCI"
32 #endif
33
34 sync_agent_dev_return_e dev_init_dev(int device_plugin_id)
35 {
36         _EXTERN_FUNC_ENTER;
37
38         sync_agent_dev_return_e res = SYNC_AGENT_DEV_RETURN_SUCCESS;
39
40         _DEBUG_INFO("[%s] plug-in id : %d\n", __func__, device_plugin_id);
41
42         plugin_load_devinfo_cb func_point_load_dev_info = plugin_get_function_load_devinfo(device_plugin_id);
43
44         retvm_if(func_point_load_dev_info == NULL, SYNC_AGENT_DEV_RETURN_FAIL, "cannot get plugin_load_devinfo_cb !!");
45
46         int err = func_point_load_dev_info();
47         if (err != 1) {
48                 _DEBUG_INFO("[%s] fail !!\n", __func__);
49                 res = SYNC_AGENT_DEV_RETURN_FAIL;
50         } else {
51                 _DEBUG_INFO("[%s] success !! \n", __func__);
52         }
53
54         _EXTERN_FUNC_EXIT;
55
56         return res;
57 }
58
59 EXPORT_API sync_agent_dev_return_e sync_agent_get_devinfo(int device_plugin_id, char *info_name, char **value)
60 {
61         _EXTERN_FUNC_ENTER;
62
63         sync_agent_dev_return_e res = SYNC_AGENT_DEV_RETURN_SUCCESS;
64
65         if (info_name == NULL || !strcmp(info_name, ""))
66                 return SYNC_AGENT_DEV_RETURN_FAIL;
67
68         plugin_get_devinfo_cb func_point_get_devInfo = plugin_get_function_get_devinfo(device_plugin_id);
69
70         retvm_if(func_point_get_devInfo == NULL, SYNC_AGENT_DEV_RETURN_FAIL, "cannot get plugin_get_devinfo_cb !!");
71
72         int err = func_point_get_devInfo(info_name, value);
73         _DEBUG_INFO("[%s] info name : %s\n", __func__, info_name);
74         _DEBUG_INFO("[%s] value : %s\n", __func__, *value);
75
76         if (err == 0) {
77                 _DEBUG_INFO("[%s] fail - value is null !!\n", __func__);
78                 res = SYNC_AGENT_DEV_RETURN_DEVINFO_VALUE_IS_NULL;
79         } else if (err == -1) {
80                 _DEBUG_INFO("[%s] fail - not exist this information !!\n", __func__);
81                 res = SYNC_AGENT_DEV_RETURN_NOT_EXIST_DEVINFO;
82         } else {
83                 _DEBUG_INFO("[%s] success !! \n", __func__);
84         }
85
86         _EXTERN_FUNC_EXIT;
87
88         return res;
89 }
90
91 sync_agent_dev_return_e dev_destroy_dev(int device_plugin_id)
92 {
93         _EXTERN_FUNC_ENTER;
94
95         sync_agent_dev_return_e res = SYNC_AGENT_DEV_RETURN_SUCCESS;
96
97         plugin_clear_devinfo_cb func_point_clear_devInfo = plugin_get_function_clear_devinfo(device_plugin_id);
98
99         retvm_if(func_point_clear_devInfo == NULL, SYNC_AGENT_DEV_RETURN_FAIL, "cannot get plugin_clear_devinfo_cb !!");
100
101         int err = func_point_clear_devInfo();
102         if (err != 1) {
103                 _DEBUG_INFO("[%s] fail !!\n", __func__);
104                 res = SYNC_AGENT_DEV_RETURN_FAIL;
105         } else {
106                 _DEBUG_INFO("[%s] success !! \n", __func__);
107         }
108
109         _EXTERN_FUNC_EXIT;
110
111         return res;
112 }