tizen 2.3 release
[kernel/api/system-resource.git] / src / network / datausage-vconf-callbacks.c
1 /*
2  * resourced
3  *
4  * Copyright (c) 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 /*
20  *  @file: datausage-vconf-callbacks.c
21  *
22  *  @desc Add datausage callback functions to vconf
23  *
24  */
25
26 #include "const.h"
27 #include "counter.h"
28 #include "daemon-options.h"
29 #include "datausage-vconf-callbacks.h"
30 #include "datausage-quota-processing.h"
31 #include "datausage-quota.h"
32 #include "iface.h"
33 #include "macro.h"
34 #include "resourced.h"
35 #include "settings.h"
36 #include "trace.h"
37
38 #include <stdlib.h>
39 #include <vconf.h>
40
41 static void wifi_change_cb(keynode_t *key, void *data)
42 {
43         int val = vconf_keynode_get_bool(key);
44         _SD("key = %s, value = %d(int)\n",
45             vconf_keynode_get_name(key), val);
46         set_wifi_allowance(val ?
47                            RESOURCED_OPTION_ENABLE : RESOURCED_OPTION_DISABLE);
48 }
49
50 static void datacall_change_cb(keynode_t *key, void *data)
51 {
52         int val = vconf_keynode_get_bool(key);
53
54         _SD("key = %s, value = %d(int)\n",
55             vconf_keynode_get_name(key), val);
56         set_datacall_allowance(val ? RESOURCED_OPTION_ENABLE :
57                                RESOURCED_OPTION_DISABLE);
58 }
59
60 static void datacall_logging_change_cb(keynode_t *key, void *data)
61 {
62         struct daemon_opts *options = (struct daemon_opts *)data;
63         int val = vconf_keynode_get_bool(key);
64
65         if (!options) {
66                 _E("Please provide valid argument!");
67                 return;
68         }
69         _SD("key = %s, value = %d(int)\n",
70             vconf_keynode_get_name(key), val);
71         options->datacall_logging = val ? RESOURCED_OPTION_ENABLE :
72                 RESOURCED_OPTION_DISABLE;
73 }
74
75 static void datausage_timer_change_cb(keynode_t *key, void *data)
76 {
77         struct daemon_opts *options = (struct daemon_opts *)data;
78         int val = vconf_keynode_get_int(key);
79
80         if (!options) {
81                 _E("Please provide valid argument!");
82                 return;
83         }
84         _SD("key = %s, value = %d(int)\n",
85             vconf_keynode_get_name(key), val);
86
87         options->update_period = val;
88 }
89
90 void resourced_add_vconf_datausage_cb(struct counter_arg *carg)
91 {
92         _D("Add vconf datausage callbacks\n");
93         ret_msg_if(!carg || !carg->opts,
94                          "Please provide valid argument!");
95         vconf_notify_key_changed(RESOURCED_WIFI_STATISTICS_PATH, wifi_change_cb,
96                                  NULL);
97         vconf_notify_key_changed(RESOURCED_DATACALL_PATH, datacall_change_cb,
98                                  NULL);
99         vconf_notify_key_changed(RESOURCED_DATAUSAGE_TIMER_PATH,
100                                  datausage_timer_change_cb, (void *)carg->opts);
101         vconf_notify_key_changed(RESOURCED_DATACALL_LOGGING_PATH,
102                                  datacall_logging_change_cb,
103                                  (void *)carg->opts);
104 }
105
106 void resourced_remove_vconf_datausage_cb(void)
107 {
108         _D("Remove vconf datausage callbacks\n");
109         vconf_ignore_key_changed(RESOURCED_WIFI_STATISTICS_PATH,
110                                  wifi_change_cb);
111         vconf_ignore_key_changed(RESOURCED_DATACALL_PATH, datacall_change_cb);
112         vconf_ignore_key_changed(RESOURCED_DATAUSAGE_TIMER_PATH,
113                                  datausage_timer_change_cb);
114         vconf_ignore_key_changed(RESOURCED_DATACALL_LOGGING_PATH,
115                                  datacall_logging_change_cb);
116 }