-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / dtmail / Notifier.hh
1 /*
2  *+SNOTICE
3  *
4  *      $XConsortium: Notifier.hh /main/4 1996/04/21 19:42:50 drk $
5  *
6  *      RESTRICTED CONFIDENTIAL INFORMATION:
7  *      
8  *      The information in this document is subject to special
9  *      restrictions in a confidential disclosure agreement between
10  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
11  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
12  *      Sun's specific written approval.  This document and all copies
13  *      and derivative works thereof must be returned or destroyed at
14  *      Sun's request.
15  *
16  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
17  *
18  *+ENOTICE
19  */
20
21 #ifndef NOTIFIER_HH
22 #define NOTIFIER_HH
23
24 #include <X11/Intrinsic.h>
25
26 #include <DtMail/DtMailTypes.h>
27 #include <DtMail/DtVirtArray.hh>
28 #include <DtMail/HashTable.hh>
29
30 class NotifyEvent {
31   public:
32     NotifyEvent(void);
33     virtual ~NotifyEvent(void);
34
35     virtual void eventTriggered(void); // PURE VIRTUAL
36 };
37
38 class Notifier {
39   public:
40     Notifier(XtAppContext);
41     virtual ~Notifier(void);
42
43     void notify(NotifyEvent & event,
44                 DtMailBoolean fast_path = DTM_FALSE);
45
46     typedef void * IntervalId;
47     IntervalId addInterval(int interval_ms,
48                            DtMailBoolean multi_shot,
49                            NotifyEvent & event);
50     void removeInterval(IntervalId id);
51
52     void signalEvent(int sig, NotifyEvent & event);
53     void removeSignal(int sig);
54
55   private:
56     int                         _event_fds[2];
57     DtVirtArray<NotifyEvent *>  _events;
58
59     struct TimerSearch;
60     friend TimerSearch;
61
62     class EventKey : public ObjectKey {
63       public:
64             EventKey(void * key);
65             ~EventKey(void);
66             
67             virtual int operator==(ObjectKey &);
68             virtual int operator!=(ObjectKey &);
69             virtual int operator<(ObjectKey &);
70             virtual int operator>(ObjectKey &);
71             virtual int operator<=(ObjectKey &);
72             virtual int operator>=(ObjectKey &);
73             
74             virtual HashVal hashValue(void);
75
76             void * keyValue(void) { return _key; }
77           private:
78             void *      _key;
79         };
80
81     struct TimerEvent {
82         NotifyEvent     *event;
83         DtMailBoolean   multi_shot;
84         int             interval;
85         XtIntervalId    id;
86     };
87
88     HashTable<TimerEvent *>     _timer_events;
89
90     XtAppContext                _context;
91     XtInputId                   _id;
92
93     static void eventProc(XtPointer client_data, int * fd, XtInputId *);
94     static void timerProc(XtPointer, XtIntervalId *);
95
96     static int deleteTimerEvent(ObjectKey &, TimerEvent *, void *);
97
98     struct TimerSearch {
99         TimerEvent *    srch_event;
100         EventKey *      key;
101     };
102     static int searchTimer(ObjectKey &, TimerEvent *, void *);
103 };
104
105 #endif