tizen 2.3 release
[kernel/api/system-resource.git] / src / network / network.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 network.c
22  *
23  * @desc Entity for storing applications statistics
24  *
25  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
26  *
27  */
28
29 #include <stdio.h>
30
31 #include "data_usage.h"
32 #include "datausage-restriction.h"
33 #include "macro.h"
34 #include "net-cls-cgroup.h"
35 #include "rd-network.h"
36 #include "resourced.h"
37
38 API network_error_e network_set_option(const network_option_s *options)
39 {
40         return (network_error_e)set_resourced_options((const resourced_options*)options);
41 }
42
43 API network_error_e network_get_option(network_option_s *options)
44 {
45         return (network_error_e)get_resourced_options((resourced_options*)options);
46 }
47
48 API network_error_e network_make_cgroup_with_pid(const int pid,
49         const char *pkg_name)
50 {
51         return (network_error_e)make_net_cls_cgroup_with_pid(pid, pkg_name);
52 }
53
54 API u_int32_t network_get_classid_by_pkg_name(const char *pkg_name, int create)
55 {
56         return (network_error_e)get_classid_by_pkg_name(pkg_name, create);
57 }
58
59 API network_error_e network_set_restriction(const char *app_id,
60                             const network_restriction_s *restriction)
61 {
62         return (network_error_e)set_net_restriction(app_id,
63                         (const resourced_net_restrictions*)restriction);
64 }
65
66 API network_error_e network_restriction_foreach(network_restriction_cb restriction_cb,
67                                 void *user_data)
68 {
69         return (network_error_e)restrictions_foreach((resourced_restriction_cb)restriction_cb, user_data);
70 }
71
72 API network_error_e network_remove_restriction(const char *app_id)
73 {
74         return (network_error_e)remove_restriction(app_id);
75 }
76
77 API network_error_e network_remove_restriction_by_iftype(const char *app_id,
78                                              const network_iface_e iftype)
79 {
80         return (network_error_e)remove_restriction_by_iftype(app_id, (const resourced_iface_type)iftype);
81 }
82
83 API network_error_e network_exclude_restriction(const char *app_id)
84 {
85         return (network_error_e)exclude_restriction(app_id);
86 }
87
88 API network_error_e network_exclude_restriction_by_iftype(
89         const char *app_id, const network_iface_e iftype)
90 {
91         return (network_error_e)exclude_restriction_by_iftype(
92                 app_id, (const resourced_iface_type)iftype);
93 }
94
95 API network_error_e network_register_activity_cb(network_activity_cb activity_cb)
96 {
97         return (network_error_e)register_net_activity_cb((net_activity_cb)activity_cb);
98 }
99
100 API network_error_e network_join_app_performance(const char *app_id, const pid_t pid)
101 {
102         return (network_error_e)join_app_performance(app_id, pid);
103 }
104
105 API network_error_e network_update_statistics(void)
106 {
107         return (network_error_e)resourced_update_statistics();
108 }
109
110 API network_error_e network_foreach(const network_selection_rule_s *rule,
111                              network_info_cb info_cb, void *user_data)
112 {
113         return (network_error_e)data_usage_foreach(
114                         (const data_usage_selection_rule*)rule,
115                         (data_usage_info_cb)info_cb,
116                         user_data);
117 }
118
119 API network_error_e network_details_foreach(const char *app_id,
120                                            network_selection_rule_s *rule,
121                                            network_info_cb info_cb,
122                                            void *user_data)
123 {
124         return (network_error_e)data_usage_details_foreach(app_id,
125                         (data_usage_selection_rule*)rule,
126                         (data_usage_info_cb)info_cb,
127                         user_data);
128 }
129
130 API network_error_e network_reset(const network_reset_rule_s *rule)
131 {
132         return (network_error_e)reset_data_usage((const data_usage_reset_rule*)rule);
133 }
134
135 API network_error_e network_remove_quota(
136         const network_quota_reset_rule_s *rule)
137 {
138         return (network_error_e)remove_datausage_quota(
139                         (const struct datausage_quota_reset_rule*)rule);
140 }
141
142 API network_error_e network_remove_quota_by_iftype(
143         const char *app_id, const network_iface_e iftype)
144 {
145         return (network_error_e)remove_datausage_quota_by_iftype(app_id,
146                         (const resourced_iface_type)iftype);
147 }
148
149 API network_error_e network_set_quota(const char *app_id,
150                               const network_quota_s *quota)
151 {
152         return (network_error_e)set_datausage_quota(app_id,
153                         (const data_usage_quota*)quota);
154 }
155
156 API network_error_e network_get_restriction_state(const char *pkg_id,
157         network_iface_e iftype, network_restriction_state *state)
158 {
159         return (network_error_e)get_restriction_state(pkg_id,
160                 (const resourced_iface_type)iftype,
161                 (resourced_restriction_state *)state);
162 }