コード例 #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 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";
}
コード例 #3
0
ファイル: test-client.php プロジェクト: santiago739/php-gupnp
function tvcontrol_set_channel($proxy, $arg)
{
    $channel_new = (int) $arg;
    /* Set the target */
    if (!gupnp_service_proxy_action_set($proxy, 'SetChannel', 'Channel', $channel_new, GUPNP_TYPE_INT)) {
        printf("Cannot set channel\n");
    } else {
        printf("Set channel to %d.\n", $channel_new);
    }
    sleep(11);
    if (!gupnp_service_proxy_action_set($proxy, 'SetChannel', 'Channel', ++$channel_new, GUPNP_TYPE_INT)) {
        printf("Cannot set channel\n");
    } else {
        printf("Set channel to %d.\n", $channel_new);
    }
    printf("\n");
}