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
|
#include "main.h"
#include "./deviceCommandParser.h"
#include "../../xml/obj_xml.h"
typedef void (*COMMANDTAGCALLBACK)(DeviceCommandParser* /*self*/, ifc_devicecommandeditor* /*editor*/, const wchar_t* /*value*/);
typedef struct COMMANDTAG
{
const wchar_t *name;
BOOL multiEntry;
COMMANDTAGCALLBACK callback;
} COMMANDTAG;
static void
DeviceCommandParser_DisplayNameCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
editor->SetDisplayName(value);
}
static void
DeviceCommandParser_IconCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
ifc_deviceiconstore *iconStore;
if (SUCCEEDED(editor->GetIconStore(&iconStore)))
{
iconStore->Add(value, self->iconSize.cx, self->iconSize.cy, TRUE);
iconStore->Release();
}
}
static void
DeviceCommandParser_DescirptionCb(DeviceCommandParser *self, ifc_devicecommandeditor *editor, const wchar_t *value)
{
editor->SetDescription(value);
}
static const COMMANDTAG knownTags[COMMAND_TAG_MAX] =
{
{L"displayName", FALSE, DeviceCommandParser_DisplayNameCb},
{L"icon", TRUE, DeviceCommandParser_IconCb},
{L"description", FALSE, DeviceCommandParser_DescirptionCb},
};
DeviceCommandParser::DeviceCommandParser()
: editor(NULL)
{
}
DeviceCommandParser::~DeviceCommandParser()
{
if (NULL != editor)
editor->Release();
}
BOOL DeviceCommandParser::Begin(obj_xml *reader, ifc_xmlreaderparams *params)
{
const wchar_t *name;
ifc_devicecommand *command;
char *nameAnsi;
if (NULL != editor)
return FALSE;
if (NULL == reader || NULL == params)
return FALSE;
name = params->getItemValue(L"name");
if (NULL == name)
return FALSE;
nameAnsi = String_ToAnsi(CP_UTF8, 0, name, -1, NULL, NULL);
if (NULL == nameAnsi)
return FALSE;
if (NULL != WASABI_API_DEVICES &&
SUCCEEDED(WASABI_API_DEVICES->CreateCommand(nameAnsi, &command)))
{
if(FAILED(command->QueryInterface(IFC_DeviceCommandEditor, (void**)&editor)))
editor = NULL;
command->Release();
}
AnsiString_Free(nameAnsi);
if (NULL == editor)
return FALSE;
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\fdisplayName", this);
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\fdescription", this);
reader->xmlreader_registerCallback(L"testprovider\fcommands\fcommand\ficon", this);
ZeroMemory(hitList, sizeof(hitList));
return TRUE;
}
BOOL DeviceCommandParser::End(obj_xml *reader, ifc_devicecommand **command)
{
BOOL result;
if (NULL != reader)
reader->xmlreader_unregisterCallback(this);
if (NULL == command)
return FALSE;
if (NULL == editor)
return FALSE;
if (NULL != command)
{
if (FAILED(editor->QueryInterface(IFC_DeviceCommand, (void**)command)))
result = FALSE;
else
result = TRUE;
}
else
result = TRUE;
editor->Release();
editor = NULL;
return result;
}
void DeviceCommandParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
{
elementString.Clear();
if (CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, L"icon", -1, xmltag, -1))
{
const wchar_t *sVal;
int iVal;
sVal = params->getItemValue(L"width");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cx = iVal;
sVal = params->getItemValue(L"height");
if (NULL == sVal ||
FALSE == StrToIntEx(sVal, STIF_DEFAULT, &iVal))
{
iVal = 0;
}
iconSize.cy = iVal;
}
}
void DeviceCommandParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
{
if (NULL == editor)
return;
for (size_t i = 0; i < COMMAND_TAG_MAX; i++)
{
if (FALSE == hitList[i] &&
CSTR_EQUAL == CompareString(CSTR_INVARIANT, NORM_IGNORECASE, knownTags[i].name, -1, xmltag, -1))
{
knownTags[i].callback(this, editor, elementString.Get());
if (FALSE == knownTags[i].multiEntry)
hitList[i] = TRUE;
break;
}
}
}
void DeviceCommandParser::Event_XmlCharData(const wchar_t *xmlpath, const wchar_t *xmltag, const wchar_t *value)
{
elementString.Append(value);
}
void DeviceCommandParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
{
elementString.Clear();
}
#define CBCLASS DeviceCommandParser
START_DISPATCH;
VCB(ONSTARTELEMENT, Event_XmlStartElement)
VCB(ONENDELEMENT, Event_XmlEndElement)
VCB(ONCHARDATA, Event_XmlCharData)
VCB(ONERROR, Event_XmlError)
END_DISPATCH;
#undef CBCLASS
|