Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXDispatcher.h
1 /********************************************************************************
2 * *
3 * C a l l b a c k D i s p a t c h e r *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2006,2024 by Jeroen van der Zijp. All Rights Reserved. *
7 ********************************************************************************/
8 #ifndef FXDISPATCHER_H
9 #define FXDISPATCHER_H
10 
11 #ifndef FXREACTOR_H
12 #include "FXReactor.h"
13 #endif
14 
15 namespace FX {
16 
17 
22 class FXAPI FXDispatcher : public FXReactor {
23 private:
24  struct Handle;
25  struct Signal;
26  struct Idle;
27  struct Timer;
28 private:
29  FXHash handles; // Handle callbacks
30  Signal **signals; // Signal callbacks
31  Timer *timers; // Timeout callbacks
32  Idle *idles; // Idle callbacks
33  Timer *timerrecs; // Timer records
34  Idle *idlerecs; // Idle records
35 private:
36  FXDispatcher(const FXDispatcher&);
37  FXDispatcher &operator=(const FXDispatcher&);
38 public:
39 
42 
45 
48 
51 
52 public:
53 
55  FXDispatcher();
56 
58  virtual FXbool init();
59 
61  virtual FXbool addHandle(HandleCallback cb,FXInputHandle hnd,FXuint mode=InputRead,void* ptr=nullptr);
62 
64  virtual FXbool addHandle(FXInputHandle hnd,FXuint mode=InputRead);
65 
67  virtual FXbool remHandle(FXInputHandle hnd);
68 
70  virtual FXbool hasHandle(FXInputHandle hnd) const;
71 
74  virtual FXbool dispatchHandle(FXInputHandle hnd,FXuint mode,FXuint flags);
75 
77  virtual FXbool addSignal(SignalCallback cb,FXint sig,void* ptr=nullptr,FXbool async=false);
78 
80  virtual FXbool addSignal(FXint sig,FXbool async=false);
81 
83  virtual FXbool remSignal(FXint sig);
84 
87  virtual FXbool dispatchSignal(FXint sig);
88 
92  virtual void* addTimeout(TimeoutCallback cb,FXTime due,void* ptr=nullptr);
93 
97  virtual void* addInterval(TimeoutCallback cb,FXTime interval,void* ptr=nullptr);
98 
101  virtual void* remTimeout(TimeoutCallback cb);
102 
105  virtual FXTime getTimeout(TimeoutCallback cb) const;
106 
108  virtual FXbool hasTimeout(TimeoutCallback cb) const;
109 
112  virtual FXTime nextTimeout();
113 
116  virtual FXbool dispatchTimeout(FXTime due);
117 
121  virtual void* addIdle(IdleCallback cb,void* ptr=nullptr);
122 
125  virtual void* remIdle(IdleCallback cb);
126 
128  virtual FXbool hasIdle(IdleCallback cb) const;
129 
132  virtual FXbool dispatchIdle();
133 
135  virtual FXbool exit();
136 
138  virtual ~FXDispatcher();
139  };
140 
141 
142 }
143 
144 #endif
FXCallback< FXbool(FXDispatcher *, FXint, void *)> SignalCallback
Signal callback when signal has been fired.
Definition: FXDispatcher.h:44
FXCallback< FXbool(FXDispatcher *, void *)> IdleCallback
Idle callback when dispatcher is about to block.
Definition: FXDispatcher.h:50
FXCallback< FXbool(FXDispatcher *, FXInputHandle, FXuint, void *)> HandleCallback
I/O Handle callback when a handle is raised.
Definition: FXDispatcher.h:41
Definition: FXCallback.h:30
A hash table for mapping pointers to pointers.
Definition: FXHash.h:33
A FXDispatcher watches a number of devices and signals for activity and dispatches to the proper func...
Definition: FXDispatcher.h:22
Definition: FX4Splitter.h:28
FXReactor implements the reactor pattern.
Definition: FXReactor.h:58
FXCallback< FXbool(FXDispatcher *, FXTime, void *)> TimeoutCallback
Timer callback when timer expired.
Definition: FXDispatcher.h:47

Copyright © 1997-2022 Jeroen van der Zijp