]>
Commit | Line | Data |
---|---|---|
a553a5a3 | 1 | /* |
a553a5a3 | 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. | |
26ac0430 | 19 | * |
a553a5a3 | 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. | |
26ac0430 | 24 | * |
a553a5a3 | 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 | ||
c8ea3cc0 | 34 | #include <vector> |
a553a5a3 | 35 | |
6289f91f AJ |
36 | #define EVENT_LOOP_TIMEOUT 1000 /* 1s timeout */ |
37 | ||
314782d4 FC |
38 | class AsyncEngine; |
39 | class TimeEngine; | |
40 | ||
6289f91f | 41 | /** An event loop. An event loop is the core inner loop of squid. |
a553a5a3 | 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. | |
6289f91f | 44 | \par |
a553a5a3 | 45 | * The event loop cannot be run once it is running until it has finished. |
46 | */ | |
a553a5a3 | 47 | class EventLoop |
48 | { | |
49 | ||
50 | public: | |
51 | EventLoop(); | |
6289f91f AJ |
52 | |
53 | /** register an async engine which will be given the opportunity to perform | |
8ff3fa2e | 54 | * in-main-thread tasks each event loop. |
55 | */ | |
56 | void registerEngine(AsyncEngine *engine); | |
6289f91f AJ |
57 | |
58 | /** start the event loop running. The loop will run until it is stopped by | |
26ac0430 | 59 | * calling stop(), or when the loop is completely idle - nothing |
8ff3fa2e | 60 | * dispatched in a loop, and all engines idle. |
61 | */ | |
a553a5a3 | 62 | void run(); |
6289f91f AJ |
63 | |
64 | /** run the loop once. This may not complete all events! It should therefor | |
a553a5a3 | 65 | * be used with care. |
66 | * TODO: signal in runOnce whether or not the loop is over - IDLE vs OK vs | |
67 | * TIMEOUT? | |
68 | */ | |
8ff3fa2e | 69 | bool runOnce(); |
6289f91f AJ |
70 | |
71 | /** set the primary async engine. The primary async engine recieves the | |
bef81ea5 | 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). | |
26ac0430 | 75 | * If no primary has been nominated, the last async engine added is |
bef81ea5 | 76 | * implicitly the default. |
77 | */ | |
78 | void setPrimaryEngine(AsyncEngine * engine); | |
6289f91f AJ |
79 | |
80 | /** set the time service. There can be only one time service set at any | |
26ac0430 | 81 | * time. The time service is invoked on each loop |
8ff3fa2e | 82 | */ |
83 | void setTimeService(TimeEngine *engine); | |
6289f91f AJ |
84 | |
85 | /** stop the event loop - it will finish the current loop and then return to the | |
a553a5a3 | 86 | * caller of run(). |
87 | */ | |
88 | void stop(); | |
89 | ||
8ff3fa2e | 90 | int errcount; |
91 | ||
0a720258 AR |
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 | ||
a553a5a3 | 96 | private: |
6289f91f | 97 | /** setup state variables prior to running */ |
a553a5a3 | 98 | void prepareToRun(); |
6289f91f AJ |
99 | |
100 | /** check an individual engine */ | |
bef81ea5 | 101 | void checkEngine(AsyncEngine * engine, bool const primary); |
6289f91f AJ |
102 | |
103 | /** dispatch calls and events scheduled during checkEngine() */ | |
1fd133b5 | 104 | bool dispatchCalls(); |
105 | ||
a553a5a3 | 106 | bool last_loop; |
c8ea3cc0 | 107 | typedef std::vector<AsyncEngine *> engine_vector; |
8ff3fa2e | 108 | engine_vector engines; |
109 | TimeEngine * timeService; | |
bef81ea5 | 110 | AsyncEngine * primaryEngine; |
6289f91f AJ |
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 */ | |
a553a5a3 | 114 | }; |
115 | ||
a553a5a3 | 116 | #endif /* SQUID_EVENTLOOP_H */ |