tizen 2.3 release
[kernel/api/system-resource.git] / src / common / app-stat.h
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: app-stat.h
22  *
23  *  @desc Application stat entity
24  *  @version 1.0
25  *
26  */
27
28 #ifndef _RESOURCED_APPLICATION_STAT_H_
29 #define _RESOURCED_APPLICATION_STAT_H_
30
31 #include <netinet/in.h>
32 #include <glib.h>
33 #include <sys/types.h>
34
35 #include "const.h"
36 #include "data_usage.h"
37 #include "daemon-options.h"
38 #include "transmission.h"
39
40 #define RSML_UNKNOWN_CLASSID 1
41
42 /*
43 * General structure containing information for storing
44 * application_id - package name as unique application identifier
45 * snd_count - sent bytes
46 * rcv_count - received bytes
47 * pid - process identifier
48 * ifindex - network interface index, iftype holds in key @see resourced_iface_type
49 * is_roaming - is traffic consumed at roaming, @see resourced_roaming_type
50 */
51 struct application_stat {
52         char *application_id;
53         uint32_t snd_count;
54         uint32_t rcv_count;
55         uint32_t delta_snd;
56         uint32_t delta_rcv;
57
58         pid_t pid;
59         int ifindex;
60         resourced_roaming_type is_roaming;
61 };
62
63 /*
64 * Structure for holding serialized data from kernel @see traffic_event
65 */
66 struct traffic_stat {
67         unsigned long bytes;
68         int ifindex;
69 };
70
71 struct classid_iftype_key
72 {
73         u_int32_t classid;
74         int iftype;
75         char ifname[MAX_NAME_LENGTH];
76 };
77
78 typedef GTree traffic_stat_tree;
79
80 struct application_stat_tree {
81         GTree *tree;
82         time_t last_touch_time;
83         pthread_rwlock_t guard;
84 };
85
86 struct application_stat_tree *create_app_stat_tree(void);
87 void free_app_stat_tree(struct application_stat_tree *tree);
88 void nulify_app_stat_tree(struct application_stat_tree **tree);
89
90 traffic_stat_tree *create_traffic_stat_tree(void);
91 void free_traffic_stat_tree(traffic_stat_tree *list);
92
93 resourced_ret_c prepare_application_stat(traffic_stat_tree *tree_in,
94                  traffic_stat_tree *tree_out,
95                  struct application_stat_tree *result,
96                  volatile struct daemon_opts *opts);
97
98
99 #endif /* _RESOURCED_APPLICATION_STAT_H_ */