Tizen 2.0 Release
[pkgs/o/oma-ds-service.git] / src / agent / service-engine / se_notification.c
1 /*
2  * oma-ds-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 /**
19  *   @SE_Notification.c
20  *   @version                                                                   0.1
21  *   @brief                                                                             This file is the source file of implementation of notify to ui
22  */
23
24 #include <aul.h>
25
26 #include <sync_agent.h>
27
28 #include "service-engine/se_notification.h"
29 #include "service-engine/se_sync.h"
30
31 #ifndef OMADS_AGENT_LOG
32 #undef LOG_TAG
33 #define LOG_TAG "OMA_DS_SE"
34 #endif
35
36 #define NOTI_KEY        "OMADS"
37 #define OMA_DS_UI_PKG "ug-setting-synchronise-efl"
38
39 se_error_type_e send_noti_session_process(char *profile, char *sync_type, char *progress, char *error)
40 {
41         _EXTERN_FUNC_ENTER;
42
43         se_error_type_e err = SE_INTERNAL_OK;
44
45         int notiType = 1;
46         sync_agent_event_data_s *noti = NULL;
47
48         if (profile == NULL) {
49                 _DEBUG_ERROR("Not Defined profile");
50                 err = SE_INTERNAL_NOT_DEFINED;
51                 goto error;
52         }
53
54         noti = sync_agent_create_noti(notiType);
55         if (noti == NULL) {
56                 _DEBUG_ERROR("failed to sync_agent_create_noti");
57                 err = SE_INTERNAL_NO_MEMORY;
58                 goto error;
59         }
60
61         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile);
62         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type);
63         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)progress);
64         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)error);
65
66         sync_agent_event_error_e event_err;
67         sync_agent_send_noti(NOTI_KEY, noti, NULL, NULL, &event_err);
68         if (event_err != SYNC_AGENT_EVENT_SUCCESS) {
69                 if (aul_app_is_running(OMA_DS_UI_PKG)) {
70                         _DEBUG_ERROR("failed to sync_agent_send_noti");
71                         err = SE_INTERNAL_EVENT_ERROR;
72                         goto error;
73                 }
74         }
75
76  error:
77
78         sync_agent_free_noti(noti);
79
80         _EXTERN_FUNC_EXIT;
81         return err;
82 }
83
84 se_error_type_e send_noti_process_update(char *profile_dir_name, char *sync_type, char *uri, char *progress_status, char *operation_type, int is_from_server, int total_per_operation, int synced_per_operation, int total_per_db, int synced_per_db)
85 {
86         _EXTERN_FUNC_ENTER;
87
88         se_error_type_e err = SE_INTERNAL_OK;
89
90         int notiType = 2;
91         sync_agent_event_data_s *noti = NULL;
92
93         if (profile_dir_name == NULL) {
94                 _DEBUG_ERROR("Not Defined profileDirName");
95                 err = SE_INTERNAL_NOT_DEFINED;
96                 goto error;
97         }
98
99         noti = sync_agent_create_noti(notiType);
100         if (noti == NULL) {
101                 _DEBUG_ERROR("failed to sync_agent_create_noti");
102                 err = SE_INTERNAL_NO_MEMORY;
103                 goto error;
104         }
105
106         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)profile_dir_name);
107         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)sync_type);
108         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)uri);
109         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)progress_status);
110         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, (void *)operation_type);
111         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &is_from_server);
112         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &total_per_operation);
113         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &synced_per_operation);
114         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &total_per_db);
115         sync_agent_append_event_data_param(noti, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &synced_per_db);
116
117         sync_agent_event_error_e event_err;
118         sync_agent_send_noti(NOTI_KEY, noti, NULL, NULL, &event_err);
119         if (event_err != SYNC_AGENT_EVENT_SUCCESS) {
120                 if (aul_app_is_running(OMA_DS_UI_PKG)) {
121                         _DEBUG_ERROR("failed to sync_agent_send_noti");
122                         err = SE_INTERNAL_EVENT_ERROR;
123                         goto error;
124                 }
125         }
126
127  error:
128
129         sync_agent_free_noti(noti);
130
131         _EXTERN_FUNC_EXIT;
132         return err;
133 }