Merge pull request #1710 from likema/cfg-assign-not-null-str
[ACE_TAO.git] / ACE / apps / JAWS3 / contrib / john_at_lyris_dot_com / jaws3-cntlC.code
blobdf2a69d2bc04d11489fcc08d233082689d8d40b1
2 bool PlatformSpecificInitialize() {
4      LYRIS_PROFILE("PlatformSpecificInitialize");
6      bool retval;
7      retval = SetConsoleCtrlHandler(handler_routine, TRUE);
8      if (retval != TRUE) {
9           trace("Note: SetConsoleCtrlHandler() did not succeed.");
10      }
12      retval = SetConsoleTitle(APPLICATION_NAME.c_str());
13      if (retval != TRUE) {
14           trace("Note: setConsoleTitle() did not succeed.");
15      }
17      return lyris_success;
20 BOOL WINAPI handler_routine(DWORD signal) {
22      LYRIS_PROFILE("handler_routine");
24      static unsigned char handles_to_use = 3;
25      static bool handled_already = false;
26      if ((signal == CTRL_CLOSE_EVENT) || (signal == CTRL_SHUTDOWN_EVENT)) {
27           // if we receive a Windows signal to shutdown, we should exit
28           // immediately, and cleanly
29           if (handled_already == false) {
30                handled_already = true;
31                //lyris_Thread::ExitApplicationNow();
32                DisplayMessage("Shutting down as requested");
33                // create shutdown thread so that signal handler can return
34                // immediately
35                lyris_Thread aShutDown(ShutDownNow, NULL, "Shut Down Thread");
37                return TRUE;
38           }
39           else {
40                return FALSE;
41           }
42      }
43      else if (signal == CTRL_C_EVENT) {
44           // if we receive a Windows signal to shutdown, we should exit
45           // immediately, and cleanly
46           if (handles_to_use == 3) {
47                handles_to_use--;
48                //lyris_Thread::ExitApplicationNow();
49                DisplayMessage("Shutting down as requested");
50                // create shutdown thread so that signal handler can return
51                // immediately
52                lyris_Thread aShutDown(ShutDownNow, NULL, "Shut Down Thread");
54                return TRUE;
55           }
56           else if (handles_to_use > 0) {
57                DisplayMessage("Currently shutting down: press Ctrl-C " +
58                               ULong2String(handles_to_use) +
59                               " more times to shut down immediately.");
60                handles_to_use--;
61                return TRUE;
62           }
63           else {
64                return FALSE;
65           }
66      }
67      else if (signal == CTRL_BREAK_EVENT) {
68           if (APPLICATION_NAME == "Lyris") {
69                if (ShouldDisplayDebugMessages() == 0) {
70                     SetShouldDisplayDebugMessages(1);
71                }
72                else {
73                     SetShouldDisplayDebugMessages(0);
74                }
75                DisplayMessage("Debug mode is now: " +
76                               Bool2String(ShouldDisplayDebugMessages()));
77           }
78           else if (APPLICATION_NAME == "MailShield") {
79                specific::setReloadConfig(lyris_yes);
80           }
81           else {
82                lyr_fatal;
83           }
84           return TRUE;
85      }
86      else {
87           lyr_notify("Unknown Windows signal passed to handler: " +
88                      ULong2String(signal));
89      };
90      return FALSE;