function service_proxy_available_cb($proxy, $arg) { $mode = $arg['mode']; printf("Set subscribed\n"); gupnp_service_proxy_set_subscribed($proxy, true); /* Add notify if status will be changed */ if (!gupnp_service_proxy_add_notify($proxy, "Status", GUPNP_TYPE_BOOLEAN, "status_changed_cb", $arg)) { printf("Failed to add notify\n"); } $introspection = gupnp_service_info_get_introspection($proxy); $status_val = gupnp_service_introspection_get_state_variable($introspection, 'Status'); printf("Status state value:\n"); var_dump($status_val); if ($mode == 'TOGGLE') { /* We're toggling, so first fetch the current status */ $target = gupnp_service_proxy_action_get($proxy, 'GetStatus', 'ResultStatus', GUPNP_TYPE_BOOLEAN); /* And then toggle it */ $target = !$target; } else { /* Mode is a boolean, so the target is the mode thanks to our well chosen enumeration values. */ $target = $mode == 'ON' ? true : false; } /* Set the target */ if (!gupnp_service_proxy_action_set($proxy, 'SetTarget', 'NewTargetValue', $target, GUPNP_TYPE_BOOLEAN)) { printf("Cannot set switch\n"); } else { printf("Set switch to %s.\n", $target ? "on" : "off"); } }
function tvcontrol_service_proxy_available_cb($proxy, $arg) { printf("Service is available\n"); /* Get service info */ $info = gupnp_service_info_get($proxy); foreach ($info as $key => $value) { printf("\t%-30s: %s\n", $key, $value); } printf("\n"); $introspection = gupnp_service_info_get_introspection($proxy); show_state_variable($introspection, 'Power'); show_state_variable($introspection, 'Channel'); show_state_variable($introspection, 'Volume'); /* Set callback for async introspection */ gupnp_service_info_get_introspection($proxy, "tvcontrol_introspection_cb", NULL); /* Subscibe to service proxy */ gupnp_service_proxy_callback_set($proxy, GUPNP_SIGNAL_SUBSCRIPTION_LOST, "tvcontrol_subscription_lost_cb", NULL); $subscribed = gupnp_service_proxy_get_subscribed($proxy); printf("Check subscribed:\n"); printf("\tstatus: %s\n", $subscribed ? 'true' : 'false'); if (!$subscribed) { printf("Set subscribed\n"); gupnp_service_proxy_set_subscribed($proxy, true); } /* Add notify if channel will be changed */ if (!gupnp_service_proxy_add_notify($proxy, "Channel", GUPNP_TYPE_INT, "tvcontrol_channel_changed_cb", NULL)) { printf("Failed to add notify\n"); } printf("\n"); if (isset($arg['args']['power'])) { tvcontrol_set_power($proxy, $arg['args']['power']); } if (isset($arg['args']['channel'])) { tvcontrol_set_channel($proxy, $arg['args']['channel']); } }