Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / fumo / fumo_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 /*common*/
22 #include "common/dm_common.h"
23 #include "dm-engine/fumo/fumo_account.h"
24
25 #ifndef OMADM_AGENT_LOG
26 #undef LOG_TAG
27 #define LOG_TAG "FUMO_ENGINE"
28 #endif
29
30 int register_fota_account()
31 {
32         _EXTERN_FUNC_ENTER;
33
34         int ret = 1;
35         sync_agent_dm_mo_error_e err = 1;
36         int count = 0;
37         int value = 0;
38
39         /*
40          * check ip push registration
41          */
42         //temp code
43 /*      int db_ret = 0;
44
45         db_ret = sync_agent_open_agent();
46         _DEBUG_INFO("OPEN DACI : %d", db_ret);*/
47         set_alarm_config_int(FUMO_ACCOUNT_FLAG_TYPE, FUMO_ACCOUNT_FLAG, 0, FUMO_ENGINE);
48         value = get_config_int(FUMO_ACCOUNT_FLAG_TYPE, FUMO_ACCOUNT_FLAG);
49
50         if (value != 1) {
51                 do {
52                         err = sync_agent_initialize_mo(3);
53                         if (err == SYNC_AGENT_DM_MO_FAIL) {
54                                 _DEBUG_INFO("fail register fota account : %d ", err);
55                                 ret = 0;
56                         } else {
57                                 _DEBUG_INFO("success register fota account : %d ", err);
58                                 break;
59                         }
60                         count++;
61                 } while (err == SYNC_AGENT_DM_MO_FAIL && count < 3);
62
63                 if (err == SYNC_AGENT_DM_MO_FAIL) {
64                         ret = set_account_registration_alarm(FUMO_ACCOUNT_ALARM, FUMO_ACCOUNT_ALARM_TYPE);
65                         _DEBUG_INFO("add fota account registration alarm : %d ", ret);
66                         ret = 0;
67                 } else {
68                         ret = set_config_int(FUMO_ACCOUNT_FLAG_TYPE, FUMO_ACCOUNT_FLAG, 1, FUMO_ENGINE, 0);
69                         _DEBUG_INFO("add fota account flag type setting result : %d ", ret);
70                         delete_account_registration_alarm(FUMO_ACCOUNT_ALARM, FUMO_ACCOUNT_ALARM_TYPE);
71                         _DEBUG_INFO("delete fota 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         _DEBUG_INFO("end : %d", ret);
80         _EXTERN_FUNC_EXIT;
81         return ret;
82
83 }