SOL9 2.0 Class: UPnPDeviceFinder

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * UPnPDeviceFinder.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9
// 2009/12/02

#pragma once

#include <sol/upnp/UPnPObject.h>
#include <sol/upnp/UPnPDevices.h>

namespace SOL {

class UPnPDeviceFinder :public UPnPObject {


public:
    /**
     * Constructor
     */
    UPnPDeviceFinder()
    :UPnPObject(NULL) 
    {
        IUPnPDeviceFinder *pDeviceFinder = NULL;

        HRESULT  hr = CoCreateInstance(CLSID_UPnPDeviceFinder, 
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      IID_IUPnPDeviceFinder,
                      (void **) &pDeviceFinder);
    
        if (FAILED(hr)) {
            throw hr;
        } else {
            set(pDeviceFinder);
        }
    }

public:
    /**
     * Destructor
     */
    ~UPnPDeviceFinder()
    {
    }

public:
    IUPnPDeviceFinder *get()
    {
        return (IUPnPDeviceFinder*)getIDispatch();
    }
    
public:
    /**
     * Find a set of devices specified by typeURI, and return it to foundDevices.
     */
    IUPnPDevices* find(__in const wchar_t* typeURI) 
    {
        IUPnPDevices* pFoundDevices = NULL;
        HRESULT hr = E_FAIL;
        if (FAILED(hr = find(typeURI, &pFoundDevices))) {
        
            throw hr;
        }
        return pFoundDevices;
     }

public:
    /**
     * Find a set of devices specified by typeURI, and return it to foundDevices.
     */
    HRESULT find(__in const wchar_t* typeURI, __out UPnPDevices& foundDevices) 
    {
        IUPnPDevices* pFoundDevices = NULL;
        HRESULT hr = find(typeURI, &pFoundDevices);
        if (SUCCEEDED(hr)) {
            foundDevices.set(pFoundDevices);
        }
        return hr;
     }


public:
    /**
     * Call IUPnPDeviceFinder::FindByType
     */
    HRESULT find(__in const wchar_t* typeURI, __out IUPnPDevices** ppFoundDevices) 
    {
        HRESULT hr = E_FAIL;
        
        if (typeURI && ppFoundDevices) {    
            BSTR uri = SysAllocString(typeURI);
            *ppFoundDevices = NULL;
            if (uri) {
                IUPnPDeviceFinder *pDeviceFinder = get();
                hr = pDeviceFinder->FindByType(uri, 0, ppFoundDevices);
                SysFreeString(uri);
            }
        }
        return hr;
     }
};

}

Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.