示例#1
0
文件: Client.php 项目: fundef/pupnp
 /**
  * Constructor - preparing Service
  *
  * @access public
  *
  * @param Device   $device
  * @param string   $service
  */
 public function __construct(Device $device, $service)
 {
     Logger::debug(__METHOD__ . '; Device: ' . $device->getId() . ' [' . $device->getName() . ']; Service: ' . $service, self::$logfile);
     $this->device = $device;
     $services = $this->device->services;
     if (!isset($services[$service])) {
         throw new UPnPException('Unknown service: ' . $service);
     }
     $this->service = $services[$service];
 }
示例#2
0
文件: event.php 项目: jdegraef/pupnp
                if ($instance->hasChildNodes()) {
                    foreach ($instance->childNodes as $cn) {
                        if ($cn->localName == 'TransportState' && $cn->hasAttributes()) {
                            foreach ($cn->attributes as $attr) {
                                if ($attr->localName == 'val') {
                                    $transportState = $attr->textContent;
                                }
                            }
                        }
                    }
                }
                if ($transportState != null) {
                    if (isset($headers['SID'])) {
                        $sid = $headers['SID'];
                        file_put_contents('/tmp/tmp.log', $sid . "\n", FILE_APPEND);
                        $subscriptions = Device::getAllSubscriptions();
                        $device = null;
                        foreach ($subscriptions as $deviceId => $ids) {
                            foreach ($ids as $id) {
                                if ($id == $sid) {
                                    $device = UPnP::getDevice($deviceId);
                                    $device->receivedEvent($transportState);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
示例#3
0
文件: UPnP.php 项目: jdegraef/pupnp
 /**
  * Find devices by UPnP multicast message and stores them to cache
  * 
  * @static
  * @access public
  *
  * @return array     Parsed device list
  */
 public static function findDevices()
 {
     $discover = self::discover();
     $cache = array();
     flush();
     foreach ($discover as $response) {
         $device = new Device();
         if ($device->initByDiscoveryReponse($response)) {
             $device->saveToCache();
             try {
                 $client = $device->getClient('ConnectionManager');
                 $protocolInfo = $client->call('GetProtocolInfo');
                 $sink = $protocolInfo['Sink'];
                 $tmp = explode(',', $sink);
                 $protocols = array();
                 foreach ($tmp as $protocol) {
                     $t = explode(':', $protocol);
                     if ($t[0] == 'http-get') {
                         $protocols[] = $t[2];
                     }
                 }
             } catch (UPnPException $upnpe) {
                 $protocols = array();
             }
             $device->protocolInfo = $protocols;
             $cache[$device->getId()] = array('name' => $device->getName(), 'services' => $device->getServices(), 'icons' => $device->getIcons(), 'protocols' => $device->getProtocolInfo());
         }
     }
     self::saveCache($cache);
     flush();
     return $cache;
 }