Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / APG / Reactor / Timers.cpp
blobf6638bcf6985ffa853a797c5674543a7c3038f4c
1 #include "ace/config-all.h"
2 #include "ace/OS_main.h"
4 #if !defined (ACE_LACKS_FORK)
6 #include "ace/streams.h"
7 #include "ace/OS_NS_unistd.h"
8 #include "ace/OS_NS_time.h"
9 #include "ace/OS_NS_signal.h"
11 typedef void (*timerTask_t)();
13 // Listing 1 code/ch07
14 pid_t timerTask (int initialDelay,
15 int interval,
16 timerTask_t task)
18 if (initialDelay < 1 && interval < 1)
19 return -1;
21 pid_t pid = ACE_OS::fork ();
23 if (pid < 0)
24 return -1;
26 if (pid > 0)
27 return pid;
29 if (initialDelay > 0)
30 ACE_OS::sleep (initialDelay);
32 if (interval < 1)
33 return 0;
35 while (1)
37 (*task) ();
38 ACE_OS::sleep (interval);
41 ACE_NOTREACHED (return 0);
43 // Listing 1
45 // Listing 2 code/ch07
46 void foo ()
48 time_t now = ACE_OS::time (0);
49 cerr << "The time is " << ACE_OS::ctime (&now) << endl;
51 // Listing 2
53 void programMainLoop ()
55 ACE_OS::sleep (30);
58 // Listing 3 code/ch07
59 int ACE_TMAIN (int, ACE_TCHAR *[])
61 pid_t timerId = timerTask (3, 5, foo);
62 programMainLoop ();
63 ACE_OS::kill (timerId, SIGINT);
64 return 0;
66 // Listing 3
68 #else
69 #include "ace/OS_NS_stdio.h"
71 int ACE_TMAIN (int, ACE_TCHAR *[])
73 //FUZZ: disable check_for_lack_ACE_OS
74 ACE_OS::puts ("This very unportable example requires fork().\n");
75 //FUZZ: enable check_for_lack_ACE_OS
77 return 0;
80 #endif /* ACE_LACKS_FORK */