Initialize Tizen 2.3
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / lawmo / lawmo_account.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 /*sync-agent*/
19 #include <sync_agent.h>
20
21 /*dm-agent*/
22 #include "common/dm_common.h"
23 #include "dm-engine/lawmo/lawmo_account.h"
24 #include <vconf.h>
25
26 #ifndef OMADM_AGENT_LOG
27 #undef LOG_TAG
28 #define LOG_TAG "LAWMO_ENGINE"
29 #endif
30
31 int register_lawmo_account(int item_id, void *user_data)
32 {
33         _EXTERN_FUNC_ENTER;
34
35         int ret = 1;
36         sync_agent_dm_mo_error_e err = 1;
37         int count = 0;
38         int value = 0;
39
40 /*int db_ret = 0;
41  * db_ret = sync_agent_open_agent();
42         _DEBUG_INFO("OPEN DACI : %d", db_ret);*/
43
44         set_alarm_config_int(LAWMO_ACCOUNT_FLAG_TYPE, LAWMO_ACCOUNT_FLAG, 0, LAWMO_ENGINE);
45         value = get_config_int(LAWMO_ACCOUNT_FLAG_TYPE, LAWMO_ACCOUNT_FLAG);
46
47         _DEBUG_INFO("lawmo account flag : %d ", value);
48
49         if (value != 1) {
50                 do {
51                         err = sync_agent_initialize_mo(7);
52                         if (err == SYNC_AGENT_DM_MO_FAIL) {
53                                 _DEBUG_INFO("fail register lawmo account : %d ", err);
54                                 ret = 0;
55                         } else {
56                                 _DEBUG_INFO("success register lawmo account : %d ", err);
57                                 break;
58                         }
59                         count++;
60                 } while (err == SYNC_AGENT_DM_MO_FAIL && count < 3);
61
62                 if (err == SYNC_AGENT_DM_MO_FAIL) {
63                         _DEBUG_INFO("add lawmo account registration alarm : %d ", ret);
64                         ret = set_account_registration_alarm(LAWMO_ACCOUNT_ALARM, LAWMO_ACCOUNT_ALARM_TYPE);
65                         _DEBUG_INFO("set account registration alarm lawmo account : %d ", ret);
66                         ret = 0;
67                 } else {
68                         ret = set_config_int(LAWMO_ACCOUNT_FLAG_TYPE, LAWMO_ACCOUNT_FLAG, 1, LAWMO_ENGINE, 0);
69                         _DEBUG_INFO("add lawmo account flag type setting result : %d ", ret);
70                         delete_account_registration_alarm(LAWMO_ACCOUNT_ALARM, LAWMO_ACCOUNT_ALARM_TYPE);
71                         _DEBUG_INFO("delete lawmo account delete alarm");
72                 }
73         } else {
74                 //do nothing
75         }
76
77 /*      db_ret = sync_agent_close_agent();
78         _DEBUG_INFO("CLOSE DACI : %d", db_ret);*/
79
80         _DEBUG_INFO("end : %d", ret);
81         _EXTERN_FUNC_EXIT;
82         return ret;
83 }
84
85 int deregister_lawmo_account(int item_id, void *user_data)
86 {
87         _EXTERN_FUNC_ENTER;
88         int ret = 1;
89
90         ret = sync_agent_open_agent();
91         _DEBUG_INFO("OPEN DACI : %d", ret);
92
93         //set_alarm_config_int(LAWMO_ACCOUNT_FLAG_TYPE, LAWMO_ACCOUNT_FLAG, 0, LAWMO_ENGINE);
94         set_config_int(LAWMO_ACCOUNT_FLAG_TYPE, LAWMO_ACCOUNT_FLAG, 0, LAWMO_ENGINE, 0);
95         _DEBUG_INFO("lawmo account flag 0");
96
97         ret = sync_agent_close_agent();
98         _DEBUG_INFO("CLOSE DACI : %d", ret);
99
100         _EXTERN_FUNC_EXIT;
101         return ret;
102 }