From da6d72a31eddcea972027eb78138e9a4a785cab7 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 5 Mar 2008 04:19:39 +0000 Subject: [PATCH] [SIGAR-90] move Service to its own class --- .../src/org/hyperic/sigar/test/TestPTQL.java | 8 +-- src/sigar_ptql.c | 57 +++++++++++-------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java index 9dc331b9..d916ff3d 100644 --- a/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java +++ b/bindings/java/src/org/hyperic/sigar/test/TestPTQL.java @@ -67,10 +67,10 @@ public class TestPTQL extends SigarTestCase { "Pid.PidFile.eq=pid.file", "Pid.Pid.eq=1", THIS_PROCESS, - "Pid.Service.eq=Eventlog", - "Pid.Service.eq=NOSUCHSERVICE", - "Pid.Service.ct=Oracle", - "Pid.ServiceDisplay.re=DHCP|DNS", + "Pid.Service.eq=Eventlog", //compat -> Service.Name + "Service.Name.eq=NOSUCHSERVICE", + "Service.Name.ct=Oracle", + "Service.DisplayName.re=DHCP|DNS", OTHER_JAVA_PROCESS, //all java procs cept this one "Cpu.Percent.ge=0.2", "State.Name.sw=java,Args.*.eq=org.jboss.Main", //jboss diff --git a/src/sigar_ptql.c b/src/sigar_ptql.c index 14db2638..96883fa2 100644 --- a/src/sigar_ptql.c +++ b/src/sigar_ptql.c @@ -665,8 +665,29 @@ enum { #endif -#define PID_SERVICE_ATTR "Service" -#define PID_SERVICE_ATTR_LEN (sizeof(PID_SERVICE_ATTR)-1) +static int ptql_branch_init_service(ptql_parse_branch_t *parsed, + ptql_branch_t *branch, + sigar_ptql_error_t *error) +{ + branch->op_flags |= PTQL_OP_FLAG_PID; + + if (strEQ(parsed->attr, "Name")) { + branch->flags = PTQL_PID_SERVICE; + } + else if (strEQ(parsed->attr, "DisplayName")) { + branch->flags = PTQL_PID_SERVICE_DISPLAY; + } + else { + return ptql_error(error, "Unsupported %s attribute: %s", + parsed->name, parsed->attr); + } + +#ifdef WIN32 + branch->data.str = sigar_strdup(parsed->value); + branch->data_size = strlen(parsed->value); +#endif + return SIGAR_OK; +} static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, ptql_branch_t *branch, @@ -694,27 +715,6 @@ static int ptql_branch_init_pid(ptql_parse_branch_t *parsed, branch->data_size = strlen(parsed->value); return SIGAR_OK; } - else if (strnEQ(parsed->attr, - PID_SERVICE_ATTR, PID_SERVICE_ATTR_LEN)) - { - char *attr = parsed->attr + PID_SERVICE_ATTR_LEN; - branch->flags = 0; - if (*attr) { - if (strEQ(attr, "Display")) { - branch->flags = PTQL_PID_SERVICE_DISPLAY; - } - } - else { - branch->flags = PTQL_PID_SERVICE; - } - if (branch->flags) { -#ifdef WIN32 - branch->data.str = sigar_strdup(parsed->value); - branch->data_size = strlen(parsed->value); -#endif - return SIGAR_OK; - } - } return ptql_error(error, "Unsupported %s attribute: %s", parsed->name, parsed->attr); @@ -1124,6 +1124,10 @@ static ptql_lookup_t PTQL_Pid[] = { { NULL, ptql_pid_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_pid } }; +static ptql_lookup_t PTQL_Service[] = { + { NULL, ptql_pid_match, 0, 0, PTQL_VALUE_TYPE_ANY, ptql_branch_init_service } +}; + static ptql_entry_t ptql_map[] = { { "Time", PTQL_Time }, { "Cpu", PTQL_Cpu }, @@ -1137,6 +1141,7 @@ static ptql_entry_t ptql_map[] = { { "Env", PTQL_Env }, { "Port", PTQL_Port }, { "Pid", PTQL_Pid }, + { "Service", PTQL_Service }, { NULL } }; @@ -1192,6 +1197,12 @@ static int ptql_branch_parse(char *query, ptql_parse_branch_t *branch, return ptql_error(error, "Missing query"); } + /* Pid.Service -> Service.Name */ + if (strEQ(branch->attr, "Service")) { + branch->name = branch->attr; + branch->attr = "Name"; + } + return SIGAR_OK; }