aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_devices/deviceHandler.cpp
blob: 7140f6627972812c41a3f94dba58f8ff4914e267 (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include "main.h"
#include "./deviceHandler.h"

DeviceHandler::DeviceHandler() 
	: ref(1), relayWindow(NULL)
{
}

DeviceHandler::~DeviceHandler()
{
}

HRESULT DeviceHandler::CreateInstance(DeviceHandler **instance)
{
	if (NULL == instance) 
		return E_POINTER;

	*instance = new DeviceHandler();

	if (NULL == *instance) 
		return E_OUTOFMEMORY;

	return S_OK;
}

size_t DeviceHandler::AddRef()
{
	return InterlockedIncrement((LONG*)&ref);
}

size_t DeviceHandler::Release()
{
	if (0 == ref)
		return ref;
	
	LONG r = InterlockedDecrement((LONG*)&ref);
	if (0 == r)
		delete(this);
	
	return r;
}

int DeviceHandler::QueryInterface(GUID interface_guid, void **object)
{
	if (NULL == object) return E_POINTER;
	
	if (IsEqualIID(interface_guid, IFC_DeviceEvent))
		*object = static_cast<ifc_deviceevent*>(this);
	else
	{
		*object = NULL;
		return E_NOINTERFACE;
	}

	if (NULL == *object)
		return E_UNEXPECTED;

	AddRef();
	return S_OK;
}


void DeviceHandler::IconChanged(ifc_device *device)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceIconChanged);
}

void DeviceHandler::DisplayNameChanged(ifc_device *device, const wchar_t *displayName)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceDisplayNameChanged);
}

void DeviceHandler::AttachmentChanged(ifc_device *device, BOOL attached)
{
	if (NULL != relayWindow)
	{
		if (FALSE != attached)
		{
			EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceAttached);
		}
		else
		{
			EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceDetached);
		}
	}
}

void DeviceHandler::VisibilityChanged(ifc_device *device, BOOL visible)
{
	if (NULL != relayWindow)
	{
		if (FALSE == visible)
		{
			EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceHidden);
		}
		else
		{
			EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceShown);
		}
	}
}

void DeviceHandler::TotalSpaceChanged(ifc_device *device, size_t space)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceTotalSpaceChanged);
}

void DeviceHandler::UsedSpaceChanged(ifc_device *device, size_t space)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceUsedSpaceChanged);
}

void DeviceHandler::CommandChanged(ifc_device *device)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceCommandChanged);
}


void DeviceHandler::ActivityStarted(ifc_device *device, ifc_deviceactivity *activity)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceActivityStarted);
}

void DeviceHandler::ActivityFinished(ifc_device *device, ifc_deviceactivity *activity)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceActivityFinished);
}

void DeviceHandler::ActivityChanged(ifc_device *device, ifc_deviceactivity *activity)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceActivityChanged);
}

void DeviceHandler::ModelChanged(ifc_device *device, const wchar_t *model)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceModelChanged);
}

void DeviceHandler::StatusChanged(ifc_device *device, const wchar_t *status)
{
	if (NULL != relayWindow)
		EVENTRELAY_NOTIFY_DEVICE(relayWindow, device, Event_DeviceStatusChanged);
}

HRESULT DeviceHandler::SetRelayWindow(HWND hwnd)
{
	relayWindow = hwnd;
	return S_OK;
}

HRESULT DeviceHandler::Advise(ifc_device *device)
{
	HRESULT hr;

	if (NULL == device)
		return E_INVALIDARG;

	hr = device->Advise(this);
	if (FAILED(hr))
		return hr;
	
	return hr;
}

HRESULT DeviceHandler::Unadvise(ifc_device *device)
{
	HRESULT hr;

	if (NULL == device)
		return E_INVALIDARG;

	hr = device->Unadvise(this);
	if (FAILED(hr))
		return hr;

	return hr;
}

#define CBCLASS DeviceHandler
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
VCB(API_ICONCHANGED, IconChanged)
VCB(API_DISPLAYNAMECHANGED, DisplayNameChanged)
VCB(API_ATTACHMENTCHANGED, AttachmentChanged)
VCB(API_VISIBILITYCHANGED, VisibilityChanged)
VCB(API_TOTALSPACECHANGED, TotalSpaceChanged)
VCB(API_USEDSPACECHANGED, UsedSpaceChanged)
VCB(API_COMMANDCHANGED, CommandChanged)
VCB(API_ACTIVITYSTARTED, ActivityStarted)
VCB(API_ACTIVITYFINISHED, ActivityFinished)
VCB(API_ACTIVITYCHANGED, ActivityChanged)
VCB(API_MODELCHANGED, ModelChanged)
VCB(API_STATUSCHANGED, StatusChanged)
END_DISPATCH;
#undef CBCLASS