Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update to version 0.17
Removed obsolete event definitions
Added pause and resume commands

This commit is slightly modified to apply cleanly.

Signed-off-by: Juho Hämäläinen <juho.hamalainen@tieto.com>
  • Loading branch information
Janne Mäntyharju authored and Juho Hämäläinen committed Nov 28, 2012
1 parent d48ad53 commit 8ee38eb
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 1 deletion.
48 changes: 48 additions & 0 deletions examples/ngf-client.c
Expand Up @@ -164,6 +164,50 @@ parse_command_stop (TestClient *c, char *buf)
g_print ("STOP (id=%d)\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 (id=%d)\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 (id=%d)\n", id);
}

static void
parse_input (TestClient *c, char *buf, size_t max_bytes)
{
Expand All @@ -178,6 +222,10 @@ 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
Expand Down
70 changes: 70 additions & 0 deletions libngf/client.c
Expand Up @@ -42,6 +42,9 @@
/** DBus method for stopping event */
#define NGF_DBUS_METHOD_STOP "Stop"

/** DBus method for pausing/resuming event */
#define NGF_DBUS_METHOD_PAUSE "Pause"

/** DBus method call that is sent to us when the event state changes */
#define NGF_DBUS_INTERNAL_STATUS "Status"

Expand Down Expand Up @@ -460,3 +463,70 @@ ngf_client_stop_event (NgfClient *client,
reply = reply->next;
}
}

static void
_pause_active_event (NgfClient *client,
NgfEvent *event,
int pause)
{
DBusMessage *msg = NULL;
DBusMessageIter iter;

if ((msg = dbus_message_new_method_call (NGF_DBUS_NAME,
NGF_DBUS_PATH,
NGF_DBUS_IFACE,
NGF_DBUS_METHOD_PAUSE)) == NULL)
{
return;
}

dbus_message_iter_init_append (msg, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &event->policy_id);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &pause);

dbus_connection_send (client->connection, msg, NULL);
dbus_message_unref (msg);
}

void
ngf_client_pause_event (NgfClient *client,
uint32_t id)
{
NgfEvent *event = NULL;
NgfReply *reply = NULL;

if (client == NULL)
return;

event = client->active_events;
while (event) {
if (event->event_id == id) {
_pause_active_event (client, event, 1);
break;
}

event = event->next;
}
}

void
ngf_client_resume_event (NgfClient *client,
uint32_t id)
{
NgfEvent *event = NULL;
NgfReply *reply = NULL;

if (client == NULL)
return;

event = client->active_events;
while (event) {
if (event->event_id == id) {
_pause_active_event (client, event, 0);
break;
}

event = event->next;
}
}

21 changes: 20 additions & 1 deletion libngf/client.h
Expand Up @@ -130,7 +130,7 @@ uint32_t ngf_client_play_event (NgfClient *client,
NgfProplist *proplist);

/**
* Stop a currently active event.
* Stop an active event.
*
* @param client NgfClient instance
* @param id Event id. If no such event, nothing is done.
Expand All @@ -139,6 +139,25 @@ uint32_t ngf_client_play_event (NgfClient *client,
void ngf_client_stop_event (NgfClient *client,
uint32_t id);

/**
* Pause active event.
*
* @param client NgfClient instance
* @param id Event id.
*/

void ngf_client_pause_event (NgfClient *client,
uint32_t id);

/**
* Resume paused event.
*
* @param client NgfClient instance
* @param id Event id.
*/

void ngf_client_resume_event (NgfClient *client,
uint32_t id);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 8ee38eb

Please sign in to comment.