Example #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");
    }
}
Example #2
0
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']);
    }
}
Example #3
0
function tv_service_cb($proxy, $arg)
{
    echo "[CALLED] tv_service_cb()\n";
    global $proxy1;
    $proxy1 = $proxy;
    var_dump($proxy);
    var_dump($arg);
    //unset($proxy);
    unset($arg);
    //var_dump($proxy);
    var_dump($arg);
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_info_get({$proxy}) \n";
    echo "---------------------------------------------------------\n";
    $info = gupnp_service_info_get($proxy);
    echo "[RESULT]: ";
    var_dump($info);
    echo "---------------------------------------------------------\n\n";
    $value = rand(1, 100);
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_action_set({$proxy}, 'SetChannel', 'Channel', {$value}, GUPNP_TYPE_LONG) \n";
    echo "---------------------------------------------------------\n";
    $res = gupnp_service_proxy_action_set($proxy, 'SetChannel', 'Channel', $value, GUPNP_TYPE_LONG);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_action_get({$proxy}, 'SetChannel', 'Channel', GUPNP_TYPE_LONG) \n";
    echo "---------------------------------------------------------\n";
    $res = gupnp_service_proxy_action_get($proxy, 'SetChannel', 'Channel', GUPNP_TYPE_LONG);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_add_notify({$proxy}, 'Channel', GUPNP_TYPE_LONG, {$cb}, {$arg}) \n";
    echo "---------------------------------------------------------\n";
    $cb = "notify_cb";
    $arg = "notify data, channel";
    $res = gupnp_service_proxy_add_notify($proxy, 'Channel', GUPNP_TYPE_LONG, $cb, $arg);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_add_notify({$proxy}, 'Power', GUPNP_TYPE_BOOLEAN, {$cb}, {$arg}) \n";
    echo "---------------------------------------------------------\n";
    $cb = "notify_cb";
    $arg = "notify data, power";
    $res = gupnp_service_proxy_add_notify($proxy, 'Power', GUPNP_TYPE_BOOLEAN, $cb, $arg);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_get_subscribed() \n";
    echo "---------------------------------------------------------\n";
    $res = gupnp_service_proxy_get_subscribed($proxy);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_set_subscribed({$proxy}, true) \n";
    echo "---------------------------------------------------------\n";
    gupnp_service_proxy_set_subscribed($proxy, true);
    echo "---------------------------------------------------------\n\n";
    echo "---------------------------------------------------------\n";
    echo "[CALL]: gupnp_service_proxy_get_subscribed({$proxy}) \n";
    echo "---------------------------------------------------------\n";
    $res = gupnp_service_proxy_get_subscribed($proxy);
    echo "[RESULT]: ";
    var_dump($res);
    echo "---------------------------------------------------------\n\n";
}