Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / plugins / dm-public / devdetail / src / plugin_interface.c
1 /*
2  * oma-dm-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 <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <vconf.h>
22
23 /*sync-agent*/
24 #include <sync_agent.h>
25
26 #ifndef EXPORT_API
27 #define EXPORT_API __attribute__ ((visibility("default")))
28 #endif
29
30 #ifndef OMADM_AGENT_LOG
31 #undef LOG_TAG
32 #define LOG_TAG "PLUGIN_DEVDETAIL"
33 #endif
34
35 #define SERVER_NUM                                                                                                              1
36 /*
37 #define  CSC_VCONF_KEY_SYNCMLDM_NBFIELD                                 "db/SyncML/oma-dm-service/DevManagement/NbDevManagement"
38 #define  CSC_VCONF_KEY_SYNCMLDM_ACCNAME                         "db/SyncML/oma-dm-service/DevManagement/%d/AccName"
39 #define  CSC_VCONF_KEY_SYNCMLDM_SERVID                                  "db/SyncML/oma-dm-service/DevManagement/%d/ServID"
40
41 #define ALTER_SYNCMLDM_NBFIELD                                                                  3
42 #define SERVER_NUM                                                                                                              3
43 #define ALTER_SYNCMLDM_ACCNAME_1                                                                "MSCTestserver"
44 #define ALTER_SYNCMLDM_ACCNAME_2                                                                "MSCServer"
45 #define ALTER_SYNCMLDM_ACCNAME_3                                                                "gcf"
46 */
47
48 #define MAX_DEPTH                                                                                                                       "100"
49 #define MAX_SEG_LEN                                                                                                             "100"
50 #define MAX_TOTAL_LEN                                                                                                   "1000"
51
52 static sync_agent_get_devinfo_cb pfunc_get_dev_info = 0;
53
54 //static int _get_index(const char *name);
55 //static char *_get_mo_value_str(const char *vconf_key, int n_index);
56
57 EXPORT_API char **sync_agent_plugin_get_server_id_list(int *server_id_list_cnt)
58 {
59         _EXTERN_FUNC_ENTER;
60 /*
61         *server_id_list_cnt = 0;
62         char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
63         if (temp_id_list == NULL) {
64                 _EXTERN_FUNC_EXIT;
65                 return 0;
66         }
67
68         char *sever_name = 0;
69         int server_idx = 0;
70         char *server_id = 0;
71
72         int i;
73         for (i = 0; i < SERVER_NUM; i++) {
74
75                 switch (i) {
76                 case 0:
77                         sever_name = ALTER_SYNCMLDM_ACCNAME_1;
78                         break;
79                 case 1:
80                         sever_name = ALTER_SYNCMLDM_ACCNAME_2;
81                         break;
82                 case 2:
83                         sever_name = ALTER_SYNCMLDM_ACCNAME_3;
84                         break;
85                 default :
86                         continue;
87                         break;
88                 }
89
90                 server_idx = _get_index(sever_name);
91                 server_id = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_SERVID, server_idx);
92                 if (server_id != NULL) {
93                         _DEBUG_INFO("Temp_id_list[%d] = %s\n", i, server_id);
94                         temp_id_list[i] = server_id;
95                         (*server_id_list_cnt)++;
96                 }
97         }
98         _DEBUG_INFO("server_id_list_cnt = %d\n", *server_id_list_cnt);
99         _EXTERN_FUNC_EXIT;
100         return temp_id_list;
101
102 */
103         *server_id_list_cnt = 1;
104         char **temp_id_list = (char **)calloc(SERVER_NUM, sizeof(char *));
105         if (temp_id_list == NULL) {
106                 _EXTERN_FUNC_EXIT;
107                 return NULL;
108         }
109         char *server_id = NULL;
110         server_id = strdup("*");
111         *temp_id_list = server_id;
112
113         _DEBUG_INFO("devdetail  server_id = %s\n", server_id);
114         _DEBUG_INFO("devdetail  server_id_list_cnt = %d\n", *server_id_list_cnt);
115
116         _EXTERN_FUNC_EXIT;
117         return temp_id_list;
118 }
119
120 EXPORT_API int sync_agent_plugin_get_mo_value(const char *mo_pull_path, const char *mo_name, char **mo_value)
121 {
122         _EXTERN_FUNC_ENTER;
123
124         retvm_if((mo_pull_path) == NULL, -1, "mo_pull_path is NULL!!");
125         retvm_if((mo_name) == NULL, -1, "mo_name is NULL!!");
126
127         _DEBUG_INFO("mo_name : %s", mo_name);
128         *mo_value = 0;
129
130         if (!strcmp(mo_name, "DevTyp")) {
131                 if (pfunc_get_dev_info == NULL) {
132                         _EXTERN_FUNC_EXIT;
133                         return -1;
134                 }
135                 pfunc_get_dev_info(2, "DevTyp", mo_value);
136         } else if (!strcmp(mo_name, "Bearer")) {
137                 if (pfunc_get_dev_info == NULL) {
138                         _EXTERN_FUNC_EXIT;
139                         return -1;
140                 }
141                 pfunc_get_dev_info(2, "Bearer", mo_value);
142         } else if (!strcmp(mo_name, "OEM")) {
143                 if (pfunc_get_dev_info == NULL) {
144                         _EXTERN_FUNC_EXIT;
145                         return -1;
146                 }
147                 pfunc_get_dev_info(2, "OEM", mo_value);
148         } else if (!strcmp(mo_name, "FwV")) {
149                 if (pfunc_get_dev_info == NULL) {
150                         _EXTERN_FUNC_EXIT;
151                         return -1;
152                 }
153                 pfunc_get_dev_info(2, "FwV", mo_value);
154         } else if (!strcmp(mo_name, "SwV")) {
155                 if (pfunc_get_dev_info == NULL) {
156                         _EXTERN_FUNC_EXIT;
157                         return -1;
158                 }
159                 pfunc_get_dev_info(2, "SwV", mo_value);
160         } else if (!strcmp(mo_name, "HwV")) {
161                 if (pfunc_get_dev_info == NULL) {
162                         _EXTERN_FUNC_EXIT;
163                         return -1;
164                 }
165                 pfunc_get_dev_info(2, "HwV", mo_value);
166         } else if (!strcmp(mo_name, "LrgObj")) {
167                 *mo_value = strdup("0");
168         } else if (!strcmp(mo_name, "MaxDepth")) {
169                 *mo_value = strdup(MAX_DEPTH);
170         } else if (!strcmp(mo_name, "MaxTotLen")) {
171                 *mo_value = strdup(MAX_TOTAL_LEN);
172         } else if (!strcmp(mo_name, "MaxSegLen")) {
173                 *mo_value = strdup(MAX_SEG_LEN);
174         }
175
176         _DEBUG_INFO("mo_value : %s", *mo_value);
177
178         _EXTERN_FUNC_EXIT;
179
180         return 0;
181 }
182
183 EXPORT_API void sync_agent_plugin_set_function_get_devinfo(sync_agent_get_devinfo_cb func)
184 {
185         _EXTERN_FUNC_ENTER;
186
187         pfunc_get_dev_info = func;
188
189         _EXTERN_FUNC_EXIT;
190 }
191
192 /*
193 static int _get_index(const char *name)
194 {
195         _INNER_FUNC_ENTER;
196
197         retvm_if((name) == NULL, -1, "name is NULL!!");
198
199         int acc_count = 0;
200         if (vconf_get_int(CSC_VCONF_KEY_SYNCMLDM_NBFIELD, &acc_count)) {
201                 _DEBUG_TRACE("vconf_get_int FAIL");
202                 //return -1;
203                 acc_count =ALTER_SYNCMLDM_NBFIELD;
204         }
205
206         _DEBUG_TRACE("acc_count : %d", acc_count);
207
208         int i = 0;
209         for (; i < acc_count; i++) {
210                 char *compare_name = _get_mo_value_str(CSC_VCONF_KEY_SYNCMLDM_ACCNAME, i + 1);
211                 if (compare_name != NULL) {
212                         _DEBUG_TRACE("[%d] compare_name : %s [%d], name : %s [%d]", i, compare_name, strlen(compare_name), name, strlen(name));
213                         if (!strcmp(name, compare_name)) {
214                                 _DEBUG_TRACE("nIndex : %d", i + 1);
215                                 _INNER_FUNC_EXIT;
216                                 return i + 1;
217                         }
218                 }
219         }
220
221         _INNER_FUNC_EXIT;
222         return -1;
223 }
224
225 static char *_get_mo_value_str(const char *vconf_key, int n_index)
226 {
227         _INNER_FUNC_ENTER;
228
229         retvm_if((vconf_key) == NULL, NULL, "vconf_key is NULL!!");
230
231         if (n_index == -1) {
232                 return 0;
233         }
234
235         char input_vconf_path[200] = { 0, };
236         char cRecIdx[8];
237
238         memset(cRecIdx, 0x0, sizeof(cRecIdx));
239         snprintf(cRecIdx, sizeof(cRecIdx), "%d", n_index);
240         snprintf(input_vconf_path, strlen(vconf_key) + strlen(cRecIdx) + 1, vconf_key, n_index);
241
242         char *value = vconf_get_str(input_vconf_path);
243         if (value == NULL) {
244                 _DEBUG_TRACE("vconf_get_str FAIL");
245         }
246
247         _INNER_FUNC_EXIT;
248
249         return value;
250 }
251 */