~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/event.h

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2006-11-11 10:32:06 UTC
  • Revision ID: james.westby@ubuntu.com-20061111103206-f3p0r9g0vq44rp3r
Tags: upstream-3.0.PRE5
ImportĀ upstreamĀ versionĀ 3.0.PRE5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/*
 
3
 * $Id: event.h,v 1.3 2006/09/02 12:20:53 serassio Exp $
 
4
 *
 
5
 *
 
6
 * SQUID Web Proxy Cache          http://www.squid-cache.org/
 
7
 * ----------------------------------------------------------
 
8
 *
 
9
 *  Squid is the result of efforts by numerous individuals from
 
10
 *  the Internet community; see the CONTRIBUTORS file for full
 
11
 *  details.   Many organizations have provided support for Squid's
 
12
 *  development; see the SPONSORS file for full details.  Squid is
 
13
 *  Copyrighted (C) 2001 by the Regents of the University of
 
14
 *  California; see the COPYRIGHT file for full details.  Squid
 
15
 *  incorporates software developed and/or copyrighted by other
 
16
 *  sources; see the CREDITS file for full details.
 
17
 *
 
18
 *  This program is free software; you can redistribute it and/or modify
 
19
 *  it under the terms of the GNU General Public License as published by
 
20
 *  the Free Software Foundation; either version 2 of the License, or
 
21
 *  (at your option) any later version.
 
22
 *  
 
23
 *  This program is distributed in the hope that it will be useful,
 
24
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
25
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
26
 *  GNU General Public License for more details.
 
27
 *  
 
28
 *  You should have received a copy of the GNU General Public License
 
29
 *  along with this program; if not, write to the Free Software
 
30
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 
31
 *
 
32
 */
 
33
 
 
34
#ifndef SQUID_EVENT_H
 
35
#define SQUID_EVENT_H
 
36
 
 
37
#include "squid.h"
 
38
#include "Array.h"
 
39
#include "AsyncEngine.h"
 
40
#include "CompletionDispatcher.h"
 
41
 
 
42
/* forward decls */
 
43
 
 
44
class StoreEntry;
 
45
 
 
46
/* event scheduling facilities - run a callback after a given time period. */
 
47
 
 
48
typedef void EVH(void *);
 
49
 
 
50
extern void eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata=true);
 
51
SQUIDCEXTERN void eventAddIsh(const char *name, EVH * func, void *arg, double delta_ish, int);
 
52
SQUIDCEXTERN void eventDelete(EVH * func, void *arg);
 
53
SQUIDCEXTERN void eventInit(CacheManager &);
 
54
SQUIDCEXTERN void eventFreeMemory(void);
 
55
SQUIDCEXTERN int eventFind(EVH *, void *);
 
56
 
 
57
class ev_entry
 
58
{
 
59
 
 
60
public:
 
61
    ev_entry(char const * name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
 
62
    MEMPROXY_CLASS(ev_entry);
 
63
    const char *name;
 
64
    EVH *func;
 
65
    void *arg;
 
66
    double when;
 
67
 
 
68
    int weight;
 
69
    bool cbdata;
 
70
 
 
71
    ev_entry *next;
 
72
};
 
73
 
 
74
MEMPROXY_CLASS_INLINE(ev_entry);
 
75
 
 
76
class EventDispatcher : public CompletionDispatcher
 
77
{
 
78
 
 
79
public:
 
80
    EventDispatcher();
 
81
    /* add an event to dequeue when dispatch is called */
 
82
 
 
83
    void add
 
84
        (ev_entry *);
 
85
 
 
86
    /* add an event to be dispatched in the future */
 
87
    void add
 
88
        (const char *name, EVH * func, void *arg, double when, int, bool cbdata=true);
 
89
 
 
90
    bool dispatch();
 
91
 
 
92
    static EventDispatcher *GetInstance();
 
93
 
 
94
private:
 
95
    Vector<ev_entry *> queue;
 
96
 
 
97
    static EventDispatcher _instance;
 
98
};
 
99
 
 
100
class EventScheduler : public AsyncEngine
 
101
{
 
102
 
 
103
public:
 
104
    /* Create an event scheduler that will hand its ready to run callbacks to
 
105
     * an EventDispatcher 
 
106
     *
 
107
     * TODO: add should include a dispatcher to use perhaps? then it would be
 
108
     * more decoupled..
 
109
     */
 
110
    EventScheduler(EventDispatcher *);
 
111
    ~EventScheduler();
 
112
    /* cancel a scheduled but not dispatched event */
 
113
    void cancel(EVH * func, void * arg);
 
114
    /* clean up the used memory in the scheduler */
 
115
    void clean();
 
116
    /* how long until the next event ? */
 
117
    int checkDelay();
 
118
    /* cache manager output for the event queue */
 
119
    void dump(StoreEntry *);
 
120
    /* find a scheduled event */
 
121
    bool find(EVH * func, void * arg);
 
122
    /* schedule a callback function to run in when seconds */
 
123
    void schedule(const char *name, EVH * func, void *arg, double when, int weight, bool cbdata=true);
 
124
    int checkEvents(int timeout);
 
125
    static EventScheduler *GetInstance();
 
126
 
 
127
private:
 
128
    static EventScheduler _instance;
 
129
    EventDispatcher * dispatcher;
 
130
    ev_entry * tasks;
 
131
};
 
132
 
 
133
#endif /* SQUID_EVENT_H */