PageRenderTime 162ms CodeModel.GetById 50ms app.highlight 59ms RepoModel.GetById 33ms app.codeStats 1ms

/thirdparty/liblastfm2/src/ws/win/WmiSink.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 202 lines | 68 code | 17 blank | 117 comment | 11 complexity | bf459195f8aa1b279d1e42d3693fffad MD5 | raw file
  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 "WmiSink.h"
 21#include "NdisEvents.h"
 22
 23
 24WmiSink::WmiSink(NdisEvents *callback) 
 25    : m_cRef(1)
 26    , m_callback(callback)
 27{}
 28
 29WmiSink::~WmiSink() 
 30{}
 31
 32void
 33WmiSink::disconnect()
 34{
 35    m_callback = 0;
 36}
 37
 38STDMETHODIMP
 39WmiSink::QueryInterface(REFIID riid, LPVOID * ppv)
 40{
 41    *ppv = 0;
 42
 43    if (IID_IUnknown==riid || IID_IWbemObjectSink == riid)
 44    {
 45        *ppv = (IWbemObjectSink *) this;
 46        AddRef();
 47        return NOERROR;
 48    }
 49
 50    return E_NOINTERFACE;
 51}
 52
 53
 54ULONG
 55WmiSink::AddRef()
 56{
 57    return ++m_cRef;
 58}
 59
 60ULONG
 61WmiSink::Release()
 62{
 63    if (0 != --m_cRef)
 64        return m_cRef;
 65
 66    delete this;
 67    return 0;
 68}
 69
 70// This method receives notification objects.
 71HRESULT 
 72WmiSink::Indicate(long lObjectCount, IWbemClassObject** ppObjArray)
 73{
 74    // For each object in the array, extract the object and display the
 75    // information in the object.
 76    for (long i=0; i<lObjectCount; i++)
 77    {
 78        CComVariant vt, vtClass;
 79        ppObjArray[i]->Get(L"InstanceName", 0, &vt, NULL, NULL);
 80        ppObjArray[i]->Get(L"__Class", 0, &vtClass, NULL, NULL);
 81
 82        if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusMediaDisconnect"))
 83        {
 84            if (m_callback) m_callback->onConnectionDown(vt.bstrVal);
 85        }
 86        else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusMediaConnect"))
 87        {
 88            if (m_callback) m_callback->onConnectionUp(vt.bstrVal);
 89        }
 90        // notifications we aren't interested in right now:
 91        //
 92        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_NotifyAdapterRemoval"))
 93        //{
 94        //    bstrLog = (_bstr_t) vt.bstrVal;
 95        //    VariantClear (&vt);
 96        //    ppObjArray[i]->Get (L"DeviceName", 0, &vt, NULL, NULL);
 97        //    bstrLog += (_bstr_t) _T(": ") + (_bstr_t) vt.bstrVal + (_bstr_t) _T(" has been removed");
 98        //    displayDlg.LogEvent (bstrLog);
 99        //}
100        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_NotifyAdapterArrival"))
101        //{
102        //    bstrLog = (_bstr_t) vt.bstrVal;
103        //    VariantClear (&vt);
104        //    ppObjArray[i]->Get(L"DeviceName", 0, &vt, NULL, NULL);
105        //    bstrLog += (_bstr_t) _T(": ") + (_bstr_t) vt.bstrVal + (_bstr_t) _T(" has been added");
106        //    displayDlg.LogEvent (bstrLog);
107        //}
108        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusResetStart"))
109        //{
110        //    bstrLog = (_bstr_t) vt.bstrVal + (_bstr_t) _T(" has begun a reset");
111        //    displayDlg.LogEvent (bstrLog);
112        //}
113        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusResetEnd"))
114        //{
115        //    bstrLog = (_bstr_t) vt.bstrVal + (_bstr_t) _T(" has finished a reset");
116        //    displayDlg.LogEvent (bstrLog);
117        //}
118        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_NotifyVcArrival"))
119        //{
120        //    bstrLog = (_bstr_t) _T("VC arrival: ") + (_bstr_t) vt.bstrVal;
121        //    displayDlg.LogEvent (bstrLog);
122        //}
123        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_NotifyVcRemoval"))
124        //{
125        //    bstrLog = (_bstr_t) _T("VC removal: ") + (_bstr_t) vt.bstrVal;
126        //    displayDlg.LogEvent (bstrLog);
127        //}
128        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusMediaSpecificIndication"))
129        //{
130        //    ATLTRACE (_T("Media specific indication: %s\n"), (TCHAR *) (_bstr_t) vt.bstrVal);
131        //    VariantClear (&vt);
132        //    ppObjArray[i]->Get (L"NdisStatusMediaSpecificIndication", 0, &vt, NULL, NULL);
133        //    LONG lLowerBound, lUpperBound, j;
134        //    UCHAR ch;
135        //    SafeArrayGetLBound (V_ARRAY (&vt), 1, &lLowerBound);
136        //    SafeArrayGetUBound (V_ARRAY (&vt), 1, &lUpperBound);
137        //    ATLTRACE (" ");
138        //    for (j = lLowerBound; j<= lUpperBound; j++ )
139        //    {
140        //        SafeArrayGetElement (V_ARRAY (&vt), &j, &ch);
141        //        ATLTRACE (_T("%4i"), ch);
142
143        //        if (((j - lLowerBound) % 8 == 7) && (j <= lUpperBound))
144        //            ATLTRACE (_T("\n"));         
145        //    }                          
146        //}
147        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusProtocolBind"))
148        //{
149        //    bstrLog = (_bstr_t) vt.bstrVal;
150        //    VariantClear (&vt);
151        //    ppObjArray[i]->Get (L"Transport", 0, &vt, NULL, NULL);
152        //    bstrLog += (_bstr_t) _T(" is now bound to ") + (_bstr_t) vt.bstrVal;
153        //    displayDlg.LogEvent (bstrLog);
154        //}
155        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusProtocolBind"))
156        //{
157        //    bstrLog = (_bstr_t) vt.bstrVal;
158        //    VariantClear (&vt);
159        //    ppObjArray[i]->Get(L"Transport", 0, &vt, NULL, NULL);
160        //    bstrLog += (_bstr_t) _T(" was unbound from ") + (_bstr_t) vt.bstrVal;
161        //    displayDlg.LogEvent (bstrLog);
162        //}
163        //else if (!wcscmp (vtClass.bstrVal, L"MSNdis_StatusLinkSpeedChange"))
164        //{
165        //    IWbemClassObject* pWMIObj=NULL;
166        //    bstrLog = (_bstr_t) _T("Link speed change ") + (_bstr_t) vt.bstrVal;
167        //    VariantClear (&vt);
168        //    ppObjArray[i]->Get (L"NdisStatusLinkSpeedChange", 0, &vt, NULL, NULL);
169        //    if SUCCEEDED (vt.punkVal->QueryInterface (IID_IWbemClassObject, (void**)&pWMIObj))
170        //    {
171        //        TCHAR szNum[50];
172        //        pWMIObj->Get (L"Inbound", 0, &vt2, NULL, NULL);
173        //        _stprintf (szNum, _T(" Inbound = %u "), vt2.lVal);
174        //        bstrLog += (_bstr_t) szNum;
175        //        VariantClear (&vt2);
176        //        pWMIObj->Get (L"Outbound", 0, &vt2, NULL, NULL);
177        //        _stprintf (szNum, _T(" Outbound = %u "), vt2.lVal);
178        //        bstrLog += (_bstr_t) szNum;
179        //        VariantClear (&vt2);
180        //        pWMIObj->Release ();
181        //        pWMIObj = NULL;
182        //    }
183        //    displayDlg.LogEvent (bstrLog);
184        //}
185
186        VariantClear (&vtClass);
187        VariantClear (&vt);
188    }
189    return WBEM_NO_ERROR;
190}
191
192
193// Misc. status codes sent by sink.
194HRESULT 
195WmiSink::SetStatus(long lFlags, HRESULT hResult, BSTR strParam, IWbemClassObject __RPC_FAR *pObjParam)
196{
197    lFlags;
198    hResult;
199    strParam;
200    pObjParam;
201    return WBEM_NO_ERROR;
202}