tizen 2.3 release
[kernel/api/system-resource.git] / src / network / counter.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: counter.c
21  *  @desc Entity for working with datausage counter.
22  *
23  */
24
25 #include "app-stat.h"
26 #include "counter.h"
27 #include "macro.h"
28 #include "trace.h"
29
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <sys/socket.h>
33
34 struct counter_arg *init_counter_arg(struct daemon_opts *opts)
35 {
36         struct counter_arg *result =
37                 (struct counter_arg *)calloc(1, sizeof(struct counter_arg));
38
39         ret_value_msg_if(result == NULL, NULL, "Not enough memory\n");
40 #ifndef CONFIG_DATAUSAGE_NFACCT
41         result->pid = getpid();
42 #endif
43         result->opts = opts;
44         return result;
45 }
46
47 void finalize_carg(struct counter_arg *carg)
48 {
49         free(carg);
50 }
51
52 void reschedule_count_timer(const struct counter_arg *carg, const double delay)
53 {
54         ret_msg_if(!carg || !carg->ecore_timer,
55                          "Invalid counter argument or carg_timer is null\n");
56         ecore_timer_delay(carg->ecore_timer,
57                           delay - ecore_timer_pending_get(carg->ecore_timer));
58 }