]> git.ipfire.org Git - thirdparty/squid.git/blob - src/event.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / event.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_EVENT_H
10 #define SQUID_EVENT_H
11
12 #include "AsyncEngine.h"
13 #include "MemPool.h"
14
15 class StoreEntry;
16
17 /* event scheduling facilities - run a callback after a given time period. */
18
19 typedef void EVH(void *);
20
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 *);
27
28 class ev_entry
29 {
30
31 public:
32 ev_entry(char const * name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
33 ~ev_entry();
34 MEMPROXY_CLASS(ev_entry);
35 const char *name;
36 EVH *func;
37 void *arg;
38 double when;
39
40 int weight;
41 bool cbdata;
42
43 ev_entry *next;
44 };
45
46 MEMPROXY_CLASS_INLINE(ev_entry);
47
48 // manages time-based events
49 class EventScheduler : public AsyncEngine
50 {
51
52 public:
53 EventScheduler();
54 ~EventScheduler();
55 /* cancel a scheduled but not dispatched event */
56 void cancel(EVH * func, void * arg);
57 /* clean up the used memory in the scheduler */
58 void clean();
59 /* either EVENT_IDLE or milliseconds remaining until the next event */
60 int timeRemaining() const;
61 /* cache manager output for the event queue */
62 void dump(StoreEntry *);
63 /* find a scheduled event */
64 bool find(EVH * func, void * arg);
65 /* schedule a callback function to run in when seconds */
66 void schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
67 int checkEvents(int timeout);
68 static EventScheduler *GetInstance();
69
70 private:
71 static EventScheduler _instance;
72 ev_entry * tasks;
73 };
74
75 #endif /* SQUID_EVENT_H */