2 //=============================================================================
6 * This is the implementation of the NT service. It beeps every 2
7 * seconds until the service is stopped.
9 * @author Gonzalo Diethelm <gonzo@cs.wustl.edu> and Steve Huston <shuston@riverace.com>
11 //=============================================================================
14 #include "ace/Reactor.h"
17 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_SERVICES)
21 // Remember the Reactor instance.
22 reactor (ACE_Reactor::instance ());
27 if (ACE_Reactor::instance ()->cancel_timer(this) == -1)
29 "Service::~Service failed to cancel_timer.\n"));
32 // This method is called when the service gets a control request. It
33 // handles requests for stop and shutdown by calling terminate ().
34 // All others get handled by calling up to inherited::handle_control.
37 Service::handle_control (DWORD control_code
)
39 if (control_code
== SERVICE_CONTROL_SHUTDOWN
40 || control_code
== SERVICE_CONTROL_STOP
)
42 report_status (SERVICE_STOP_PENDING
);
45 ACE_TEXT ("Service control stop requested\n")));
47 reactor ()->notify (this,
48 ACE_Event_Handler::EXCEPT_MASK
);
51 inherited::handle_control (control_code
);
54 // This is just here to be the target of the notify from above... it
55 // doesn't do anything except aid on popping the reactor off its wait
56 // and causing a drop out of handle_events.
59 Service::handle_exception (ACE_HANDLE
)
64 // Beep every two seconds. This is what this NT service does...
67 Service::handle_timeout (const ACE_Time_Value
&tv
,
72 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%T (%t): Beep...\n")));
76 // This is the main processing function for the Service. It sets up
77 // the initial configuration and runs the event loop until a shutdown
78 // request is received.
84 ACE_TEXT ("Service::svc\n")));
86 // As an NT service, we come in here in a different thread than the
87 // one which created the reactor. So in order to do anything, we
88 // need to own the reactor. If we are not a service, report_status
90 if (report_status (SERVICE_RUNNING
) == 0)
91 reactor ()->owner (ACE_Thread::self ());
95 // Schedule a timer every two seconds.
96 ACE_Time_Value
tv (2, 0);
97 ACE_Reactor::instance ()->schedule_timer (this, 0, tv
, tv
);
100 reactor ()->handle_events ();
102 // Cleanly terminate connections, terminate threads.
103 ACE_DEBUG ((LM_DEBUG
,
104 ACE_TEXT ("Shutting down\n")));
105 reactor ()->cancel_timer (this);
109 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_SERVICES */