KWayland

generator.h
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #ifndef KWAYLAND_TOOLS_GENERATOR_H
7 #define KWAYLAND_TOOLS_GENERATOR_H
8 
9 #include <QObject>
10 #include <QMap>
11 #include <QMutex>
12 #include <QThreadStorage>
13 #include <QWaitCondition>
14 #include <QXmlStreamReader>
15 
16 class QTextStream;
17 
18 namespace KWayland
19 {
20 namespace Tools
21 {
22 
23 class Argument
24 {
25 public:
26  explicit Argument();
27  explicit Argument(const QXmlStreamAttributes &attributes);
28  ~Argument();
29 
30  enum class Type {
31  Unknown,
32  NewId,
33  Destructor,
34  Object,
35  FileDescriptor,
36  Fixed,
37  Uint,
38  Int,
39  String
40  };
41 
42  QString name() const {
43  return m_name;
44  }
45  Type type() const {
46  return m_type;
47  }
48  bool isNullAllowed() const {
49  return m_allowNull;
50  }
51  QString interface() const {
52  return m_inteface;
53  }
54  QString typeAsQt() const;
55  QString typeAsServerWl() const;
56 
57 private:
58  Type parseType(const QStringRef &type);
59  QString m_name;
60  Type m_type = Type::Unknown;
61  bool m_allowNull = false;
62  QString m_inteface;
63 };
64 
65 class Request
66 {
67 public:
68  explicit Request();
69  explicit Request(const QString &name);
70  ~Request();
71 
72  void addArgument(const Argument &arg) {
73  m_arguments << arg;
74  }
75 
76  QString name() const {
77  return m_name;
78  }
79 
80  QVector<Argument> arguments() const {
81  return m_arguments;
82  }
83 
84  bool isDestructor() const {
85  return m_destructor;
86  }
87  bool isFactory() const;
88 
89  void markAsDestructor() {
90  m_destructor = true;
91  }
92 
93 private:
94  QString m_name;
95  QVector<Argument> m_arguments;
96  bool m_destructor = false;
97 };
98 
99 class Event
100 {
101 public:
102  explicit Event();
103  explicit Event(const QString &name);
104  ~Event();
105 
106  void addArgument(const Argument &arg) {
107  m_arguments << arg;
108  }
109 
110  QString name() const {
111  return m_name;
112  }
113 
114  QVector<Argument> arguments() const {
115  return m_arguments;
116  }
117 
118 private:
119  QString m_name;
120  QVector<Argument> m_arguments;
121 };
122 
123 class Interface
124 {
125 public:
126  explicit Interface();
127  explicit Interface(const QXmlStreamAttributes &attributes);
128  virtual ~Interface();
129 
130  void addRequest(const Request &request) {
131  m_requests << request;
132  }
133  void addEvent(const Event &event) {
134  m_events << event;
135  }
136 
137  QString name() const {
138  return m_name;
139  }
140  quint32 version() const {
141  return m_version;
142  }
143  QString kwaylandClientName() const {
144  return m_clientName;
145  }
146  QString kwaylandServerName() const {
147  return m_clientName + QStringLiteral("Interface");
148  }
149 
150  QVector<Request> requests() const {
151  return m_requests;
152  }
153 
154  QVector<Event> events() const {
155  return m_events;
156  }
157 
158  void markAsGlobal() {
159  m_global = true;
160  }
161  bool isGlobal() const {
162  return m_global;
163  }
164  void setFactory(Interface *factory) {
165  m_factory = factory;
166  }
167  Interface *factory() const {
168  return m_factory;
169  }
170 
171  bool isUnstableInterface() const {
172  return m_name.startsWith(QLatin1String("zwp"));
173  }
174 
175 private:
176  QString m_name;
177  QString m_clientName;
178  quint32 m_version;
179  QVector<Request> m_requests;
180  QVector<Event> m_events;
181  bool m_global = false;
182  Interface *m_factory;
183 };
184 
185 
186 class Generator : public QObject
187 {
188  Q_OBJECT
189 public:
190  explicit Generator(QObject *parent = nullptr);
191  virtual ~Generator();
192 
193  void setXmlFileName(const QString &name) {
194  m_xmlFileName = name;
195  }
196  void setBaseFileName(const QString &name) {
197  m_baseFileName = name;
198  }
199  void start();
200 
201 private:
202  void generateCopyrightHeader();
203  void generateStartIncludeGuard();
204  void generateEndIncludeGuard();
205  void generateStartNamespace();
206  void generateEndNamespace();
207  void generateHeaderIncludes();
208  void generateCppIncludes();
209  void generatePrivateClass(const Interface &interface);
210  void generateClientPrivateClass(const Interface &interface);
211  void generateClientPrivateResourceClass(const Interface &interface);
212  void generateClientPrivateGlobalClass(const Interface &interface);
213  void generateServerPrivateGlobalClass(const Interface &interface);
214  void generateServerPrivateResourceClass(const Interface &interface);
215  void generateServerPrivateInterfaceClass(const Interface &interface);
216  void generateServerPrivateGlobalCtorBindClass(const Interface &interface);
217  void generateServerPrivateResourceCtorDtorClass(const Interface &interface);
218  void generateServerPrivateCallbackDefinitions(const Interface &interface);
219  void generateServerPrivateCallbackImpl(const Interface &interface);
220  void generateClientCpp(const Interface &interface);
221  void generateClass(const Interface &interface);
222  void generateClientGlobalClass(const Interface &interface);
223  void generateClientResourceClass(const Interface &interface);
224  void generateServerGlobalClass(const Interface &interface);
225  void generateServerGlobalClassUnstable(const Interface &interface);
226  void generateServerResourceClass(const Interface &interface);
227  void generateServerResourceClassUnstable(const Interface &interface);
228  void generateClientClassQObjectDerived(const Interface &interface);
229  void generateClientGlobalClassDoxy(const Interface &interface);
230  void generateClientGlobalClassCtor(const Interface &interface);
231  void generateClientGlobalClassSetup(const Interface &interface);
232  void generateClientResourceClassSetup(const Interface &interface);
233  void generateClientClassDtor(const Interface &interface);
234  void generateClientClassReleaseDestroy(const Interface &interface);
235  void generateClientClassStart(const Interface &interface);
236  void generateClientClassCasts(const Interface &interface);
237  void generateClientClassSignals(const Interface &interface);
238  void generateClientClassDptr(const Interface &interface);
239  void generateClientGlobalClassEnd(const Interface &interface);
240  void generateClientResourceClassEnd(const Interface &interface);
241  void generateClientClassRequests(const Interface &interface);
242  void generateClientCppRequests(const Interface &interface);
243  void generateWaylandForwardDeclarations();
244  void generateNamespaceForwardDeclarations();
245  void startParseXml();
246  void startAuthorNameProcess();
247  void startAuthorEmailProcess();
248  void startGenerateHeaderFile();
249  void startGenerateCppFile();
250  void startGenerateServerHeaderFile();
251  void startGenerateServerCppFile();
252 
253  void checkEnd();
254 
255  void parseProtocol();
256  Interface parseInterface();
257  Request parseRequest();
258  Event parseEvent();
259 
260  QString projectToName() const;
261 
263  QString m_xmlFileName;
264  enum class Project {
265  Client,
266  Server
267  };
268  QThreadStorage<Project> m_project;
269  QString m_authorName;
270  QString m_authorEmail;
271  QString m_baseFileName;
272 
273  QMutex m_mutex;
274  QWaitCondition m_waitCondition;
275  QXmlStreamReader m_xmlReader;
276  QVector<Interface> m_interfaces;
277 
278  int m_finishedCounter = 0;
279 };
280 
281 }
282 }
283 
284 #endif
Type type(const QSqlDatabase &db)
KDB_EXPORT KDbVersionInfo version()
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.