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