Skip to content

Commit

Permalink
Merge pull request #3 from jusa/dev
Browse files Browse the repository at this point in the history
Update client to match updated ngfd DBus interface, update ngf-client example.
  • Loading branch information
bwachter committed Dec 3, 2012
2 parents d48ad53 + 5c8d7bc commit b8f2c9d
Show file tree
Hide file tree
Showing 11 changed files with 538 additions and 309 deletions.
11 changes: 0 additions & 11 deletions coverage.sh

This file was deleted.

9 changes: 0 additions & 9 deletions debian/api

This file was deleted.

2 changes: 1 addition & 1 deletion doc/doxygen.cfg
Expand Up @@ -43,7 +43,7 @@ WARN_LOGFILE = "doxygen.log"
#---------------------------------------------------------------------------

#FILE_VERSION_FILTER = "git log --pretty=format:%H -n 1"
INPUT = ../libngf/ ./src
INPUT = ./libngf/ ./doc/src
FILE_PATTERNS = *.h *.dox
RECURSIVE = YES
#EXCLUDE =
Expand Down
119 changes: 102 additions & 17 deletions examples/ngf-client.c
Expand Up @@ -77,16 +77,30 @@ get_str (char *buffer, char delim, char **str)
return p;
}

static void
print_help ()
{
g_print ("Available commands:\n");
g_print (" play [EVENT_NAME] [KEY:VALUE], returns [ID]*\n");
g_print (" stop [ID]\n");
g_print (" pause [ID]\n");
g_print (" resume [ID]\n\n");
g_print ("Examples:\n");
g_print (" play ringtone media.audio:(boolean)true\n");
g_print (" stop 1\n");
g_print (" play sms media.audio:(boolean)true\n");
}

static void
parse_command_play (TestClient *c, char *buf)
{
char *advance = buf;
char *event_id = NULL, *key = NULL, *value = NULL, *ptr = NULL, *type = NULL;
char *event = NULL, *key = NULL, *value = NULL, *ptr = NULL, *type = NULL;
NgfProplist *p = NULL;

/* First parameter is the event */
advance = get_str (buf, ' ', &event_id);
if (event_id == NULL) {
advance = get_str (buf, ' ', &event);
if (event == NULL) {
g_print ("Usage: play [EVENT_NAME] [KEY:VALUE], returns [ID]*\n");
return;
}
Expand All @@ -107,39 +121,54 @@ parse_command_play (TestClient *c, char *buf)

/* Parse the value, it may contain optional type within parenthesis. */

g_print ("key=%s, value=%s\n", key, value);
g_print ("key=%s ", key);

if (value[0] == '(') {
ptr = get_str ((value + 1), ')', &type);
g_print ("type=%s, ptr=%s\n", type, ptr);

if (strncmp (type, "string", 6) == 0) {
ngf_proplist_sets (p, key, ptr);
g_print ("value=string:%s\n", ptr);
}
else if (strncmp (type, "integer", 7) == 0) {
ngf_proplist_set_as_integer (p, key, ngf_proplist_parse_integer (ptr));
g_print ("integer -> %d\n", ngf_proplist_get_as_integer (p, key));
int32_t value;
if (ngf_proplist_parse_integer (ptr, &value)) {
ngf_proplist_set_as_integer (p, key, value);
g_print ("value=integer:%d\n", value);
}
}
else if (strncmp (type, "boolean", 7) == 0) {
ngf_proplist_set_as_boolean (p, key, ngf_proplist_parse_boolean (ptr));
g_print ("boolean -> %s\n", ngf_proplist_get_as_boolean (p, key) ? "TRUE" : "FALSE");
else if (strncmp (type, "unsigned", 8) == 0) {
uint32_t value;
if (ngf_proplist_parse_unsigned (ptr, &value)) {
ngf_proplist_set_as_unsigned (p, key, value);
g_print ("value=unsigned:%u\n", value);
}
}
else if (strncmp (type, "boolean", 7) == 0) {
int value;
if (ngf_proplist_parse_boolean (ptr, &value)) {
ngf_proplist_set_as_boolean (p, key, value);
g_print ("value=boolean:%s\n", value ? "TRUE" : "FALSE");
}
} else
g_print ("value type unknown. skipping.\n");

free (type);
}
else {
ngf_proplist_sets (p, key, value);
g_print ("value=string:%s\n", ptr);
}

free (key);
free (value);
}

uint32_t id = ngf_client_play_event (c->client, event_id, p);
g_print ("PLAY (id=%d, event_id=%s)\n", id, event_id);
uint32_t event_id = ngf_client_play_event (c->client, event, p);
g_print ("PLAY (event=%s, event_id=%u)\n", event, event_id);

ngf_proplist_free (p);
free (event_id);
free (event);
}

static void
Expand All @@ -161,7 +190,51 @@ parse_command_stop (TestClient *c, char *buf)
free (str);

ngf_client_stop_event (c->client, id);
g_print ("STOP (id=%d)\n", id);
g_print ("STOP (event_id=%u)\n", id);
}

