summaryrefslogtreecommitdiff
path: root/wpd/WpdWudfSampleDriver/WpdBaseDriver.h
blob: ee092fd6aedeaca55f958dce75ae49aa4602b09e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#pragma once

// This class is used to store the connected client information.
// This is for demonstration purposes only - this driver does not
// make use of the information.
class ClientContext : public IUnknown
{
public:
    ClientContext() :
        MajorVersion(0),
        MinorVersion(0),
        Revision(0),
        m_cRef(1)
    {
    }

    ~ClientContext()
    {
    }

public: // IUnknown
    ULONG __stdcall AddRef()
    {
        InterlockedIncrement((long*) &m_cRef);
        return m_cRef;
    }

    _At_(this, __drv_freesMem(Mem)) 
    ULONG __stdcall Release()
    {
        ULONG ulRefCount = m_cRef - 1;

        if (InterlockedDecrement((long*) &m_cRef) == 0)
        {
            delete this;
            return 0;
        }
        return ulRefCount;
    }

    HRESULT __stdcall QueryInterface(
        REFIID riid,
        void** ppv)
    {
        HRESULT hr = S_OK;

        if(riid == IID_IUnknown)
        {
            *ppv = static_cast<IUnknown*>(this);
            AddRef();
        }
        else
        {
            *ppv = NULL;
            hr = E_NOINTERFACE;
        }

        return hr;
    }

private:
    DWORD m_cRef;

public:
    CAtlStringW ClientName;
    CAtlStringW EventCookie;
    DWORD       MajorVersion;
    DWORD       MinorVersion;
    DWORD       Revision;
};

class WpdBaseDriver :
    public IUnknown
{
public:
    WpdBaseDriver();
    virtual ~WpdBaseDriver();

    HRESULT Initialize(_In_ LPCWSTR pszPortName, _In_ IPortableDeviceClassExtension* pPortableDeviceClassExtension);
    VOID    Uninitialize();

    HRESULT DispatchWpdMessage(_In_ IPortableDeviceValues* pParams,
                               _In_ IPortableDeviceValues* pResults);

private:
    HRESULT OnSaveClientInfo(_In_ IPortableDeviceValues* pParams,
                             _In_ IPortableDeviceValues* pResults);

    HRESULT OnGetObjectIDsFromPersistentUniqueIDs(_In_ IPortableDeviceValues* pParams,
                                                  _In_ IPortableDeviceValues* pResults);

public: // IUnknown
    ULONG __stdcall AddRef();

    _At_(this, __drv_freesMem(Mem)) 
    ULONG __stdcall Release();

    HRESULT __stdcall QueryInterface(REFIID riid, void** ppv);

private:
    WpdObjectEnumerator                 m_ObjectEnum;
    WpdObjectProperties                 m_ObjectProperties;
    WpdObjectPropertiesBulk             m_ObjectPropertiesBulk;
    WpdObjectResources                  m_ObjectResources;
    WpdObjectManagement                 m_ObjectManagement;
    WpdCapabilities                     m_Capabilities;
    WpdStorage                          m_Storage;
    WpdNetworkConfig                    m_NetworkConfig;
    FakeDevice                          m_FakeDevice;
    CComPtr<IPortableDeviceClassExtension> m_pPortableDeviceClassExtension;
    ULONG m_cRef;
};