change Service.create to take ServiceConfig arg

This commit is contained in:
Doug MacEachern 2005-06-26 02:53:54 +00:00
parent 7e3f7cce07
commit 72e7b88512
2 changed files with 27 additions and 43 deletions

View File

@ -119,55 +119,37 @@ public class Service extends Win32 {
}
}
public static Service create(String serviceName,
String displayName,
String description,
String path)
public static Service create(ServiceConfig config)
throws Win32Exception
{
return create(serviceName, displayName, description,
ServiceConfig.TYPE_WIN32_OWN_PROCESS,
ServiceConfig.START_AUTO,
ServiceConfig.ERROR_NORMAL,
path, null, null, "");
if (config.getName() == null) {
throw new IllegalArgumentException("name=null");
}
public static Service create(String serviceName, String displayName,
String description, int serviceType,
int startType, int errorControl,
String path, String[] dependencies,
String startName, String password)
throws Win32Exception
{
if (serviceName == null) {
throw new IllegalArgumentException("serviceName=null");
}
if (path == null) {
if (config.getPath() == null) {
throw new IllegalArgumentException("path=null");
}
if (displayName == null) {
displayName = serviceName;
}
Service service = new Service();
service.service = CreateService(service.manager,
serviceName,
displayName,
serviceType,
startType,
errorControl,
path,
dependencies,
startName,
password);
service.service =
CreateService(service.manager,
config.getName(),
config.getDisplayName(),
config.getType(),
config.getStartType(),
config.getErrorControl(),
config.getPath(),
config.getDependencies(),
config.getServiceStartName(),
config.getPassword());
if (service.service == 0) {
throw getLastErrorException();
}
service.setDescription(description);
if (config.getDescription() != null) {
service.setDescription(config.getDescription());
}
return service;
}

View File

@ -2,6 +2,7 @@ package net.hyperic.sigar.win32.test;
import junit.framework.TestCase;
import net.hyperic.sigar.win32.Service;
import net.hyperic.sigar.win32.ServiceConfig;
public class TestService extends TestCase {
@ -20,11 +21,12 @@ public class TestService extends TestCase {
if (!TEST_CREATE) {
return;
}
Service service =
Service.create("MyTestService",
"My Test Service",
"This is a great service.",
"C:\\oracle\\ora90\\bin\\agntsrvc.exe");
ServiceConfig config = new ServiceConfig("MyTestService");
config.setDisplayName("My Test Service");
config.setDescription("A Description of " + config.getDisplayName());
config.setPath("C:\\Program Files\\My Test 1.0\\mytest.exe");
Service.create(config);
}
public void testDeleteService() throws Exception {