function gupnp_device_proxy_available_cb($proxy, $arg)
{
    /* Get device info */
    $info = gupnp_device_info_get($proxy);
    if ($info['friendly_name'] == 'MediaTomb') {
        printf("Device is available:\n");
        foreach ($info as $key => $value) {
            printf("\t%-30s: %s\n", $key, $value);
        }
        printf("\n");
        gupnp_control_point_browse_stop($arg['cp_device']);
        $arg_service = array('udn' => $info['udn'], 'cp_service' => $arg['cp_service']);
        $cb_service = "gupnp_service_proxy_available_cb";
        gupnp_control_point_callback_set($arg['cp_service'], GUPNP_SIGNAL_SERVICE_PROXY_AVAILABLE, $cb_service, $arg_service);
        gupnp_control_point_browse_start($arg['cp_service']);
    }
}
Example #2
0
    gupnp_control_point_browse_stop($arg['cp']);
}
/* Check and parse command line arguments */
if (count($argv) != 2) {
    usage();
    exit(-1);
}
if ($argv[1] == "on") {
    $mode = 'ON';
} elseif ($argv[1] == "off") {
    $mode = 'OFF';
} elseif ($argv[1] == "toggle") {
    $mode = 'TOGGLE';
} else {
    usage();
    exit(-1);
}
/* Create the UPnP context */
$context = gupnp_context_new();
if (!$context) {
    printf("Error creating the GUPnP context\n");
    exit(-1);
}
/* Create the control point, searching for SwitchPower services */
$cp = gupnp_control_point_new($context, "urn:schemas-upnp-org:service:SwitchPower:1");
/* Connect to the service-found callback */
$cb = "service_proxy_available_cb";
$arg = array('mode' => $mode, 'cp' => $cp);
gupnp_control_point_callback_set($cp, GUPNP_SIGNAL_SERVICE_PROXY_AVAILABLE, $cb, $arg);
/* Start for browsing */
gupnp_control_point_browse_start($cp);
Example #3
0
{
    $info = gupnp_service_info_get($proxy);
    $type = $info['service_type'];
    $location = $info['location'];
    printf("Service available:\n");
    printf("\ttype:     %s\n", $type);
    printf("\tlocation: %s\n", $location);
}
function service_proxy_unavailable_cb($proxy, $arg)
{
    $info = gupnp_service_info_get($proxy);
    $type = $info['service_type'];
    $location = $info['location'];
    printf("Service unavailable:\n");
    printf("\ttype:     %s\n", $type);
    printf("\tlocation: %s\n", $location);
}
/* Create the UPnP context */
$context = gupnp_context_new();
if (!$context) {
    printf("Error creating the GUPnP context\n");
    exit(-1);
}
/* We're interested in everything */
$cp = gupnp_control_point_new($context, "ssdp:all");
gupnp_control_point_callback_set($cp, GUPNP_SIGNAL_DEVICE_PROXY_AVAILABLE, 'device_proxy_available_cb');
gupnp_control_point_callback_set($cp, GUPNP_SIGNAL_DEVICE_PROXY_UNAVAILABLE, 'device_proxy_unavailable_cb');
gupnp_control_point_callback_set($cp, GUPNP_SIGNAL_SERVICE_PROXY_AVAILABLE, 'service_proxy_available_cb');
gupnp_control_point_callback_set($cp, GUPNP_SIGNAL_SERVICE_PROXY_UNAVAILABLE, 'service_proxy_unavailable_cb');
/* Start for browsing */
gupnp_control_point_browse_start($cp);