Gcov automation
[platform/core/messaging/msg-service.git] / utils / MsgGconfWrapper.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 */
16
17 #include <stdio.h>
18
19 #include "MsgDebug.h"
20 #include "MsgUtilStorage.h"
21 #include "MsgGconfWrapper.h"
22 #include "MsgException.h"
23
24 int autoReject = 0;
25 bool bUnknownAutoReject = false;
26
27
28
29 /*==================================================================================================
30                                      FUNCTION IMPLEMENTATION
31 ==================================================================================================*/
32
33 msg_error_t MsgSettingSetString(const char *pKey, const char *pSetValue)
34 {
35         if (pKey == NULL || pSetValue == NULL) {
36                 MSG_DEBUG("IN Parameter is NULL");
37                 return MSG_ERR_NULL_POINTER;
38         }
39
40         if (vconf_set_str(pKey, pSetValue) != 0) {
41                 int vconf_err = vconf_get_ext_errno();
42                 MSG_DEBUG("Fail to vconf_set_str with [%s], err=[%d]", pKey, vconf_err);
43                 return MSG_ERR_SET_SETTING;
44         }
45
46         return MSG_SUCCESS;
47 }
48
49
50 msg_error_t MsgSettingSetInt(const char *pKey, int nSetValue)
51 {
52         if (pKey == NULL) {
53                 MSG_DEBUG("IN Parameter is NULL");
54                 return MSG_ERR_NULL_POINTER;
55         }
56
57         if (vconf_set_int(pKey, nSetValue) != 0) {
58                 int vconf_err = vconf_get_ext_errno();
59                 MSG_DEBUG("Fail to vconf_set_int with [%s], err=[%d]", pKey, vconf_err);
60                 return MSG_ERR_SET_SETTING;
61         }
62
63         return MSG_SUCCESS;
64 }
65
66
67 msg_error_t MsgSettingSetBool(const char *pKey, bool bSetValue)
68 {
69         if (pKey == NULL) {
70                 MSG_DEBUG("IN Parameter is NULL");
71                 return MSG_ERR_NULL_POINTER;
72         }
73
74         if (vconf_set_bool(pKey, bSetValue) != 0) {
75                 int vconf_err = vconf_get_ext_errno();
76                 MSG_DEBUG("Fail to vconf_set_bool with [%s], err=[%d]", pKey, vconf_err);
77                 return MSG_ERR_SET_SETTING;
78         }
79
80         return MSG_SUCCESS;
81 }
82
83
84 msg_error_t MsgSettingGetString(const char *pKey, char **pVal)
85 {
86         if (pKey == NULL) {
87                 MSG_DEBUG("IN Parameter is NULL");
88                 return MSG_ERR_NULL_POINTER;
89         }
90
91         msg_error_t retVal = MSG_SUCCESS;
92         char *param = NULL;
93
94         param = vconf_get_str(pKey);
95         if (param == NULL) {
96                 int vconf_err = vconf_get_ext_errno();
97                 MSG_DEBUG("Fail to vconf_get_str with [%s], err=[%d]", pKey, vconf_err);
98                 if (vconf_err == VCONF_ERROR_FILE_PERM)
99                         retVal = MSG_ERR_PERMISSION_DENIED;
100                 else
101                         retVal = MSG_ERR_UNKNOWN;
102         }
103
104         *pVal = param;
105
106         return retVal;
107 }
108
109
110 msg_error_t MsgSettingGetInt(const char *pKey, int *pVal)
111 {
112         if (pKey == NULL) {
113                 MSG_DEBUG("IN Parameter is NULL");
114                 return -1;
115         }
116
117         msg_error_t retVal = MSG_SUCCESS;
118         int param = 0;
119
120         if (vconf_get_int(pKey, &param) != 0) {
121                 int vconf_err = vconf_get_ext_errno();
122                 MSG_DEBUG("Fail to vconf_get_int with [%s], err=[%d]", pKey, vconf_err);
123                 if (vconf_err == VCONF_ERROR_FILE_PERM)
124                         retVal = MSG_ERR_PERMISSION_DENIED;
125                 else
126                         retVal = MSG_ERR_UNKNOWN;
127         }
128
129         *pVal = (int)param;
130
131         return retVal;
132 }
133
134
135 msg_error_t MsgSettingGetBool(const char *pKey, bool *pVal)
136 {
137         if (pKey == NULL) {
138                 MSG_DEBUG("IN Parameter is NULL");
139                 return -1;
140         }
141
142         msg_error_t retVal = MSG_SUCCESS;
143         int param = 0;
144
145         if (vconf_get_bool(pKey, &param) != 0) {
146                 int vconf_err = vconf_get_ext_errno();
147                 MSG_DEBUG("Fail to vconf_get_bool with [%s], err=[%d]", pKey, vconf_err);
148                 if (vconf_err == VCONF_ERROR_FILE_PERM)
149                         retVal = MSG_ERR_PERMISSION_DENIED;
150                 else
151                         retVal = MSG_ERR_UNKNOWN;
152         }
153
154         *pVal = (bool)param;
155
156         return retVal;
157 }
158
159
160 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
161 {
162         MSG_BEGIN();
163
164         MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
165
166         /* Set Msg Count into VConf */
167         if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS) {
168                 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
169                 return MSG_ERR_SET_SETTING;
170         }
171
172 #if 0
173         if (SmsCnt == 0 && MmsCnt == 0) {
174                 MSG_DEBUG("No New Message.");
175         } else {
176                 MSG_DEBUG("New Message.");
177
178                 bool bNotification = true;
179
180                 if (MsgSettingGetBool(MSG_SETTING_NOTIFICATION, &bNotification) != MSG_SUCCESS) {
181                         MSG_DEBUG("MsgSettingGetBool is failed.");
182                 }
183
184                 if (bNotification)
185                         MsgChangePmState();
186         }
187 #endif
188
189         MSG_END();
190
191         return MSG_SUCCESS;
192 }
193
194
195 msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
196 {
197         if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
198                 return MSG_ERR_SET_SETTING;
199         if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
200                 return MSG_ERR_SET_SETTING;
201
202         return MSG_SUCCESS;
203 }
204
205
206 int MsgSettingGetAutoReject()
207 {
208         return autoReject;
209 }
210
211 bool MsgSettingGetUnknownAutoReject()
212 {
213         return bUnknownAutoReject;
214 }
215
216 msg_error_t MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
217 {
218         msg_error_t err = MSG_SUCCESS;
219
220         if (vconf_notify_key_changed(pKey, pCb, NULL) != 0) {
221                 int vconf_err = vconf_get_ext_errno();
222                 MSG_DEBUG("Fail to vconf_notify_key_changed with [%s], err=[%d]", pKey, vconf_err);
223                 if (vconf_err == VCONF_ERROR_FILE_PERM)
224                         err = MSG_ERR_PERMISSION_DENIED;
225                 else
226                         err = MSG_ERR_UNKNOWN;
227         } else {
228                 MSG_DEBUG("Success to regist vconf CB with [%s]", pKey);
229         }
230
231         return err;
232 }
233
234 msg_error_t MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
235 {
236         msg_error_t err = MSG_SUCCESS;
237
238         if (vconf_ignore_key_changed(pKey, pCb) != 0) {
239                 int vconf_err = vconf_get_ext_errno();
240                 MSG_DEBUG("Fail to vconf_ignore_key_changed [%s], err=[%d]", pKey, vconf_err);
241                 if (vconf_err == VCONF_ERROR_FILE_PERM)
242                         err = MSG_ERR_PERMISSION_DENIED;
243                 else
244                         err = MSG_ERR_UNKNOWN;
245         } else {
246                 MSG_DEBUG("Success to remove vconf CB with [%s]", pKey);
247         }
248
249         return err;
250 }