-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
148 lines (109 loc) · 5.68 KB
/
main.cpp
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
#include <QDebug>
#include <QFile>
#include <QDomDocument>
#include <QStringList>
#include "CInterfaceGenerator.hpp"
static const bool skipDeprecatedEntries = true;
static const QLatin1String s_deprecatedElement = QLatin1String("tp:deprecated");
void processSpec(const QString &fileName)
{
QFile xmlFile(fileName);
if (!xmlFile.open(QIODevice::ReadOnly)) {
qCritical() << "Could not open file" << fileName;
return;
}
QDomDocument document;
document.setContent(xmlFile.readAll());
xmlFile.close();
const QDomElement interfaceElement = document.documentElement().firstChildElement(QLatin1String("interface"));
QString interfaceName = interfaceElement.attribute(QLatin1String("name"));
CInterfaceGenerator generator;
generator.setFullName(interfaceName);
if (!generator.isValid()) {
qCritical() << "File doesn't contain telepathy spec in known format (Error 1)";
return;
}
generator.setNode(document.documentElement().attribute(QLatin1String("name")));
const QDomElement annotationElement = interfaceElement.firstChildElement(QLatin1String("annotation"));
if (!annotationElement.isNull()) {
const QString annotationName = annotationElement.attribute(QLatin1String("name"));
if (annotationName == QLatin1String("org.freedesktop.DBus.Property.EmitsChangedSignal")) {
generator.setEmitPropertiesChangedSignal(true);
}
}
QDomElement propertyElement = interfaceElement.firstChildElement(QLatin1String("property"));
while (!propertyElement.isNull()) {
if (!skipDeprecatedEntries || propertyElement.firstChildElement(s_deprecatedElement).isNull()) {
// Element is *not* deprecated.
CInterfaceProperty *property = new CInterfaceProperty();
property->setName(propertyElement.attribute(QLatin1String("name")));
property->setTypeFromStr(propertyElement.attribute(QLatin1String("type")), propertyElement.attribute(QLatin1String("tp:type")));
property->setImmutable(propertyElement.attribute(QLatin1String("tp:immutable")) == QLatin1String("yes"));
QDomElement docString = propertyElement.firstChildElement(QLatin1String("tp:docstring"));
if (!docString.isNull()) {
QDomNodeList children = docString.childNodes();
for (int i = 0; i < children.count(); ++i) {
if (children.at(i).toElement().text() == QLatin1String("This property cannot change during the lifetime of the channel.")) {
property->setUnchangeable(true);
break;
}
}
}
generator.m_properties.append(property);
}
propertyElement = propertyElement.nextSiblingElement(QLatin1String("property"));
}
QDomElement methodElement = interfaceElement.firstChildElement(QLatin1String("method"));
while (!methodElement.isNull()) {
if (!skipDeprecatedEntries || methodElement.firstChildElement(s_deprecatedElement).isNull()) {
// Element is *not* deprecated.
CInterfaceMethod *method = new CInterfaceMethod(methodElement.attribute(QLatin1String("name")));
QDomElement argElement = methodElement.firstChildElement(QLatin1String("arg"));
while (!argElement.isNull()) {
CMethodArgument arg;
arg.setName(argElement.attribute(QLatin1String("name")));
arg.setTypeFromStr(argElement.attribute(QLatin1String("type")), argElement.attribute(QLatin1String("tp:type")));
arg.setDirection(argElement.attribute(QLatin1String("direction")));
method->arguments.append(arg);
argElement = argElement.nextSiblingElement(QLatin1String("arg"));
}
generator.m_methods.append(method);
}
methodElement = methodElement.nextSiblingElement(QLatin1String("method"));
}
QDomElement signalElement = interfaceElement.firstChildElement(QLatin1String("signal"));
while (!signalElement.isNull()) {
if (!skipDeprecatedEntries || signalElement.firstChildElement(s_deprecatedElement).isNull()) {
// Element is *not* deprecated.
CInterfaceSignal *signal = new CInterfaceSignal(signalElement.attribute(QLatin1String("name")));
QDomElement argElement = signalElement.firstChildElement(QLatin1String("arg"));
while (!argElement.isNull()) {
CMethodArgument arg;
arg.setName(argElement.attribute(QLatin1String("name")));
arg.setTypeFromStr(argElement.attribute(QLatin1String("type")), argElement.attribute(QLatin1String("tp:type")));
arg.setDirection(QLatin1String("in"));
signal->arguments.append(arg);
argElement = argElement.nextSiblingElement(QLatin1String("arg"));
}
generator.m_signals.append(signal);
}
signalElement = signalElement.nextSiblingElement(QLatin1String("signal"));
}
generator.prepare();
printf("Generated code for %s spec\n\n", fileName.toLocal8Bit().constData());
printf("--- Public header: ---\n");
printf("%s", generator.generateHeaderInterface().toLocal8Bit().constData());
printf("--- Private (internal) header: ---\n");
printf("%s", generator.generateHeaderAdaptee().toLocal8Bit().constData());
printf("--- Source file: ---\n");
printf("%s", generator.generateImplementations().toLocal8Bit().constData());
}
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: %s <specs file>\n", argv[0]);
return 0;
}
processSpec(QString::fromLocal8Bit(argv[1]));
return 0;
}