Пример #1
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::OnDeviceRemoved
+---------------------------------------------------------------------*/
NPT_Result
PLT_SyncMediaBrowser::OnDeviceRemoved(PLT_DeviceDataReference& device)
{
    NPT_String uuid = device->GetUUID();

    // Remove from our list of servers first if found
    {
        NPT_AutoLock lock(m_MediaServers);
        m_MediaServers.Erase(uuid);
    }

    // clear cache for that device
    if (m_UseCache) m_Cache.Clear(device.AsPointer()->GetUUID());
    
    return PLT_MediaBrowser::OnDeviceRemoved(device);
}
Пример #2
0
/*----------------------------------------------------------------------
|   PLT_SyncMediaBrowser::OnMSAddedRemoved
+---------------------------------------------------------------------*/
void
PLT_SyncMediaBrowser::OnMSAddedRemoved(PLT_DeviceDataReference& device, int added)
{
    NPT_String uuid = device->GetUUID();

    if (added) {
        // test if it's a media server
        m_MediaServers.Lock();
        PLT_Service* service;
        if (NPT_SUCCEEDED(device->FindServiceByType("urn:schemas-upnp-org:service:ContentDirectory:1", service))) {
            m_MediaServers.Put(uuid, device);
        }
        m_MediaServers.Unlock();
    } else { /* removed */
        // Remove from our list of servers first if found
        m_MediaServers.Lock();
        m_MediaServers.Erase(uuid);
        m_MediaServers.Unlock();

        // clear cache for that device
        if (m_UseCache) m_Cache.Clear(device.AsPointer()->GetUUID());
    }
}
Пример #3
0
/*----------------------------------------------------------------------
|   PLT_DeviceData::SetDescriptionDevice
+---------------------------------------------------------------------*/
NPT_Result
PLT_DeviceData::SetDescriptionDevice(PLT_DeviceDataReference&      device,
                                     NPT_XmlElementNode*           device_node, 
                                     const NPT_HttpRequestContext& context)
{
    NPT_Result res;
    
    device->m_LocalIfaceIp = context.GetLocalAddress().GetIpAddress();
    
    NPT_CHECK_SEVERE(PLT_XmlHelper::GetChildText(device_node, "deviceType", device->m_DeviceType));
    NPT_CHECK_SEVERE(PLT_XmlHelper::GetChildText(device_node, "UDN", device->m_UUID));

    // remove uuid: prefix
    if (device->m_UUID.StartsWith("uuid:")) {
        device->m_UUID = ((const char*)device->m_UUID)+5;
    }

    // optional attributes
    PLT_XmlHelper::GetChildText(device_node, "friendlyName", device->m_FriendlyName);
    PLT_XmlHelper::GetChildText(device_node, "manufacturer", device->m_Manufacturer);
    PLT_XmlHelper::GetChildText(device_node, "manufacturerURL", device->m_ManufacturerURL);
    PLT_XmlHelper::GetChildText(device_node, "modelDescription", device->m_ModelDescription);
    PLT_XmlHelper::GetChildText(device_node, "modelName", device->m_ModelName);
    PLT_XmlHelper::GetChildText(device_node, "modelURL", device->m_ModelURL);
    PLT_XmlHelper::GetChildText(device_node, "modelNumber", device->m_ModelNumber);
    PLT_XmlHelper::GetChildText(device_node, "serialNumber", device->m_SerialNumber);

    // enumerate icons
    NPT_XmlElementNode* iconList = PLT_XmlHelper::GetChild(device_node, "iconList");
    if (iconList) {
        NPT_Array<NPT_XmlElementNode*> icons;
        PLT_XmlHelper::GetChildren(iconList, icons, "icon");

        for (NPT_Cardinal k=0 ; k<icons.GetItemCount(); k++) {
            PLT_DeviceIcon icon;
            NPT_String integer, height, depth;

            PLT_XmlHelper::GetChildText(icons[k], "mimetype", icon.m_MimeType);
            PLT_XmlHelper::GetChildText(icons[k], "url", icon.m_UrlPath);

            if(NPT_SUCCEEDED(PLT_XmlHelper::GetChildText(icons[k], "width", integer)))
                NPT_ParseInteger32(integer, icon.m_Width);
            if(NPT_SUCCEEDED(PLT_XmlHelper::GetChildText(icons[k], "height", integer)))
                NPT_ParseInteger32(integer, icon.m_Height);
            if(NPT_SUCCEEDED(PLT_XmlHelper::GetChildText(icons[k], "depth", integer)))
                NPT_ParseInteger32(integer, icon.m_Depth);

            device->m_Icons.Add(icon);
        }
    }

    // enumerate device services
    NPT_XmlElementNode* serviceList = PLT_XmlHelper::GetChild(device_node, "serviceList");
    if (serviceList) {
        NPT_Array<NPT_XmlElementNode*> services;
        PLT_XmlHelper::GetChildren(serviceList, services, "service");
        for( int k = 0 ; k < (int)services.GetItemCount(); k++) {
            NPT_String type, id, url;
            PLT_XmlHelper::GetChildText(services[k], "serviceType", type);
            PLT_XmlHelper::GetChildText(services[k], "serviceId", id);    
            PLT_Service* service = new PLT_Service(device.AsPointer(), type, id, NULL);
            
            PLT_XmlHelper::GetChildText(services[k], "SCPDURL", url);
            service->SetSCPDURL(url);
            
            PLT_XmlHelper::GetChildText(services[k], "controlURL", url);
            service->SetControlURL(url);
            
            PLT_XmlHelper::GetChildText(services[k], "eventSubURL", url);
            service->SetEventSubURL(url);
            
            if (NPT_FAILED(res = device->AddService(service))) {
                delete service;
                return res;
            }
        }
    }

    // enumerate embedded devices
    NPT_XmlElementNode* deviceList = PLT_XmlHelper::GetChild(device_node, "deviceList");
    if (deviceList) {
        NPT_Array<NPT_XmlElementNode*> devices;
        PLT_XmlHelper::GetChildren(deviceList, devices, "device");
        for (int k = 0; k<(int)devices.GetItemCount(); k++) {    
            // create an embedded device with same url base and leasetime as parent
            PLT_DeviceDataReference embedded_device(new PLT_DeviceData(device->m_URLDescription, "", device->m_LeaseTime));
            NPT_CHECK_SEVERE(PLT_DeviceData::SetDescriptionDevice(embedded_device, devices[k], context));
            device->AddEmbeddedDevice(embedded_device);
        }
    }
    
    // TODO: Parse extra DLNA stuff

    return NPT_SUCCESS;
}