tizen 2.3 release
[kernel/api/system-resource.git] / src / network / datausage-vconf-common.c
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <resourced.h>
20 #include <vconf.h>
21
22 #include "trace.h"
23 #include "data_usage.h"
24 #include "datausage-vconf-common.h"
25
26 #ifndef VCONFKEY_SETAPPL_SET_DATA_USAGE_LIMIT_BOOL
27 #define VCONFKEY_SETAPPL_SET_DATA_USAGE_LIMIT_BOOL "db/setting/set_data_usage_limit"
28 #endif
29
30 #ifndef VCONFKEY_SETAPPL_DATA_LIMIT_INT
31 #define VCONFKEY_SETAPPL_DATA_LIMIT_INT "db/setting/data_limit"
32 #endif
33
34 #ifndef VCONFKEY_SETAPPL_DATA_RESTRICTION_INT
35 #define VCONFKEY_SETAPPL_DATA_RESTRICTION_INT "db/setting/data_restriction"
36 #endif
37
38 resourced_ret_c restriction_check_limit_status(int *retval)
39 {
40         if (vconf_get_bool(VCONFKEY_SETAPPL_SET_DATA_USAGE_LIMIT_BOOL, retval)) {
41                 _E("vconf_get_bool FAIL\n");
42                 return RESOURCED_ERROR_FAIL;
43         };
44
45         return RESOURCED_ERROR_NONE;
46 }
47
48 resourced_ret_c restriction_read_quota(int *quota)
49 {
50         if (vconf_get_int(VCONFKEY_SETAPPL_DATA_LIMIT_INT, quota)) {
51                 _E("vconf_get_int FAIL\n");
52                 return RESOURCED_ERROR_FAIL;
53         };
54
55         return RESOURCED_ERROR_NONE;
56 }
57
58 void restriction_set_status(int value)
59 {
60         int limit = RESTRICTION_STATE_INIT;
61
62         if (vconf_get_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, &limit)) {
63                 _E("vconf_get_int FAIL\n");
64                 return;
65         }
66
67         if (limit == value) {
68                 _E("No need to change a restriction status: %d", limit);
69                 return;
70         }
71
72         vconf_set_int(VCONFKEY_SETAPPL_DATA_RESTRICTION_INT, value);
73         return;
74 }