]> git.ipfire.org Git - thirdparty/squid.git/blob - src/EventLoop.h
Support libecap v1.0, allowing asynchronous adapters and eCAP version checks.
[thirdparty/squid.git] / src / EventLoop.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 */
30
31 #ifndef SQUID_EVENTLOOP_H
32 #define SQUID_EVENTLOOP_H
33
34 #include "base/Vector.h"
35
36 #define EVENT_LOOP_TIMEOUT 1000 /* 1s timeout */
37
38 class AsyncEngine;
39 class TimeEngine;
40
41 /** An event loop. An event loop is the core inner loop of squid.
42 * The event loop can be run until exit, or once. After it finishes control
43 * returns to the caller. If desired it can be run again.
44 \par
45 * The event loop cannot be run once it is running until it has finished.
46 */
47 class EventLoop
48 {
49
50 public:
51 EventLoop();
52
53 /** register an async engine which will be given the opportunity to perform
54 * in-main-thread tasks each event loop.
55 */
56 void registerEngine(AsyncEngine *engine);
57
58 /** start the event loop running. The loop will run until it is stopped by
59 * calling stop(), or when the loop is completely idle - nothing
60 * dispatched in a loop, and all engines idle.
61 */
62 void run();
63
64 /** run the loop once. This may not complete all events! It should therefor
65 * be used with care.
66 * TODO: signal in runOnce whether or not the loop is over - IDLE vs OK vs
67 * TIMEOUT?
68 */
69 bool runOnce();
70
71 /** set the primary async engine. The primary async engine recieves the
72 * lowest requested timeout gathered from the other engines each loop.
73 * (There is a default of 10ms if all engines are idle or request higher
74 * delays).
75 * If no primary has been nominated, the last async engine added is
76 * implicitly the default.
77 */
78 void setPrimaryEngine(AsyncEngine * engine);
79
80 /** set the time service. There can be only one time service set at any
81 * time. The time service is invoked on each loop
82 */
83 void setTimeService(TimeEngine *engine);
84
85 /** stop the event loop - it will finish the current loop and then return to the
86 * caller of run().
87 */
88 void stop();
89
90 int errcount;
91
92 /// the [main program] loop running now; may be nil
93 /// for simplicity, we assume there are no concurrent loops
94 static EventLoop *Running;
95
96 private:
97 /** setup state variables prior to running */
98 void prepareToRun();
99
100 /** check an individual engine */
101 void checkEngine(AsyncEngine * engine, bool const primary);
102
103 /** dispatch calls and events scheduled during checkEngine() */
104 bool dispatchCalls();
105
106 bool last_loop;
107 typedef Vector<AsyncEngine *> engine_vector;
108 engine_vector engines;
109 TimeEngine * timeService;
110 AsyncEngine * primaryEngine;
111 int loop_delay; /**< the delay to be given to the primary engine */
112 bool error; /**< has an error occured in this loop */
113 bool runOnceResult; /**< the result from runOnce */
114 };
115
116 #endif /* SQUID_EVENTLOOP_H */