Async  1.5.0
AsyncCppApplication.h
Go to the documentation of this file.
1 
31 #ifndef ASYNC_CPP_APPLICATION_INCLUDED
32 #define ASYNC_CPP_APPLICATION_INCLUDED
33 
34 
35 /****************************************************************************
36  *
37  * System Includes
38  *
39  ****************************************************************************/
40 
41 #include <sys/types.h>
42 #include <sys/select.h>
43 #include <sys/time.h>
44 #include <signal.h>
45 #include <sigc++/sigc++.h>
46 
47 #include <map>
48 #include <utility>
49 
50 
51 /****************************************************************************
52  *
53  * Project Includes
54  *
55  ****************************************************************************/
56 
57 #include <AsyncApplication.h>
58 
59 
60 /****************************************************************************
61  *
62  * Local Includes
63  *
64  ****************************************************************************/
65 
66 
67 
68 /****************************************************************************
69  *
70  * Forward declarations
71  *
72  ****************************************************************************/
73 
74 
75 
76 /****************************************************************************
77  *
78  * Namespace
79  *
80  ****************************************************************************/
81 
82 namespace Async
83 {
84 
85 /****************************************************************************
86  *
87  * Defines & typedefs
88  *
89  ****************************************************************************/
90 
91 /*
92  *----------------------------------------------------------------------------
93  * Macro:
94  * Purpose:
95  * Input:
96  * Output:
97  * Author:
98  * Created:
99  * Remarks:
100  * Bugs:
101  *----------------------------------------------------------------------------
102  */
103 
104 
105 /*
106  *----------------------------------------------------------------------------
107  * Type:
108  * Purpose:
109  * Members:
110  * Input:
111  * Output:
112  * Author:
113  * Created:
114  * Remarks:
115  *----------------------------------------------------------------------------
116  */
117 
118 
119 /****************************************************************************
120  *
121  * Exported Global Variables
122  *
123  ****************************************************************************/
124 
125 
126 
127 /****************************************************************************
128  *
129  * Class definitions
130  *
131  ****************************************************************************/
132 
137 {
138  public:
142  CppApplication(void);
143 
147  ~CppApplication(void);
148 
153  void catchUnixSignal(int signum);
154 
159  void uncatchUnixSignal(int signum);
160 
168  void exec(void);
169 
175  void quit(void);
176 
185  sigc::signal<void, int> unixSignalCaught;
186 
187  protected:
188 
189  private:
190  struct lttimespec
191  {
192  bool operator()(const struct timespec& t1, const struct timespec& t2) const
193  {
194  return ((t1.tv_sec == t2.tv_sec)
195  ? (t1.tv_nsec < t2.tv_nsec)
196  : (t1.tv_sec < t2.tv_sec));
197  }
198  };
199  typedef std::map<int, FdWatch*> WatchMap;
200  typedef std::multimap<struct timespec, Timer *, lttimespec> TimerMap;
201  typedef std::map<int, struct sigaction> UnixSignalMap;
202 
203  static int sighandler_pipe[2];
204 
205  bool do_quit;
206  int max_desc;
207  fd_set rd_set;
208  fd_set wr_set;
209  WatchMap rd_watch_map;
210  WatchMap wr_watch_map;
211  TimerMap timer_map;
212  UnixSignalMap unix_signals;
213  int unix_signal_recv;
214  size_t unix_signal_recv_cnt;
215 
216  static void unixSignalHandler(int signum);
217 
218  void addFdWatch(FdWatch *fd_watch);
219  void delFdWatch(FdWatch *fd_watch);
220  void addTimer(Timer *timer);
221  void addTimerP(Timer *timer, const struct timespec& current);
222  void delTimer(Timer *timer);
223  DnsLookupWorker *newDnsLookupWorker(const std::string& label);
224  void handleUnixSignal(void);
225 
226 }; /* class CppApplication */
227 
228 
229 } /* namespace */
230 
231 #endif /* ASYNC_CPP_APPLICATION_INCLUDED */
232 
233 
234 
235 /*
236  * This file has not been truncated
237  */
238 
void catchUnixSignal(int signum)
Catch the specified UNIX signal.
void uncatchUnixSignal(int signum)
Uncatch the specified UNIX signal.
The base class for asynchronous applications.
void quit(void)
Exit the application main loop.
The core class for writing asyncronous applications.
sigc::signal< void, int > unixSignalCaught
A signal that is emitted when a monitored UNIX signal is caught.
A class that produces timer events.
Definition: AsyncTimer.h:116
A class for watching file descriptors.
Definition: AsyncFdWatch.h:119
void exec(void)
Execute the application main loop.
Namespace for the asynchronous programming classes.
~CppApplication(void)
Destructor.
An application class for writing non GUI applications.
CppApplication(void)
Constructor.