aboutsummaryrefslogtreecommitdiff
path: root/Src/devices/deviceSupportedCommand.cpp
blob: b5e09147147b36c5a8126fc33bdbfcf43ff22a72 (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
#include "main.h"
#include "./deviceSupportedCommand.h"

DeviceSupportedCommand::DeviceSupportedCommand() 
	: ref(1), name(NULL), flags(DeviceCommandFlag_None)
{
}

DeviceSupportedCommand::~DeviceSupportedCommand()
{
	AnsiString_Free(name);
}

HRESULT DeviceSupportedCommand::CreateInstance(const char *name, DeviceSupportedCommand **instance)
{
	DeviceSupportedCommand *self;

	if (NULL == instance) 
		return E_POINTER;

	*instance = NULL;
	
	self = new DeviceSupportedCommand();
	if (NULL == self) 
		return E_OUTOFMEMORY;

	self->name = AnsiString_Duplicate(name);
		
	*instance = self;
	return S_OK;
}

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

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

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

	if (NULL == *object)
		return E_UNEXPECTED;

	AddRef();
	return S_OK;
}

const char *DeviceSupportedCommand::GetName()
{
	return name;
}

HRESULT DeviceSupportedCommand::GetFlags(DeviceCommandFlags *flagsOut)
{
	if (NULL == flagsOut)
		return E_POINTER;
	
	*flagsOut = flags;
	
	return S_OK;
}

HRESULT DeviceSupportedCommand::SetFlags(DeviceCommandFlags mask, DeviceCommandFlags value)
{
	DeviceCommandFlags temp;
	temp = (flags & mask) | (mask & value);

	if (temp == flags)
		return S_FALSE;

	flags = temp;
	
	return S_OK;
}

HRESULT DeviceSupportedCommand::Clone(DeviceSupportedCommand **instance)
{
	HRESULT hr;
	
	hr = DeviceSupportedCommand::CreateInstance(name, instance);
	if (SUCCEEDED(hr))
	{
		(*instance)->flags = flags;
	}

	return hr;
	
}

#define CBCLASS DeviceSupportedCommand
START_DISPATCH;
CB(ADDREF, AddRef)
CB(RELEASE, Release)
CB(QUERYINTERFACE, QueryInterface)
CB(API_GETNAME, GetName)
CB(API_GETFLAGS, GetFlags)
END_DISPATCH;
#undef CBCLASS