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);
echo "=========================================================\n"; echo "[CALL]: gupnp_context_get_subscription_timeout({$context}) \n"; echo "---------------------------------------------------------\n"; $timeout = gupnp_context_get_subscription_timeout($context); echo "[RESULT]: "; var_dump($timeout); echo "=========================================================\n\n\n"; //$target = "urn:schemas-upnp-org:service:tvcontrol:1"; //$cb = "tv_service_cb"; $target = "urn:schemas-upnp-org:service:SwitchPower:1"; $cb = "switcher_service_cb"; $arg = "data"; echo "=========================================================\n"; echo "[CALL]: gupnp_control_point_new({$context}, {$target}) \n"; echo "---------------------------------------------------------\n"; $cp = gupnp_control_point_new($context, $target); echo "[RESULT]: "; var_dump($cp); echo "=========================================================\n\n\n"; echo "=========================================================\n"; echo "[CALL]: gupnp_browse_service({$cp}, {$cb}, {$arg}) \n"; echo "---------------------------------------------------------\n"; gupnp_browse_service($cp, $cb, $arg); echo "=========================================================\n\n\n"; //var_dump($proxy1); //$location = gupnp_service_info_get($proxy1); //var_dump($location); //$res = gupnp_service_proxy_action_set($proxy1, 'SetTarget', 'NewTargetValue', "0"); //var_dump($res); while (1) { /*
usage(); exit(-1); } $args = array(); for ($i = 1; $i < count($argv); $i++) { $tmp_args = explode('=', $argv[$i]); $args[$tmp_args[0]] = $tmp_args[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_tvdevice = gupnp_control_point_new($context, "urn:schemas-upnp-org:device:tvdevice:1"); $cp_tvcontrol = gupnp_control_point_new($context, "urn:schemas-upnp-org:service:tvcontrol:1"); /* Connect to the service-found callback */ $arg = array('args' => $args, 'cp' => $cp_tvdevice); $cb = "tvcontrol_device_proxy_available_cb"; gupnp_control_point_callback_set($cp_tvdevice, GUPNP_SIGNAL_DEVICE_PROXY_AVAILABLE, $cb, $arg); $cb = "tvcontrol_device_proxy_unavailable_cb"; gupnp_control_point_callback_set($cp_tvdevice, GUPNP_SIGNAL_DEVICE_PROXY_UNAVAILABLE, $cb, $arg); $arg = array('args' => $args, 'cp' => $cp_tvcontrol); $cb = "tvcontrol_service_proxy_available_cb"; gupnp_control_point_callback_set($cp_tvcontrol, GUPNP_SIGNAL_SERVICE_PROXY_AVAILABLE, $cb, $arg); $cb = "tvcontrol_service_proxy_unavailable_cb"; gupnp_control_point_callback_set($cp_tvcontrol, GUPNP_SIGNAL_SERVICE_PROXY_UNAVAILABLE, $cb, $arg); /* Start for browsing */ gupnp_control_point_browse_start($cp_tvdevice); gupnp_control_point_browse_start($cp_tvcontrol);
{ /* 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']); } } /* 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 MediaTomb */ $cp_device = gupnp_control_point_new($context, "urn:schemas-upnp-org:device:MediaServer:1"); $cp_service = gupnp_control_point_new($context, "urn:schemas-upnp-org:service:ContentDirectory:1"); /* Connect to the service-found callback */ $arg_device = array('cp_device' => $cp_device, 'cp_service' => $cp_service); $cb_device = "gupnp_device_proxy_available_cb"; gupnp_control_point_callback_set($cp_device, GUPNP_SIGNAL_DEVICE_PROXY_AVAILABLE, $cb_device, $arg_device); /* Start for browsing */ gupnp_control_point_browse_start($cp_device);
{ $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);
{ /* 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']); } } /* 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 MediaTomb */ $cp_device = gupnp_control_point_new($context, "urn:schemas-upnp-org:device:MediaServer:1"); $cp_service = gupnp_control_point_new($context, "urn:schemas-upnp-org:service:AVTransport:1"); /* Connect to the service-found callback */ $arg_device = array('cp_device' => $cp_device, 'cp_service' => $cp_service); $cb_device = "gupnp_device_proxy_available_cb"; gupnp_control_point_callback_set($cp_device, GUPNP_SIGNAL_DEVICE_PROXY_AVAILABLE, $cb_device, $arg_device); /* Start for browsing */ gupnp_control_point_browse_start($cp_device);