1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2016 Brazil
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License version 2.1 as published by the Free Software Foundation.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17*/
18
19#include "grn_ctx.h"
20#include "grn_request_timer.h"
21
22static grn_request_timer grn_current_request_timer = { 0 };
23static double grn_request_timer_default_timeout = 0.0;
24
25grn_bool
26grn_request_timer_init(void)
27{
28 return GRN_TRUE;
29}
30
31void *
32grn_request_timer_register(const char *request_id,
33 unsigned int request_id_size,
34 double timeout)
35{
36 void *timer_id = NULL;
37
38 if (grn_current_request_timer.register_func) {
39 void *user_data = grn_current_request_timer.user_data;
40 timer_id = grn_current_request_timer.register_func(request_id,
41 request_id_size,
42 timeout,
43 user_data);
44 }
45
46 return timer_id;
47}
48
49void
50grn_request_timer_unregister(void *timer_id)
51{
52 if (grn_current_request_timer.unregister_func) {
53 void *user_data = grn_current_request_timer.user_data;
54 grn_current_request_timer.unregister_func(timer_id, user_data);
55 }
56}
57
58void
59grn_request_timer_set(grn_request_timer *timer)
60{
61 if (grn_current_request_timer.fin_func) {
62 void *user_data = grn_current_request_timer.user_data;
63 grn_current_request_timer.fin_func(user_data);
64 }
65 if (timer) {
66 grn_current_request_timer = *timer;
67 } else {
68 memset(&grn_current_request_timer, 0, sizeof(grn_request_timer));
69 }
70}
71
72double
73grn_get_default_request_timeout(void)
74{
75 return grn_request_timer_default_timeout;
76}
77
78void
79grn_set_default_request_timeout(double timeout)
80{
81 grn_request_timer_default_timeout = timeout;
82}
83
84void
85grn_request_timer_fin(void)
86{
87 grn_request_timer_set(NULL);
88}
89