]>
Commit | Line | Data |
---|---|---|
a553a5a3 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
a553a5a3 | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
a553a5a3 | 7 | */ |
8 | ||
9 | #ifndef SQUID_EVENT_H | |
10 | #define SQUID_EVENT_H | |
11 | ||
8ff3fa2e | 12 | #include "AsyncEngine.h" |
ed6e9fb9 | 13 | #include "mem/forward.h" |
a553a5a3 | 14 | |
15 | class StoreEntry; | |
16 | ||
17 | /* event scheduling facilities - run a callback after a given time period. */ | |
18 | ||
19 | typedef void EVH(void *); | |
20 | ||
314782d4 FC |
21 | void eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata=true); |
22 | void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int); | |
23 | void eventDelete(EVH * func, void *arg); | |
24 | void eventInit(void); | |
25 | void eventFreeMemory(void); | |
26 | int eventFind(EVH *, void *); | |
a553a5a3 | 27 | |
28 | class ev_entry | |
29 | { | |
741c2986 | 30 | MEMPROXY_CLASS(ev_entry); |
a553a5a3 | 31 | |
32 | public: | |
33 | ev_entry(char const * name, EVH * func, void *arg, double when, int weight, bool cbdata=true); | |
5dee3116 | 34 | ~ev_entry(); |
a553a5a3 | 35 | const char *name; |
36 | EVH *func; | |
37 | void *arg; | |
38 | double when; | |
39 | ||
40 | int weight; | |
41 | bool cbdata; | |
42 | ||
d0e71436 | 43 | ev_entry *next; |
a553a5a3 | 44 | }; |
45 | ||
5dee3116 | 46 | // manages time-based events |
8ff3fa2e | 47 | class EventScheduler : public AsyncEngine |
a553a5a3 | 48 | { |
49 | ||
50 | public: | |
5dee3116 | 51 | EventScheduler(); |
a553a5a3 | 52 | ~EventScheduler(); |
53 | /* cancel a scheduled but not dispatched event */ | |
54 | void cancel(EVH * func, void * arg); | |
55 | /* clean up the used memory in the scheduler */ | |
56 | void clean(); | |
aa14d759 AR |
57 | /* either EVENT_IDLE or milliseconds remaining until the next event */ |
58 | int timeRemaining() const; | |
a553a5a3 | 59 | /* cache manager output for the event queue */ |
60 | void dump(StoreEntry *); | |
61 | /* find a scheduled event */ | |
62 | bool find(EVH * func, void * arg); | |
63 | /* schedule a callback function to run in when seconds */ | |
64 | void schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata=true); | |
8ff3fa2e | 65 | int checkEvents(int timeout); |
a553a5a3 | 66 | static EventScheduler *GetInstance(); |
67 | ||
68 | private: | |
69 | static EventScheduler _instance; | |
a553a5a3 | 70 | ev_entry * tasks; |
71 | }; | |
72 | ||
73 | #endif /* SQUID_EVENT_H */ | |
f53969cc | 74 |