Debian Codegraph @

src/win/NdisEvents.cpp

raw symbols SCIP
1 /*
2 Copyright 2009 Last.fm Ltd.
3 - Primarily authored by Max Howell, Jono Cole and Doug Mansell
4
5 This file is part of liblastfm.
6
7 liblastfm is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 liblastfm is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #include "NdisEvents.h"
21 #include "WmiSink.h"
22
23 // see http://msdn.microsoft.com/en-us/magazine/cc301850.aspx for
24 // more about Ndis and wmi and getting these events
25
26 // Link to wbemuuid.lib to resolve IWbemObjectSink and IWbemClassObject
27 // interface definitions.
28
29 NdisEvents::NdisEvents()
30 : m_pSink(0)
31 {}
32
33 NdisEvents::~NdisEvents()
34 {
35 if (m_pSink)
36 m_pSink->disconnect();
37 if (m_pServices && m_pSink)
38 m_pServices->CancelAsyncCall(m_pSink);
39 // and reference counting will take care of the WmiSink object
40 }
41
42 HRESULT
43 NdisEvents::registerForNdisEvents()
44 {
45 HRESULT hr = m_pLocator.CoCreateInstance(CLSID_WbemLocator);
46 if (FAILED(hr))
47 return hr;
48
49 // Connect to the root\wmi namespace with the current user.
50 hr = m_pLocator->ConnectServer(CComBSTR("ROOT\\WMI"), // strNetworkResource
51 NULL, // strUser
52 NULL, // strPassword
53 NULL, // strLocale
54 0, // lSecurityFlags
55 CComBSTR(""), // strAuthority
56 NULL, // pCtx
57 &m_pServices
58 );
59 if (FAILED(hr))
60 return hr;
61
62 m_pSink = new WmiSink(this);
63
64 //////////////////////////
65
66 // other notifications we're not interested in right now include...
67 // MSNdis_NotifyAdapterArrival \DEVICE\<guid>
68 // MSNdis_NotifyAdapterRemoval
69 // MSNdis_StatusLinkSpeedChange
70 // MSNdis_NotifyVcArrival
71 // MSNdis_NotifyVcRemoval
72 // MSNdis_StatusResetStart
73 // MSNdis_StatusResetEnd
74 // MSNdis_StatusProtocolBind
75 // MSNdis_StatusProtocolUnbind
76 // MSNdis_StatusMediaSpecificIndication
77
78 CComBSTR wql("WQL");
79 CComBSTR query("SELECT * FROM MSNdis_StatusMediaDisconnect");
80 hr = m_pServices->ExecNotificationQueryAsync(wql, query, 0, 0, m_pSink);
81
82 query = "SELECT * FROM MSNdis_StatusMediaConnect";
83 hr = m_pServices->ExecNotificationQueryAsync(wql, query, 0, 0, m_pSink);
84
85 return S_OK;
86 }
87