add sigar_services_query function

This commit is contained in:
Doug MacEachern 2008-03-26 17:06:32 +00:00
parent d98b62dc9e
commit 7a3b9a8fe6
2 changed files with 43 additions and 0 deletions

View File

@ -600,6 +600,10 @@ struct sigar_services_walker_t {
int (*add_service)(sigar_services_walker_t *walker, char *name); int (*add_service)(sigar_services_walker_t *walker, char *name);
}; };
int sigar_services_query(char *ptql,
sigar_ptql_error_t *error,
sigar_services_walker_t *walker);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -769,6 +769,14 @@ static int sigar_services_walk(sigar_services_walker_t *walker,
char *value; char *value;
char *name = ss.services[i].lpServiceName; char *name = ss.services[i].lpServiceName;
if (branch == NULL) {
/* no query, return all */
if (walker->add_service(walker, name) != SIGAR_OK) {
break;
}
continue;
}
switch (branch->flags) { switch (branch->flags) {
case PTQL_PID_SERVICE_DISPLAY: case PTQL_PID_SERVICE_DISPLAY:
value = ss.services[i].lpDisplayName; value = ss.services[i].lpDisplayName;
@ -831,6 +839,37 @@ static int ptql_pid_service_list_get(sigar_t *sigar,
return sigar_services_walk(&walker, branch); return sigar_services_walk(&walker, branch);
} }
int sigar_services_query(char *ptql,
sigar_ptql_error_t *error,
sigar_services_walker_t *walker)
{
int status;
sigar_ptql_query_t *query;
if (ptql == NULL) {
return sigar_services_walk(walker, NULL);
}
status = sigar_ptql_query_create(&query, (char *)ptql, error);
if (status != SIGAR_OK) {
return status;
}
if (query->branches.number == 1) {
status =
sigar_services_walk(walker, &query->branches.data[0]);
}
else {
ptql_error(error, "Too many queries (%d), must be (1)",
query->branches.number);
status = SIGAR_PTQL_MALFORMED_QUERY;
}
sigar_ptql_query_destroy(query);
return status;
}
#endif #endif
static int ptql_pid_get(sigar_t *sigar, static int ptql_pid_get(sigar_t *sigar,