increase chance of accurate error messages

This commit is contained in:
Doug MacEachern 2005-06-26 05:33:52 +00:00
parent 7f2451aa76
commit 01f5cb6c9e
3 changed files with 24 additions and 11 deletions

View File

@ -63,14 +63,23 @@ JNIEXPORT jboolean SIGAR_JNI(win32_Service_CloseServiceHandle)
return CloseServiceHandle((SC_HANDLE)handle);
}
JNIEXPORT jboolean SIGAR_JNI(win32_Service_ControlService)
JNIEXPORT jint SIGAR_JNI(win32_Service_ControlService)
(JNIEnv *, jclass, jlong handle, jint control)
{
BOOL retval;
SERVICE_STATUS status;
if (control == 0) {
return StartService((SC_HANDLE)handle, 0, NULL);
retval = StartService((SC_HANDLE)handle, 0, NULL);
}
else {
retval = ControlService((SC_HANDLE)handle, control, &status);
}
if (retval) {
return ERROR_SUCCESS;
}
else {
return GetLastError();
}
return ControlService((SC_HANDLE)handle, control, &status);
}
JNIEXPORT jlong SIGAR_JNI(win32_Service_CreateService)

View File

@ -183,6 +183,12 @@ public class Service extends Win32 {
return STATUS[getStatus()];
}
private void control(int ctl) throws Win32Exception {
if (ControlService(this.service, ctl) != SUCCESS) {
throw new Win32Exception(GetErrorMessage(ctl));
}
}
private static class Waiter {
long start = System.currentTimeMillis();
Service service;
@ -226,9 +232,7 @@ public class Service extends Win32 {
public void stop() throws Win32Exception
{
if (ControlService(this.service, CONTROL_STOP) == false) {
throw getLastErrorException();
}
control(CONTROL_STOP);
}
public void stop(long timeout) throws Win32Exception
@ -247,9 +251,7 @@ public class Service extends Win32 {
public void start() throws Win32Exception
{
if (ControlService(this.service, CONTROL_START) == false) {
throw getLastErrorException();
}
control(CONTROL_START);
}
public void start(long timeout) throws Win32Exception
@ -298,7 +300,7 @@ public class Service extends Win32 {
String startName,
String password);
private static native boolean ControlService(long handle,
private static native int ControlService(long handle,
int control);
private static native boolean DeleteService(long handle);

View File

@ -5,6 +5,8 @@ import net.hyperic.sigar.SigarException;
abstract class Win32 {
static int SUCCESS = 0;
static {
try {
Sigar.load();