Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / C++NPv2 / Select_Reactor_Logging_Server.cpp
blob366562ef16744cf82e636e7dbc546917cf70f141
1 /*
2 ** Copyright 2002 Addison Wesley. All Rights Reserved.
3 */
5 // FUZZ: disable check_for_streams_include
6 #include "ace/streams.h"
8 #include "ace/Reactor.h"
9 #include "ace/Select_Reactor.h"
10 #include "ace/Thread_Manager.h"
12 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
13 # include <stdio.h>
14 #else
15 # include <string>
16 #endif
18 #include "Reactor_Logging_Server_T.h"
19 #include "Logging_Acceptor_Ex.h"
21 typedef Reactor_Logging_Server<Logging_Acceptor_Ex>
22 Server_Logging_Daemon;
25 class Quit_Handler : public ACE_Event_Handler {
26 public:
27 Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {}
29 virtual int handle_exception (ACE_HANDLE) {
30 reactor ()->end_reactor_event_loop ();
31 return -1; // Trigger call to handle_close() method.
34 virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)
35 { delete this; return 0; }
37 protected:
38 // Protected destructor ensures dynamic allocation.
39 virtual ~Quit_Handler () {}
43 static ACE_THR_FUNC_RETURN event_loop (void *arg) {
44 ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);
46 reactor->owner (ACE_OS::thr_self ());
47 reactor->run_reactor_event_loop ();
48 return 0;
52 static ACE_THR_FUNC_RETURN controller (void *arg) {
53 ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);
55 Quit_Handler *quit_handler = 0;
56 ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0);
58 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
59 for (;;) {
60 char user_input[80];
61 ACE_OS::fgets (user_input, sizeof (user_input), stdin);
62 if (ACE_OS::strcmp (user_input, "quit") == 0) {
63 reactor->notify (quit_handler);
64 break;
67 #else
68 for (;;) {
69 std::string user_input;
70 std::getline (cin, user_input, '\n');
71 if (user_input == "quit") {
72 reactor->notify (quit_handler);
73 break;
76 #endif
78 return 0;
82 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
84 ACE_Select_Reactor select_reactor;
85 ACE_Reactor reactor (&select_reactor);
87 Server_Logging_Daemon *server;
88 // Ignore argv[0]...
89 --argc; ++argv;
90 ACE_NEW_RETURN (server,
91 Server_Logging_Daemon (argc, argv, &reactor),
92 1);
93 ACE_Thread_Manager::instance ()->spawn (event_loop, &reactor);
94 ACE_Thread_Manager::instance ()->spawn (controller, &reactor);
95 return ACE_Thread_Manager::instance ()->wait ();