From 7a3b9a8fe6b4f60a4177c7516af6b33276abfe91 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 26 Mar 2008 17:06:32 +0000 Subject: [PATCH] add sigar_services_query function --- src/os/win32/sigar_os.h | 4 ++++ src/sigar_ptql.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/os/win32/sigar_os.h b/src/os/win32/sigar_os.h index 63921fc8..a160d4de 100644 --- a/src/os/win32/sigar_os.h +++ b/src/os/win32/sigar_os.h @@ -600,6 +600,10 @@ struct sigar_services_walker_t { 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 } #endif diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 0d820d98..64d78b15 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -769,6 +769,14 @@ static int sigar_services_walk(sigar_services_walker_t *walker, char *value; 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) { case PTQL_PID_SERVICE_DISPLAY: 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); } + +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 static int ptql_pid_get(sigar_t *sigar,