Example #1
0
    printf("[CALL] query_status_cb");
}
/* By default the light is off */
$GLOBALS['status'] = false;
printf("The light is now %s.\n", $GLOBALS['status'] ? "on" : "off");
/* Create the UPnP context */
$context = gupnp_context_new();
if (!$context) {
    printf("Error creating the GUPnP context\n");
    exit(-1);
}
/* Host the directory that contains device and service description files */
gupnp_context_host_path($context, "./web", "");
/* Create root device */
$location = "/BinaryLight1.xml";
$dev = gupnp_root_device_new($context, $location);
gupnp_root_device_set_available($dev, true);
/* Get the switch service from the root device */
$service_type = "urn:schemas-upnp-org:service:SwitchPower:1";
$service = gupnp_device_info_get_service($dev, $service_type);
if (!$service) {
    die("Cannot get SwitchPower1 service\n");
}
/* Set callback for action GetStatus */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "GetStatus", "get_status_cb", "action data, GetStatus");
/* Set callback for action GetTarget */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "GetTarget", "get_target_cb", "action data, GetTarget");
/* Set callback for action SetTarget */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "SetTarget", "set_target_cb", "action data, SetTarget");
/* Run the main loop */
gupnp_root_device_start($dev);
Example #2
0
$service_info = gupnp_device_info_get_service($device, $service_type);
echo "[RESULT]: ";
var_dump($service_info);
echo "=========================================================\n\n\n";
$cb = "action_getstatus_cb";
$arg = "action data, GetStatus";
$action_name = "action-invoked::GetStatus";
echo "=========================================================\n";
echo "[CALL]: gupnp_device_action_callback_set({$service_info}, {$action_name}, {$cb}, {$arg}) \n";
echo "---------------------------------------------------------\n";
$result = gupnp_device_action_callback_set($service_info, $action_name, $cb, $arg);
echo "[RESULT]: ";
var_dump($result);
echo "=========================================================\n\n\n";
$cb = "action_settarget_cb";
$arg = "action data, SetTarget";
$action_name = "action-invoked::SetTarget";
echo "=========================================================\n";
echo "[CALL]: gupnp_device_action_callback_set({$service_info}, {$action_name}, {$cb}, {$arg}) \n";
echo "---------------------------------------------------------\n";
$result = gupnp_device_action_callback_set($service_info, $action_name, $cb, $arg);
echo "[RESULT]: ";
var_dump($result);
echo "=========================================================\n\n\n";
echo "=========================================================\n";
echo "[CALL]: gupnp_main_loop_run() \n";
echo "---------------------------------------------------------\n";
$result = gupnp_main_loop_run();
echo "[RESULT]: ";
var_dump($result);
echo "=========================================================\n\n\n";
Example #3
0
/* Create root device */
$dev = gupnp_root_device_new($context, "/tvdevicedesc.xml");
/* Get relative location */
$rel_location = gupnp_root_device_get_relative_location($dev);
printf("\trelative location: %s\n", $rel_location);
/* Subscription timeout */
$subs_timeout = gupnp_context_get_subscription_timeout($context);
printf("\tsubscription timeout: %d\n\n", $subs_timeout);
printf("Change timeout:\n");
gupnp_context_set_subscription_timeout($context, 10);
printf("\tsubscription timeout: %d\n\n", gupnp_context_get_subscription_timeout($context));
if (!gupnp_root_device_get_available($dev)) {
    gupnp_root_device_set_available($dev, true);
}
/* Get the service from the root device */
$service_tvcontrol = "urn:schemas-upnp-org:service:tvcontrol:1";
$service = gupnp_device_info_get_service($dev, $service_tvcontrol);
if (!$service) {
    printf("Cannot get %s service\n", $service_tvcontrol);
    exit(-1);
}
/* Set callback for action PowerOn */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "PowerOn", "power_on_cb", "PowerOn");
/* Set callback for action PowerOff */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "PowerOff", "power_off_cb", "PowerOff");
/* Set callback for action SetChannel */
gupnp_device_action_callback_set($service, GUPNP_SIGNAL_ACTION_INVOKED, "SetChannel", "set_channel_cb", "SetChannel");
/* Set callback for timeout */
gupnp_context_timeout_add($context, 5000, "timeout_cb", NULL);
/* Run the main loop */
gupnp_root_device_start($dev);