示例#1
0
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");
    }
}
示例#2
0
function show_state_variable($introspection, $var_name)
{
    $channel_value = gupnp_service_introspection_get_state_variable($introspection, $var_name);
    printf("State variable, %s\n", $var_name);
    foreach ($channel_value as $key => $value) {
        printf("\t%-30s: %s\n", $key, $value);
    }
    printf("\n");
}