Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Signals / SigHandler.cpp
blob9f171ed2daaf259392306e92eab8d7c40b85bac7
1 #include "ace/OS_NS_unistd.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/Signal.h"
4 #include "ace/Sig_Handler.h"
6 // Listing 1 code/ch11
7 class MySignalHandler : public ACE_Event_Handler
9 public:
10 MySignalHandler (int signum) : signum_(signum)
11 { }
13 virtual ~MySignalHandler()
14 { }
16 virtual int handle_signal (int signum, siginfo_t * = 0, ucontext_t * = 0)
18 ACE_TRACE ("MySignalHandler::handle_signal");
20 // Make sure the right handler was called back.
21 ACE_ASSERT (signum == this->signum_);
23 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%S occurred\n"), signum));
24 return 0;
27 private:
28 int signum_;
30 // Listing 1
31 // Listing 2 code/ch11
32 int ACE_TMAIN (int, ACE_TCHAR *[])
34 MySignalHandler h1 (SIGUSR1), h2 (SIGUSR2);
35 ACE_Sig_Handler handler;
36 handler.register_handler (SIGUSR1, &h1);
37 handler.register_handler (SIGUSR2, &h2);
39 ACE_OS::kill (ACE_OS::getpid (), SIGUSR1);
40 ACE_OS::kill (ACE_OS::getpid (), SIGUSR2);
42 int time = 10;
43 while ((time = ACE_OS::sleep (time)) == -1)
45 if (errno == EINTR)
46 continue;
47 else
49 ACE_ERROR_RETURN ((LM_ERROR,
50 ACE_TEXT ("%p\n"),
51 ACE_TEXT ("sleep")), -1);
54 return 0;
56 // Listing 2