-
Notifications
You must be signed in to change notification settings - Fork 0
/
CInterfaceGenerator.hpp
212 lines (160 loc) · 5.62 KB
/
CInterfaceGenerator.hpp
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
207
208
209
210
211
212
#ifndef CINTERFACEGENERATOR_HPP
#define CINTERFACEGENERATOR_HPP
#include <QString>
#include <QList>
class CNameFeature {
public:
CNameFeature() { }
CNameFeature(const QString &newName) { setName(newName); }
QString name() const { return m_name; }
QString nameAsIs() const { return m_nameAsIs; }
QString nameFirstCapital() const;
void setName(const QString &newName);
private:
QString m_name;
QString m_nameAsIs;
};
class CTypeFeature : public CNameFeature {
public:
CTypeFeature() { }
QString type() const { return m_type; }
QString typeForAdaptee() const { return m_typeForAdaptee; }
QString defaultValue() const { return m_defaultValue; }
void setTypeFromStr(const QString &type, const QString &tpType);
bool isPod() const;
QString formatTypeArgument(bool addName) const;
private:
QString supposeType(const QString &type, QString tpType) const;
QString m_type;
QString m_typeForAdaptee;
QString m_defaultValue;
};
class CMethodArgument : public CTypeFeature {
public:
enum Direction {
Input,
Output,
Invalid
};
CMethodArgument() : CTypeFeature(), m_direction(Invalid) { }
Direction direction() const { return m_direction; }
void setDirection(const QString &directionStr);
QString formatArgument(bool addName) const;
private:
Direction m_direction;
};
class CArgumentsFeature
{
public:
QList<CMethodArgument> arguments;
bool isSimple() const;
};
class CInterfaceSignal : public CNameFeature, public CArgumentsFeature {
public:
CInterfaceSignal(const QString &name);
bool isNotifier() const { return m_isNotifier; }
void setNotifierFlag(bool isNotifier);
private:
bool m_isNotifier;
};
class CInterfaceProperty : public CTypeFeature {
public:
CInterfaceProperty() : CTypeFeature(), m_notifier(0), m_immutable(false), m_unchangeable(false) { }
CInterfaceSignal *notifier() const { return m_notifier; }
void setNotifier(CInterfaceSignal *notifier);
bool isImmutable() const { return m_immutable || m_unchangeable; }
bool isUnchangeable() const { return m_unchangeable; }
void setImmutable(bool newImmutable);
void setUnchangeable(bool newUnchangeable);
QString dbusGetter() const;
private:
CInterfaceSignal *m_notifier;
bool m_immutable;
bool m_unchangeable;
};
class CInterfaceMethod : public CNameFeature, public CArgumentsFeature {
public:
CInterfaceMethod(const QString &name);
QString callbackType() const { return nameAsIs() + QLatin1String("Callback"); }
QString callbackMember() const { return name() + QLatin1String("CB"); }
QString callbackRetType() const { return m_callbackRetType; }
QList<uint> outputArgsIndices() const { return m_outputArgsIndices; }
void prepare();
private:
QString m_callbackRetType;
QList<uint> m_outputArgsIndices;
};
class CInterfaceGenerator
{
public:
enum class SpecFormat {
Invalid,
Classic,
V1,
};
enum InterfaceType {
InterfaceTypeInvalid,
InterfaceTypeChannel,
InterfaceTypeConnection,
InterfaceTypeProtocol
};
enum InterfaceSubType {
InterfaceSubTypeInvalid,
InterfaceSubTypeBaseClass,
InterfaceSubTypeType,
InterfaceSubTypeInterface
};
CInterfaceGenerator();
SpecFormat specFormat() const;
bool isValid() const;
QString className() const;
QString parentClassPrefix() const;
QString classPtr() const;
QString interfaceSubclass() const;
QString classBaseType() const;
QString interfaceTypeShort() const;
QString subTypeStr() const;
QString docGroup() const;
QString interfaceTpDefinition() const;
static InterfaceType strToType(const QString &str);
QString interfaceName() const { return m_name; }
void setFullName(const QString &name);
QString shortName() const;
QString fullName() const { return m_fullName; }
QString node() const { return m_node; }
QString nodeName() const { return m_nodeName; }
void setNode(const QString &node);
void setType(const QString &classBaseType);
void setSubType(InterfaceSubType subType);
void setEmitPropertiesChangedSignal(bool enable);
void prepare();
QString generateHeaderInterface() const;
QString generateHeaderAdaptee() const;
QString generateImplementationAdaptee() const;
QString generateImplementationPrivate() const;
QString generateImplementationInterface() const;
QString generateImplementations() const;
QString getServiceAdaptor() const;
QList<CInterfaceSignal*> m_signals;
QList<CInterfaceProperty*> m_properties;
QList<CInterfaceMethod*> m_methods;
private:
QString generateImmutablePropertiesListHelper(const int creatorSpacing, bool names, bool signatures) const;
QString generatePrivateConstructorPropertiesList(const int creatorSpacing) const;
QString generateMethodCallbackAndDeclaration(const CInterfaceMethod *method) const;
QString formatArguments(const CArgumentsFeature *argumentsClass, bool argName, bool hideOutputArguments = false, bool addType = true) const;
QString formatArgument(const CMethodArgument &arg, bool addName) const;
QString formatInvokeMethodArguments(const CArgumentsFeature *argumentsClass) const;
QString m_adapteeParentMember;
InterfaceType m_type;
InterfaceSubType m_subType;
QString m_node;
QString m_nodeName;
QString m_name;
QString m_fullName;
SpecFormat m_specFormat = SpecFormat::Invalid;
int m_mutablePropertiesCount;
int m_immutablePropertiesCount;
bool m_emitPropertiesChangedSignal;
};
#endif // CINTERFACEGENERATOR_HPP