tizen 2.3.1 release
[kernel/api/system-resource.git] / src / network / options.c
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2013 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 /*
21  * @file options.c
22  *
23  * @desc Implementation of API for option tweaking:
24  *      wifi - collect information for wifi
25  *      datacall - collect information for packet data
26  *      datausage_time - kernel update period
27  *
28  *
29  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
30  *
31  */
32
33 #include <errno.h>
34 #include <sys/socket.h>
35 #include <sys/un.h>
36 #include <unistd.h>
37 #include <vconf/vconf.h>
38
39 #include "macro.h"
40 #include "settings.h"
41 #include "trace.h"
42 #include "resourced.h"
43 #include "const.h"
44
45 static int save_options(const resourced_options *options)
46 {
47         if (!options) {
48                 _E("Please provid valid argument!");
49                 return -1;
50         }
51
52         if (vconf_set_bool(RESOURCED_WIFI_STATISTICS_PATH,
53                 options->wifi ==  RESOURCED_OPTION_ENABLE ? 1 : 0) != 0) {
54                 _D("Can not get WiFi statistics settings");
55                 return -1;
56         }
57
58         if (vconf_set_bool(RESOURCED_DATACALL_PATH,
59                 options->datacall == RESOURCED_OPTION_ENABLE ? 1 : 0) != 0) {
60                 _D("Can not get DataCall settings");
61                 return -1;
62         }
63
64         if (vconf_set_int(RESOURCED_DATAUSAGE_TIMER_PATH,
65                 options->datausage_timer) != 0) {
66                 _D("Can not get DataUsage timer settings");
67                 return -1;
68         }
69
70         if (vconf_set_bool(RESOURCED_DATACALL_LOGGING_PATH,
71                 options->datacall_logging == RESOURCED_OPTION_ENABLE ? 1 : 0) != 0) {
72                 _D("Can not get DataCall logging settings");
73                 return -1;
74         }
75         return 0;
76 }
77
78 API resourced_ret_c set_resourced_options(const resourced_options *options)
79 {
80         return save_options(options) ? RESOURCED_ERROR_FAIL : RESOURCED_ERROR_NONE;
81 }
82
83 API resourced_ret_c get_resourced_options(resourced_options *options)
84 {
85         return load_options(options) ? RESOURCED_ERROR_FAIL : RESOURCED_ERROR_NONE;
86 }