1 #include "stdafx.h"
2 #include "CMMNotificationClient.h"
3 #include "CDevicesManager.h"
4
5
CMMNotificationClient(IMMDeviceEnumerator * _pEnum,CDevicesManager * manager)6 CMMNotificationClient::CMMNotificationClient(IMMDeviceEnumerator* _pEnum, CDevicesManager* manager) :_cRef(1),
7 _pEnum(_pEnum), manager(manager)
8 {
9
10 }
11
~CMMNotificationClient()12 CMMNotificationClient::~CMMNotificationClient()
13 {
14 //SAFE_RELEASE(_pEnum);
15 }
16
AddRef()17 ULONG STDMETHODCALLTYPE CMMNotificationClient::AddRef()
18 {
19 return InterlockedIncrement(&_cRef);
20 }
21
Release()22 ULONG STDMETHODCALLTYPE CMMNotificationClient::Release()
23 {
24 ULONG ulRef = InterlockedDecrement(&_cRef);
25 if (0 == ulRef)
26 {
27 delete this;
28 }
29 return ulRef;
30 }
31
QueryInterface(REFIID riid,VOID ** ppvInterface)32 HRESULT STDMETHODCALLTYPE CMMNotificationClient::QueryInterface(
33 REFIID riid, VOID** ppvInterface)
34 {
35 if (IID_IUnknown == riid)
36 {
37 AddRef();
38 *ppvInterface = (IUnknown*)this;
39 }
40 else if (__uuidof(IMMNotificationClient) == riid)
41 {
42 AddRef();
43 *ppvInterface = (IMMNotificationClient*)this;
44 }
45 else
46 {
47 *ppvInterface = NULL;
48 return E_NOINTERFACE;
49 }
50 return S_OK;
51 }
52
OnDefaultDeviceChanged(EDataFlow flow,ERole role,LPCWSTR pwstrDeviceId)53 HRESULT STDMETHODCALLTYPE CMMNotificationClient::OnDefaultDeviceChanged(
54 EDataFlow flow, ERole role,
55 LPCWSTR pwstrDeviceId)
56 {
57 const char* pszFlow = "?????";
58 const char* pszRole = "?????";
59
60 switch (flow)
61 {
62 case eRender:
63 pszFlow = "eRender";
64 break;
65 case eCapture:
66 pszFlow = "eCapture";
67 break;
68 }
69
70 switch (role)
71 {
72 case eConsole:
73 pszRole = "eConsole";
74 break;
75 case eMultimedia:
76 pszRole = "eMultimedia";
77 break;
78 case eCommunications:
79 pszRole = "eCommunications";
80 break;
81 }
82
83 TRACE(" -->New default device: flow = %s, role = %s\n",
84 pszFlow, pszRole);
85
86 if (flow == eRender && role == eMultimedia)
87 manager->DefaultMultimediaDeviceChanged();
88
89 return S_OK;
90 }
OnDeviceAdded(LPCWSTR pwstrDeviceId)91 HRESULT STDMETHODCALLTYPE CMMNotificationClient::OnDeviceAdded(LPCWSTR pwstrDeviceId)
92 {
93 TRACE(" -->Added device\n");
94 //manager->notifyDeviceAddedListeners(pwstrDeviceId);
95
96 return S_OK;
97 };
98
OnDeviceRemoved(LPCWSTR pwstrDeviceId)99 HRESULT STDMETHODCALLTYPE CMMNotificationClient::OnDeviceRemoved(LPCWSTR pwstrDeviceId)
100 {
101 TRACE(" -->Removed device");
102 //manager->notifyDeviceRemovedListeners(pwstrDeviceId);
103
104 return S_OK;
105 }
OnDeviceStateChanged(LPCWSTR pwstrDeviceId,DWORD dwNewState)106 HRESULT STDMETHODCALLTYPE CMMNotificationClient::OnDeviceStateChanged(
107 LPCWSTR pwstrDeviceId,
108 DWORD dwNewState)
109 {
110 const char* pszState = "?????";
111
112 switch (dwNewState)
113 {
114 case DEVICE_STATE_ACTIVE:
115 pszState = "ACTIVE";
116 //manager->notifyDeviceAddedListeners(pwstrDeviceId);
117 break;
118 case DEVICE_STATE_DISABLED:
119 pszState = "DISABLED";
120 //manager->notifyDeviceRemovedListeners(pwstrDeviceId);
121 break;
122 case DEVICE_STATE_NOTPRESENT:
123 pszState = "NOTPRESENT";
124 //manager->notifyDeviceRemovedListeners(pwstrDeviceId);
125 break;
126 case DEVICE_STATE_UNPLUGGED:
127 pszState = "UNPLUGGED";
128 //manager->notifyDeviceRemovedListeners(pwstrDeviceId);
129 break;
130 }
131
132 TRACE(" -->New device state is DEVICE_STATE_%s (0x%8.8x)\n",
133 pszState, dwNewState);
134
135 return S_OK;
136 }
137
OnPropertyValueChanged(LPCWSTR pwstrDeviceId,const PROPERTYKEY key)138 HRESULT STDMETHODCALLTYPE CMMNotificationClient::OnPropertyValueChanged(
139 LPCWSTR pwstrDeviceId,
140 const PROPERTYKEY key)
141 {
142 //TRACE(" -->Changed device property "
143 // "{%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x}#%d\n",
144 // key.fmtid.Data1, key.fmtid.Data2, key.fmtid.Data3,
145 // key.fmtid.Data4[0], key.fmtid.Data4[1],
146 // key.fmtid.Data4[2], key.fmtid.Data4[3],
147 // key.fmtid.Data4[4], key.fmtid.Data4[5],
148 // key.fmtid.Data4[6], key.fmtid.Data4[7],
149 // key.pid);
150 return S_OK;
151 }