static void
parse_command_pause (TestClient *c, char *buf)
{
char *advance = buf;
char *str = NULL;
uint32_t id = 0;

advance = get_str (buf, ' ', &str);
(void) advance;

if (str == NULL) {
g_print ("Usage: pause [ID]\n");
return;
}

id = atoi (str);
free (str);

ngf_client_pause_event (c->client, id);
g_print ("PAUSE (event_id=%u)\n", id);
}

static void
parse_command_resume (TestClient *c, char *buf)
{
char *advance = buf;
char *str = NULL;
uint32_t id = 0;

advance = get_str (buf, ' ', &str);
(void) advance;

if (str == NULL) {
g_print ("Usage: resume [ID]\n");
return;
}

id = atoi (str);
free (str);

ngf_client_resume_event (c->client, id);
g_print ("RESUME (event_id=%u)\n", id);
}

static void
Expand All @@ -178,10 +251,16 @@ parse_input (TestClient *c, char *buf, size_t max_bytes)
parse_command_play (c, advance);
else if (strncmp (str, "stop", 4) == 0)
parse_command_stop (c, advance);
else if (strncmp (str, "pause", 5) == 0)
parse_command_pause (c, advance);
else if (strncmp (str, "resume", 6) == 0)
parse_command_resume (c, advance);
else if (strncmp (str, "quit", 4) == 0)
g_main_loop_quit (c->loop);
else if (strncmp (str, "help", 4) == 0)
print_help ();
else
g_print ("Unrecognized command: %s\n", str);
g_print ("Unrecognized command: %s (try \"help\")\n", str);

free (str);
g_print ("> ");
Expand Down Expand Up @@ -215,11 +294,17 @@ client_callback_cb (NgfClient *client, uint32_t event_id, NgfEventState state, v
(void) userdata;

switch (state) {
case NGF_EVENT_FAILED:
g_print ("\nFailed (event_id=%d)\n", event_id);
break;
case NGF_EVENT_COMPLETED:
g_print ("\nCompleted (event_id=%d)\n", event_id);
break;
case NGF_EVENT_FAILED:
g_print ("\nFailed (event_id=%d)\n", event_id);
case NGF_EVENT_PLAYING:
g_print ("\nPlaying (event_id=%d)\n", event_id);
break;
case NGF_EVENT_PAUSED:
g_print ("\nPaused (event_id=%d)\n", event_id);
break;
case NGF_EVENT_BUSY:
g_print ("\nBusy (event_id=%d)\n", event_id);
Expand Down
2 changes: 0 additions & 2 deletions libngf.changes

This file was deleted.

84 changes: 0 additions & 84 deletions libngf.spec

This file was deleted.

0 comments on commit b8f2c9d

Please sign in to comment.