[SIGAR-121] Add Service.Pid PTQL support
This commit is contained in:
parent
80ef448f8c
commit
eeb3f26ad4
|
@ -20,6 +20,8 @@ package org.hyperic.sigar.win32.test;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.hyperic.sigar.Sigar;
|
||||
import org.hyperic.sigar.ptql.ProcessFinder;
|
||||
import org.hyperic.sigar.test.SigarTestCase;
|
||||
|
||||
import org.hyperic.sigar.win32.Service;
|
||||
|
@ -27,6 +29,7 @@ import org.hyperic.sigar.win32.ServiceConfig;
|
|||
import org.hyperic.sigar.win32.Win32Exception;
|
||||
|
||||
public class TestService extends SigarTestCase {
|
||||
private static final String EVENTLOG_NAME = "Eventlog";
|
||||
private static final String TEST_NAME = "MyTestService";
|
||||
|
||||
private static final String PREFIX =
|
||||
|
@ -43,7 +46,7 @@ public class TestService extends SigarTestCase {
|
|||
}
|
||||
|
||||
public void testServiceOpen() throws Exception {
|
||||
Service service = new Service("Eventlog");
|
||||
Service service = new Service(EVENTLOG_NAME);
|
||||
service.getConfig();
|
||||
service.close();
|
||||
|
||||
|
@ -93,6 +96,19 @@ public class TestService extends SigarTestCase {
|
|||
assertGtZeroTrace("getServiceConfigs", configs.size());
|
||||
}
|
||||
|
||||
public void testServicePtql() throws Exception {
|
||||
Sigar sigar = new Sigar();
|
||||
try {
|
||||
long pid = sigar.getServicePid(EVENTLOG_NAME);
|
||||
String ptql = "Service.Pid.eq=" + pid;
|
||||
List names = Service.getServiceNames(sigar, ptql);
|
||||
traceln(ptql + "==" + names);
|
||||
assertTrue(names.contains(EVENTLOG_NAME));
|
||||
} finally {
|
||||
sigar.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testServiceCreateDelete() throws Exception {
|
||||
if (!TEST_CREATE) {
|
||||
return;
|
||||
|
|
|
@ -683,7 +683,8 @@ enum {
|
|||
PTQL_PID_SERVICE_NAME,
|
||||
PTQL_PID_SERVICE_DISPLAY,
|
||||
PTQL_PID_SERVICE_PATH,
|
||||
PTQL_PID_SERVICE_EXE
|
||||
PTQL_PID_SERVICE_EXE,
|
||||
PTQL_PID_SERVICE_PID
|
||||
};
|
||||
|
||||
#ifdef SIGAR_64BIT
|
||||
|
@ -745,6 +746,9 @@ static int ptql_branch_init_service(ptql_parse_branch_t *parsed,
|
|||
/* basename of Path */
|
||||
branch->flags = PTQL_PID_SERVICE_EXE;
|
||||
}
|
||||
else if (strEQ(parsed->attr, "Pid")) {
|
||||
branch->flags = PTQL_PID_SERVICE_PID;
|
||||
}
|
||||
else {
|
||||
return ptql_error(error, "Unsupported %s attribute: %s",
|
||||
parsed->name, parsed->attr);
|
||||
|
@ -834,6 +838,7 @@ static int sigar_services_walk(sigar_services_walker_t *walker,
|
|||
return status;
|
||||
}
|
||||
for (i=0; i<ss.count; i++) {
|
||||
sigar_pid_t service_pid = 0;
|
||||
int status;
|
||||
char *value = NULL;
|
||||
char *name = ss.services[i].lpServiceName;
|
||||
|
@ -867,13 +872,21 @@ static int sigar_services_walk(sigar_services_walker_t *walker,
|
|||
continue;
|
||||
}
|
||||
break;
|
||||
case PTQL_PID_SERVICE_PID:
|
||||
sigar_service_pid_get(walker->sigar,
|
||||
name,
|
||||
&service_pid);
|
||||
break;
|
||||
case PTQL_PID_SERVICE_NAME:
|
||||
default:
|
||||
value = name;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ptql_str_match(walker->sigar, branch, value)) {
|
||||
if ((value && ptql_str_match(walker->sigar, branch, value)) ||
|
||||
(service_pid &&
|
||||
pid_branch_match(branch, service_pid, atoi(branch->data.str))))
|
||||
{
|
||||
if (walker->add_service(walker, name) != SIGAR_OK) {
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue