summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>2003-01-19 17:47:56 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>2003-01-19 17:47:56 +0000
commit440924f1e326e1069d15beb10167143de944c3fa (patch)
treec3b9679a69e99b04d60f66e1c7ae852c690290e6
parentd3269e48beba8e3434f49bd0e379e6ba26fe048b (diff)
downloadATCD-440924f1e326e1069d15beb10167143de944c3fa.tar.gz
ChangeLogTag:Sun Jan 19 11:40:10 2003 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
-rw-r--r--ChangeLog4
-rw-r--r--ChangeLogs/ChangeLog-03a4
-rw-r--r--THANKS1
-rw-r--r--ace/NT_Service.cpp68
-rw-r--r--ace/NT_Service.h8
5 files changed, 74 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 8cea92419f8..0ea408bbf14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
Sun Jan 19 11:40:10 2003 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+ * ace/NT_Service.{h,cpp}: Enhanced the wait_For_service_state() so
+ that it actually uses the wait_time parameter. Thanks to Theo
+ Landman <tlandman@justcroft.com> for contributing this.
+
* ace/Process_Manager.cpp (spawn): Cleanup dynamically allocated
memory if the spawn() fails. Thanks to Kobi Cohen-Arazi
<kobi@mivzak.com> for this fix.
diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a
index 8cea92419f8..0ea408bbf14 100644
--- a/ChangeLogs/ChangeLog-03a
+++ b/ChangeLogs/ChangeLog-03a
@@ -1,5 +1,9 @@
Sun Jan 19 11:40:10 2003 Douglas C. Schmidt <schmidt@macarena.cs.wustl.edu>
+ * ace/NT_Service.{h,cpp}: Enhanced the wait_For_service_state() so
+ that it actually uses the wait_time parameter. Thanks to Theo
+ Landman <tlandman@justcroft.com> for contributing this.
+
* ace/Process_Manager.cpp (spawn): Cleanup dynamically allocated
memory if the spawn() fails. Thanks to Kobi Cohen-Arazi
<kobi@mivzak.com> for this fix.
diff --git a/THANKS b/THANKS
index ef8f0707d85..eba40e11935 100644
--- a/THANKS
+++ b/THANKS
@@ -1649,6 +1649,7 @@ Danile White <ygor@comcast.net>
Andrew Marlow <apm35@student.open.ac.uk>
Michael F"olsl <michael.foelsl@gmx.net>
Vincent Chau <vincent.chau@fr.thalesgroup.com>
+Theo Landman <tlandman@justcroft.com>
I would particularly like to thank Paul Stephenson, who worked with me
at Ericsson in the early 1990's. Paul devised the recursive Makefile
diff --git a/ace/NT_Service.cpp b/ace/NT_Service.cpp
index 7014d3f0502..20b490694cc 100644
--- a/ace/NT_Service.cpp
+++ b/ace/NT_Service.cpp
@@ -543,12 +543,68 @@ void
ACE_NT_Service::wait_for_service_state (DWORD desired_state,
ACE_Time_Value *wait_time)
{
- // Doing the right thing with these needs to be added.
- ACE_UNUSED_ARG (desired_state);
- ACE_UNUSED_ARG (wait_time);
-
- QueryServiceStatus (this->svc_sc_handle_,
- &this->svc_status_);
+ DWORD last_state, last_check_point;
+ int first_time = 1;
+ int service_ok;
+
+ ACE_Time_Value time_out = ACE_OS::gettimeofday ();
+ if (wait_time != 0)
+ time_out += *wait_time;
+
+ // Poll until the service reaches the desired state.
+ for (;;)
+ {
+ service_ok = 0 != QueryServiceStatus (this->svc_sc_handle_,
+ &this->svc_status_);
+
+ // If we cannot query the service, we are done.
+ if (!service_ok)
+ break;
+
+ // If the service has the desired state, we are done.
+ if (desired_state == this->svc_status_.dwCurrentState)
+ break;
+
+ // If we time-out, we are done
+ if (wait_time != 0 && ACE_OS::gettimeofday () > time_out )
+ {
+ errno = ETIME;
+ break;
+ }
+
+ if (first_time)
+ {
+ // remember the service state, the first time we wait
+ last_state = this->svc_status_.dwCurrentState;
+ last_check_point = this->svc_status_.dwCheckPoint;
+ first_time = 0;
+ }
+ else
+ {
+ // update the state change.
+ if (last_state != this->svc_status_.dwCurrentState)
+ {
+ last_state = this->svc_status_.dwCurrentState;
+ last_check_point = this->svc_status_.dwCheckPoint;
+ }
+ else
+ {
+ // The check-point should have increased
+ if (this->svc_status_.dwCheckPoint > last_check_point)
+ last_check_point = this->svc_status_.dwCheckPoint;
+ else
+ {
+ // Service control failure, we are done.
+ service_ok = 0;
+ break;
+ }
+ }
+ }
+
+ ::Sleep (this->svc_status_.dwWaitHint);
+ }
+
+ return service_ok == 0 ? -1 : 0;
}
#endif /* ACE_WIN32 && !ACE_HAS_PHARLAP */
diff --git a/ace/NT_Service.h b/ace/NT_Service.h
index 32f74318a58..e3675b6fa57 100644
--- a/ace/NT_Service.h
+++ b/ace/NT_Service.h
@@ -333,12 +333,10 @@ protected:
* most <wait_time> to get to the desired state. If <wait_time> is
* 0, then the function keeps waiting until the desired state is
* reached or the service doesn't update its state any further. The
- * svc_status_ class member is updated upon return. NOTE - the
- * timeout doesn't currently work - it always acts like
- * ACE_Time_Value::zero is passed - it checks the state once but
- * doesn't wait after that.
+ * svc_status_ class member is updated upon return.
*/
- void wait_for_service_state (DWORD desired_state, ACE_Time_Value *wait_time);
+ void wait_for_service_state (DWORD desired_state,
+ ACE_Time_Value *wait_time);
/// Called by <handle_control> when a stop/shutdown was requested.
virtual void stop_requested (DWORD control_code);