예제 #1
0
// Enumerates devices for a particular factory.
Void DeviceManagerImpl::EnumerateFactoryDevices(DeviceFactory* factory)
{
       
    class FactoryEnumerateVisitor : public DeviceFactory::EnumerateVisitor
    {        
        DeviceManagerImpl* pManager;
        DeviceFactory*     pFactory;
    public:
        FactoryEnumerateVisitor(DeviceManagerImpl* manager, DeviceFactory* factory)
            : pManager(manager), pFactory(factory) { }

        virtual void Visit(const DeviceCreateDesc& createDesc)
        {
            DeviceCreateDesc* devDesc;
            
            // If found, mark as enumerated and we are done.
            DeviceCreateDesc* descCandidate = 0;

            for(devDesc = pManager->Devices.GetFirst();
                !pManager->Devices.IsNull(devDesc);  devDesc = devDesc->pNext)
            {
                DeviceCreateDesc::MatchResult mr = devDesc->MatchDevice(createDesc, &descCandidate);
                if (mr == DeviceCreateDesc::Match_Found)
                {
                    devDesc->Enumerated = true;
                    return;
                }
            }

            // Update candidate (this may involve writing fields to HMDDevice createDesc).
            if (descCandidate && descCandidate->UpdateMatchedCandidate(createDesc))
            {
                descCandidate->Enumerated = true;
                return;
            }

            // If not found, add new device.
            //  - This stores a new descriptor with
            //    {pDevice = 0, HandleCount = 1, Enumerated = true}
            DeviceCreateDesc* desc = createDesc.Clone();
            desc->pLock = pManager->pCreateDesc->pLock;
            pManager->Devices.PushBack(desc);

            pManager->CallOnDeviceAdded(desc);
        }
    };

    FactoryEnumerateVisitor newDeviceVisitor(this, factory);
    factory->EnumerateDevices(newDeviceVisitor);


    return 0;
}
예제 #2
0
// Enumerates devices for a particular factory.
Void DeviceManagerImpl::EnumerateFactoryDevices(DeviceFactory* factory)
{
       
    class FactoryEnumerateVisitor : public DeviceFactory::EnumerateVisitor
    {        
        DeviceManagerImpl* pManager;
    public:
        FactoryEnumerateVisitor(DeviceManagerImpl* manager)
            : pManager(manager) { }

        virtual void Visit(const DeviceCreateDesc& createDesc)
        {
            pManager->AddDevice_NeedsLock(createDesc);
        }
    };

    FactoryEnumerateVisitor newDeviceVisitor(this);
    factory->EnumerateDevices(newDeviceVisitor);


    return 0;
}