comparison src/os/win32/ngx_process_cycle.c @ 2627:c9da3e4dc706

ngx_process_tray()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 30 Mar 2009 14:46:33 +0000
parents 4d9ea73a627a
children d43d73277c5c
comparison
equal deleted inserted replaced
2626:b0cfe5f66e8d 2627:c9da3e4dc706
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 #include <nginx.h> 10 #include <nginx.h>
11 11
12 12
13 static ngx_thread_value_t __stdcall ngx_worker_thread_cycle(void *data); 13 static ngx_thread_value_t __stdcall ngx_worker_thread_cycle(void *data);
14 static void ngx_process_tray(ngx_cycle_t *cycle);
14 static long __stdcall ngx_window_procedure(HWND window, u_int message, 15 static long __stdcall ngx_window_procedure(HWND window, u_int message,
15 u_int wparam, long lparam); 16 u_int wparam, long lparam);
16 17
17 #if 0 18 #if 0
18 ngx_pid_t ngx_new_binary; 19 ngx_pid_t ngx_new_binary;
55 56
56 57
57 void 58 void
58 ngx_single_process_cycle(ngx_cycle_t *cycle) 59 ngx_single_process_cycle(ngx_cycle_t *cycle)
59 { 60 {
60 int rc;
61 ngx_int_t i; 61 ngx_int_t i;
62 ngx_err_t err; 62 ngx_err_t err;
63 ngx_tid_t tid; 63 ngx_tid_t tid;
64 MSG message;
65 HWND window;
66 HMENU menu;
67 HICON icon,tray;
68 WNDCLASS wc;
69 HINSTANCE instance;
70 ngx_core_conf_t *ccf; 64 ngx_core_conf_t *ccf;
71 65
72 ngx_init_temp_number(); 66 ngx_init_temp_number();
73 67
74 for (i = 0; ngx_modules[i]; i++) { 68 for (i = 0; ngx_modules[i]; i++) {
78 exit(2); 72 exit(2);
79 } 73 }
80 } 74 }
81 } 75 }
82 76
83
84 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); 77 ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
85 78
86 if (ngx_init_threads(ngx_threads_n, 79 if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle)
87 ccf->thread_stack_size, cycle) == NGX_ERROR) 80 != NGX_OK)
88 { 81 {
89 /* fatal */ 82 /* fatal */
90 exit(2); 83 exit(2);
91 } 84 }
92 85
96 ngx_thread_key_create_n " failed"); 89 ngx_thread_key_create_n " failed");
97 /* fatal */ 90 /* fatal */
98 exit(2); 91 exit(2);
99 } 92 }
100 93
94 if (ngx_create_thread(&tid, ngx_worker_thread_cycle, NULL, cycle->log)
95 != 0)
96 {
97 /* fatal */
98 exit(2);
99 }
100
101 ngx_process_tray(cycle);
102 }
103
104
105 static ngx_thread_value_t __stdcall
106 ngx_worker_thread_cycle(void *data)
107 {
108 ngx_cycle_t *cycle;
109
110 cycle = (ngx_cycle_t *) ngx_cycle;
111
112 while (!ngx_quit) {
113 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
114
115 ngx_process_events_and_timers(cycle);
116 }
117
118 return 0;
119 }
120
121
122 static void
123 ngx_process_tray(ngx_cycle_t *cycle)
124 {
125 int rc;
126 MSG message;
127 HWND window;
128 HMENU menu;
129 HICON icon, tray;
130 WNDCLASS wc;
131 HINSTANCE instance;
101 132
102 instance = GetModuleHandle(NULL); 133 instance = GetModuleHandle(NULL);
103 134
104 icon = LoadIcon(instance, "nginx"); 135 icon = LoadIcon(instance, "nginx");
105 if (icon == NULL) { 136 if (icon == NULL) {
150 "RegisterClass() failed"); 181 "RegisterClass() failed");
151 /* fatal */ 182 /* fatal */
152 exit(2); 183 exit(2);
153 } 184 }
154 185
155
156 window = CreateWindow("nginx", "nginx", WS_OVERLAPPEDWINDOW, 186 window = CreateWindow("nginx", "nginx", WS_OVERLAPPEDWINDOW,
157 CW_USEDEFAULT, CW_USEDEFAULT, 187 CW_USEDEFAULT, CW_USEDEFAULT,
158 CW_USEDEFAULT, CW_USEDEFAULT, 188 CW_USEDEFAULT, CW_USEDEFAULT,
159 NULL, NULL, instance, NULL); 189 NULL, NULL, instance, NULL);
160 190
173 "Shell_NotifyIcon(NIM_ADD) failed"); 203 "Shell_NotifyIcon(NIM_ADD) failed");
174 /* fatal */ 204 /* fatal */
175 exit(2); 205 exit(2);
176 } 206 }
177 207
178
179 if (ngx_create_thread(&tid, ngx_worker_thread_cycle, NULL, cycle->log) != 0)
180 {
181 /* fatal */
182 exit(2);
183 }
184
185
186 for ( ;; ) { 208 for ( ;; ) {
187 rc = GetMessage(&message, NULL, 0, 0); 209 rc = GetMessage(&message, NULL, 0, 0);
188 210
189 if (rc == -1) { 211 if (rc == -1) {
190 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, 212 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
200 DispatchMessage(&message); 222 DispatchMessage(&message);
201 } 223 }
202 } 224 }
203 225
204 226
205 static ngx_thread_value_t __stdcall
206 ngx_worker_thread_cycle(void *data)
207 {
208 ngx_cycle_t *cycle;
209
210 cycle = (ngx_cycle_t *) ngx_cycle;
211
212 while (!ngx_quit) {
213 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle");
214
215 ngx_process_events_and_timers(cycle);
216 }
217
218 return 0;
219 }
220
221
222 static long __stdcall 227 static long __stdcall
223 ngx_window_procedure(HWND window, u_int message, u_int wparam, long lparam) 228 ngx_window_procedure(HWND window, u_int message, u_int wparam, long lparam)
224 { 229 {
225 POINT mouse; 230 POINT mouse;
226 231
239 "SetForegroundWindow() failed"); 244 "SetForegroundWindow() failed");
240 return 0; 245 return 0;
241 } 246 }
242 247
243 if (TrackPopupMenu(ngx_menu, TPM_RIGHTBUTTON, 248 if (TrackPopupMenu(ngx_menu, TPM_RIGHTBUTTON,
244 mouse.x, mouse.y, 0, window, NULL) == 0) 249 mouse.x, mouse.y, 0, window, NULL)
250 == 0)
245 { 251 {
246 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno, 252 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_errno,
247 "TrackPopupMenu() failed"); 253 "TrackPopupMenu() failed");
248 return 0; 254 return 0;
249 } 255 }
252 return 0; 258 return 0;
253 259
254 case WM_COMMAND: 260 case WM_COMMAND:
255 if (wparam == NGX_WM_ABOUT) { 261 if (wparam == NGX_WM_ABOUT) {
256 ngx_message_box("nginx", MB_OK, 0, 262 ngx_message_box("nginx", MB_OK, 0,
257 NGINX_VER CRLF "(C) 2002-2005 Igor Sysoev"); 263 NGINX_VER CRLF "(C) 2002-2009 Igor Sysoev");
258 return 0; 264 return 0;
259 } 265 }
260 266
261 if (wparam == NGX_WM_EXIT) { 267 if (wparam == NGX_WM_EXIT) {
262 if (ngx_system_tray_icon(window, NIM_DELETE, NULL, NULL) 268 if (ngx_system_tray_icon(window, NIM_DELETE, NULL, NULL)