Parcours des périphériques et des services

Cet exemple montre comment obtenir des informations sur tous les périphériques et les services. Une boucle infinie (en utilisant CLI) est démarrée et si un périphérique ou un service disponible est trouvé, la fonction de rappel correspondante sera appelée.

Exemple #1 Recherche tous les périphériques et services UPnP.

<?php

/* Fonction de rappel pour les périphériques disponibles */
function device_proxy_available_cb($proxy$arg)
{
    
$info gupnp_device_info_get($proxy);

    
$type $info['device_type'];
    
$location $info['location'];

    
printf("Device available:\n");
    
printf("\ttype:     %s\n"$type);
    
printf("\tlocation: %s\n"$location);
}

/* Fonction de rappel pour les services disponibles */
function service_proxy_available_cb($proxy$arg)
{
    
$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);
}

/* Création du contexte UPnP */
$context gupnp_context_new();
if (!
$context) {
    
printf("Error creating the GUPnP context\n");
    exit(-
1);
}

/* Nous sommes intéressé par tout ! */
$cp gupnp_control_point_new($context"ssdp:all");

/* Définit les fonctions de rappel */
gupnp_control_point_callback_set($cp
    
GUPNP_SIGNAL_DEVICE_PROXY_AVAILABLE'device_proxy_available_cb');
gupnp_control_point_callback_set($cp
    
GUPNP_SIGNAL_SERVICE_PROXY_AVAILABLE'service_proxy_available_cb');

/* Commence le parcours (boucle infinie, il faut utiliser le raccourci clavier Ctrl-C pour l'interrompre) */
gupnp_control_point_browse_start($cp);

?>