Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / examples / C++NPv2 / Server_Shutdown.cpp
blobeb75e3d6b1a32b3a5a189f00466f227f32d3f9c6
1 /*
2 ** Copyright 2002 Addison Wesley. All Rights Reserved.
3 */
5 #include "ace/Event_Handler.h"
6 #include "ace/Reactor.h"
7 #include "ace/Service_Object.h"
8 #include "ace/Thread_Manager.h"
9 #include "ace/OS_NS_string.h"
11 // FUZZ: disable check_for_streams_include
12 #include "ace/streams.h"
14 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
15 # include <stdio.h>
16 #else
17 # include <string>
18 #endif
20 #include "SLDEX_export.h"
23 class Quit_Handler : public ACE_Event_Handler {
24 public:
25 Quit_Handler (ACE_Reactor *r) : ACE_Event_Handler (r) {}
27 virtual int handle_exception (ACE_HANDLE) {
28 reactor ()->end_reactor_event_loop ();
29 return -1; // Trigger call to handle_close() method.
32 virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask)
33 { delete this; return 0; }
35 protected:
36 // Protected destructor ensures dynamic allocation.
37 virtual ~Quit_Handler () {}
41 static ACE_THR_FUNC_RETURN controller (void *arg) {
42 ACE_Reactor *reactor = static_cast<ACE_Reactor *> (arg);
44 Quit_Handler *quit_handler = 0;
45 ACE_NEW_RETURN (quit_handler, Quit_Handler (reactor), 0);
47 #if defined (ACE_WIN32) && defined (ACE_USES_OLD_IOSTREAMS)
48 for (;;) {
49 char user_input[80];
50 ACE_OS::fgets (user_input, sizeof (user_input), stdin);
51 if (ACE_OS::strcmp (user_input, "quit") == 0) {
52 reactor->notify (quit_handler);
53 break;
56 #else
57 for (;;) {
58 std::string user_input;
59 std::getline (cin, user_input, '\n');
60 if (user_input == "quit") {
61 reactor->notify (quit_handler);
62 break;
65 #endif
67 return 0;
71 class Server_Shutdown : public ACE_Service_Object {
72 public:
73 virtual int init (int, ACE_TCHAR *[]) {
74 reactor_ = ACE_Reactor::instance ();
75 return ACE_Thread_Manager::instance ()->spawn
76 (controller, reactor_, THR_DETACHED);
79 virtual int fini () {
80 Quit_Handler *quit_handler = 0;
81 ACE_NEW_RETURN (quit_handler,
82 Quit_Handler (reactor_), -1);
83 return reactor_->notify (quit_handler);
86 private:
87 ACE_Reactor *reactor_;
90 ACE_FACTORY_DEFINE (SLDEX, Server_Shutdown)