summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJens Georg <mail@jensge.org>2018-12-14 23:14:58 +0100
committerJens Georg <mail@jensge.org>2019-02-04 21:47:49 +0100
commitf434d30cb71061f5416ecf97b525231c6540aabf (patch)
treee3de3b9c6a632439b88c3e2077bb33359ff3016f /examples
parent45d568505ff4263eb299375bef815c38dcd97c7b (diff)
downloadgupnp-f434d30cb71061f5416ecf97b525231c6540aabf.tar.gz
service-proxy: Add new API for calling actions
Diffstat (limited to 'examples')
-rw-r--r--examples/light-client.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/examples/light-client.c b/examples/light-client.c
index 82ee54c..359bc3e 100644
--- a/examples/light-client.c
+++ b/examples/light-client.c
@@ -39,16 +39,28 @@ send_cmd (GUPnPServiceProxy *proxy)
GError *error = NULL;
gboolean target;
+ GUPnPServiceProxyAction *action;
+
if (mode == TOGGLE) {
/* We're toggling, so first fetch the current status */
- if (!gupnp_service_proxy_send_action
- (proxy, "GetStatus", &error,
- /* IN args */ NULL,
- /* OUT args */ "ResultStatus", G_TYPE_BOOLEAN, &target, NULL)) {
+
+ action = gupnp_service_proxy_action_new ("GetStatus", NULL);
+
+ gupnp_service_proxy_call_action (proxy, action, NULL, &error);
+ if (error != NULL)
goto error;
- }
+
+ gupnp_service_proxy_action_get_result (action,
+ &error,
+ "ResultStatus", G_TYPE_BOOLEAN, &target, NULL);
+ g_clear_pointer (&action, gupnp_service_proxy_action_unref);
+
+ if (error != NULL)
+ goto error;
+
/* And then toggle it */
target = ! target;
+
} else {
/* Mode is a boolean, so the target is the mode thanks to our well chosen
enumeration values. */
@@ -56,12 +68,13 @@ send_cmd (GUPnPServiceProxy *proxy)
}
/* Set the target */
- if (!gupnp_service_proxy_send_action (proxy, "SetTarget", &error,
- /* IN args */
- "newTargetValue", G_TYPE_BOOLEAN, target, NULL,
- /* OUT args */
- NULL)) {
- goto error;
+
+ action = gupnp_service_proxy_action_new ("SetTarget",
+ "newTargetValue", G_TYPE_BOOLEAN, target, NULL);
+ gupnp_service_proxy_call_action (proxy, action, NULL, &error);
+ g_clear_pointer (&action, gupnp_service_proxy_action_unref);
+ if (error != NULL) {
+ goto error;
} else {
if (!quiet) {
g_print ("Set switch to %s.\n", target ? "on" : "off");
@@ -76,6 +89,7 @@ send_cmd (GUPnPServiceProxy *proxy)
return;
error:
+ g_clear_pointer (&action, gupnp_service_proxy_action_unref);
g_printerr ("Cannot set switch: %s\n", error->message);
g_error_free (error);
goto done;