Commit a5689b7b authored by Martin Flöser's avatar Martin Flöser

[tools/generator] Generate Private::setup(wl_foo *arg) on client side

Experience showed that most generated classes need a dedicated setup
method in the Private in order to add a listener.
parent 600e7216
......@@ -883,6 +883,15 @@ void Generator::generateServerPrivateResourceCtorDtorClass(const Interface &inte
}
void Generator::generateClientPrivateClass(const Interface &interface)
{
if (interface.isGlobal()) {
generateClientPrivateGlobalClass(interface);
} else {
generateClientPrivateResourceClass(interface);
}
}
void Generator::generateClientPrivateResourceClass(const Interface &interface)
{
const QString templateString = QStringLiteral(
"class %1::Private\n"
......@@ -890,13 +899,29 @@ void Generator::generateClientPrivateClass(const Interface &interface)
"public:\n"
" Private() = default;\n"
"\n"
" WaylandPointer<%2, %2_destroy> %3;\n");
" void setup(%2 *arg);\n"
"\n"
" WaylandPointer<%2, %2_destroy> %3;\n"
"};\n\n");
*m_stream.localData() << templateString.arg(interface.kwaylandClientName()).arg(interface.name()).arg(interface.kwaylandClientName().toLower());
}
void Generator::generateClientPrivateGlobalClass(const Interface &interface)
{
const QString templateString = QStringLiteral(
"class %1::Private\n"
"{\n"
"public:\n"
" Private() = default;\n"
"\n"
" void setup(%2 *arg);\n"
"\n"
" WaylandPointer<%2, %2_destroy> %3;\n"
" EventQueue *queue = nullptr;\n"
"};\n\n");
*m_stream.localData() << templateString.arg(interface.kwaylandClientName()).arg(interface.name()).arg(interface.kwaylandClientName().toLower());
if (interface.isGlobal()) {
*m_stream.localData() << " EventQueue *queue = nullptr;\n";
}
*m_stream.localData() << "};\n\n";
}
void Generator::generateClientCpp(const Interface &interface)
......@@ -913,11 +938,16 @@ void Generator::generateClientCpp(const Interface &interface)
" release();\n"
"}\n"
"\n"
"void %1::Private::setup(%3 *arg)\n"
"{\n"
" Q_ASSERT(arg);\n"
" Q_ASSERT(!%2);\n"
" %2.setup(arg);\n"
"}\n"
"\n"
"void %1::setup(%3 *%2)\n"
"{\n"
" Q_ASSERT(%2);\n"
" Q_ASSERT(!d->%2);\n"
" d->%2.setup(%2);\n"
" d->setup(%2);\n"
"}\n"
"\n"
"void %1::release()\n"
......
......@@ -218,6 +218,8 @@ private:
void generateCppIncludes();
void generatePrivateClass(const Interface &interface);
void generateClientPrivateClass(const Interface &interface);
void generateClientPrivateResourceClass(const Interface &interface);
void generateClientPrivateGlobalClass(const Interface &interface);
void generateServerPrivateGlobalClass(const Interface &interface);
void generateServerPrivateResourceClass(const Interface &interface);
void generateServerPrivateInterfaceClass(const Interface &interface);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment