Skip to content

Commit

Permalink
C: Teach MTP-2 monitoring to allow options, e.g. filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasl committed Feb 17, 2014
1 parent cf93f07 commit a16fad4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 9 deletions.
71 changes: 62 additions & 9 deletions c/gth_apilib.c
Expand Up @@ -382,6 +382,46 @@ static int gth_wait_for_install_complete(GTH_api *api, int need_install_done)
return 0;
}

static int kv_to_tags(char *buffer,
const size_t buflen,
const GTH_attribute *attributes,
int n)
{
int used = 0;

*buffer = 0;

while (attributes && n > 0) {
used += snprintf(buffer + used, buflen - used,
"<attribute name='%s' value='%s'/>",
attributes->key, attributes->value);
n--;
attributes++;
}

return used;
}

static int kv_to_attributes(char *buffer,
const size_t buflen,
const GTH_attribute *attributes,
int n)
{
int used = 0;

*buffer = 0;

while (attributes && n > 0) {
used += snprintf(buffer + used, buflen - used,
" %s='%s'",
attributes->key, attributes->value);
n--;
attributes++;
}

return used;
}

// Internal; used by both gth_enable and gth_set
static int gth_enable_or_set(const char *command,
GTH_api *api,
Expand All @@ -397,13 +437,8 @@ static int gth_enable_or_set(const char *command,

used = snprintf(buffer, MAX_COMMAND, "<%s name='%s'>", command, resource);

while (attributes && n_attributes > 0) {
used += snprintf(buffer + used, MAX_COMMAND - used,
"<attribute name='%s' value='%s'/>",
attributes->key, attributes->value);
n_attributes--;
attributes++;
}
used += kv_to_tags(buffer + used, MAX_COMMAND - used,
attributes, n_attributes);

used += snprintf(buffer + used, MAX_COMMAND - used, "</%s>", command);

Expand Down Expand Up @@ -589,18 +624,36 @@ int gth_new_mtp2_monitor(GTH_api *api,
char *job_id,
const char *ip,
const int port)
{
return gth_new_mtp2_monitor_opt(api, tag, span, ts, job_id, ip, port, 0, 0);
}


int gth_new_mtp2_monitor_opt(GTH_api *api,
const int tag,
const char *span,
const int ts,
char *job_id,
const char *ip,
const int port,
const GTH_attribute *options,
const int n_options)
{
char command[MAX_COMMAND];
char attributes[MAX_COMMAND];
int result;
const char* template;

assert(ts > 0 && ts < 32);

template = "<new><mtp2_monitor ip_addr='%s' ip_port='%d' tag='%d'>"
result = kv_to_attributes(attributes, MAX_COMMAND, options, n_options);

template = "<new><mtp2_monitor %s ip_addr='%s' ip_port='%d' tag='%d'>"
"<pcm_source span='%s' timeslot='%d'/>"
"</mtp2_monitor></new>";

result = snprintf(command, MAX_COMMAND, template, ip, port, tag, span, ts);
result = snprintf(command, MAX_COMMAND, template,
attributes, ip, port, tag, span, ts);
assert(result < MAX_COMMAND);
api_write(api, command);
result = recv_job_id(api, job_id);
Expand Down
12 changes: 12 additions & 0 deletions c/gth_apilib.h
Expand Up @@ -262,6 +262,18 @@ int gth_new_mtp2_monitor(GTH_api *api,
const char *ip,
const int port);

// Start MTP-2 monitoring, with non-default options. The options are
// key/value pairs exactly as per the API manual, for instance
// option.name = "fisu"; option.value = "no".
int gth_new_mtp2_monitor_opt(GTH_api *api,
const int tag,
const char *span,
const int timeslot,
char *job_id,
const char *ip,
const int port,
const GTH_attribute *options,
const int n_options);

// Return: the file descriptor (>= 0) on success.
//
Expand Down

0 comments on commit a16fad4

Please sign in to comment.