]> git.ipfire.org Git - thirdparty/squid.git/blame - src/event.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / event.h
CommitLineData
a553a5a3 1/*
b8ae064d 2 * Copyright (C) 1996-2023 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"
1a51cf72 13#include "base/Packable.h"
ed6e9fb9 14#include "mem/forward.h"
a553a5a3 15
a553a5a3 16/* event scheduling facilities - run a callback after a given time period. */
17
18typedef void EVH(void *);
19
314782d4
FC
20void eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata=true);
21void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int);
22void eventDelete(EVH * func, void *arg);
23void eventInit(void);
314782d4 24int eventFind(EVH *, void *);
a553a5a3 25
26class ev_entry
27{
741c2986 28 MEMPROXY_CLASS(ev_entry);
a553a5a3 29
30public:
31 ev_entry(char const * name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
5dee3116 32 ~ev_entry();
a553a5a3 33 const char *name;
34 EVH *func;
35 void *arg;
36 double when;
37
38 int weight;
39 bool cbdata;
40
d0e71436 41 ev_entry *next;
a553a5a3 42};
43
5dee3116 44// manages time-based events
8ff3fa2e 45class EventScheduler : public AsyncEngine
a553a5a3 46{
47
48public:
5dee3116 49 EventScheduler();
337b9aa4 50 ~EventScheduler() override;
a553a5a3 51 /* cancel a scheduled but not dispatched event */
52 void cancel(EVH * func, void * arg);
53 /* clean up the used memory in the scheduler */
54 void clean();
aa14d759
AR
55 /* either EVENT_IDLE or milliseconds remaining until the next event */
56 int timeRemaining() const;
a553a5a3 57 /* cache manager output for the event queue */
1a51cf72 58 void dump(Packable *);
a553a5a3 59 /* find a scheduled event */
60 bool find(EVH * func, void * arg);
61 /* schedule a callback function to run in when seconds */
62 void schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
337b9aa4 63 int checkEvents(int timeout) override;
a553a5a3 64 static EventScheduler *GetInstance();
65
66private:
67 static EventScheduler _instance;
a553a5a3 68 ev_entry * tasks;
69};
70
71#endif /* SQUID_EVENT_H */
f53969cc 72