diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-06-20 13:49:54 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2019-06-20 13:56:56 +0900 |
commit | 81cebe1f2041581a9a8b5d03bc01848df5d95055 (patch) | |
tree | 64d8dc3a16b96ff6c951ac4e1b0d38905273d8f6 /src | |
parent | 4d6cf58ef2b1d805b510f5e4eda97939dfac4a43 (diff) | |
download | dbus-1-tqt-81cebe1f2041581a9a8b5d03bc01848df5d95055.tar.gz dbus-1-tqt-81cebe1f2041581a9a8b5d03bc01848df5d95055.zip |
Fixed direction of signals in generated code. This resolves issue #19.
This commit is partially based on work done by Emanoil Kotsev <deloptes@gmail.com>.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/dbusxml2qt3/methodgen.cpp | 133 | ||||
-rw-r--r-- | src/tools/dbusxml2qt3/methodgen.h | 7 |
2 files changed, 88 insertions, 52 deletions
diff --git a/src/tools/dbusxml2qt3/methodgen.cpp b/src/tools/dbusxml2qt3/methodgen.cpp index 74a7f6c..ac3d569 100644 --- a/src/tools/dbusxml2qt3/methodgen.cpp +++ b/src/tools/dbusxml2qt3/methodgen.cpp @@ -332,11 +332,11 @@ static TQValueList<Argument> extractArguments(const TQDomElement& methodElement, argument.name = TQString("arg%1").arg(inCount + outCount); argument.direction = Argument::In; - if (!isSignal && element.attribute("direction", "in") == "out") + if (isSignal || element.attribute("direction", "in") == "out") argument.direction = Argument::Out; TQString annotation; - if (!isSignal && argument.direction == Argument::In) + if (argument.direction == Argument::In) { annotation = argAnnotations[TQString("In%1").arg(inCount)]; ++inCount; @@ -598,25 +598,29 @@ bool MethodGenerator::extractMethods(const TQDomElement& interfaceElement, TQDomElement element = node.toElement(); if (element.attribute("name").isEmpty()) continue; - if (element.tagName() == "method" || element.tagName() == "signal") + if (element.tagName() == "method") { Method method; method.name = element.attribute("name"); + method.type = Method::_Method; method.arguments = extractArguments(element, classData); method.noReply = false; - method.async = false; - - if (element.tagName() == "method") - { - method.async = hasAnnotation(element, "org.freedesktop.DBus.GLib.Async"); + method.async = hasAnnotation(element, "org.freedesktop.DBus.GLib.Async"); + classData.methods.append(method); + if (method.async) { + method.async = false; classData.methods.append(method); - if (method.async) { - method.async = false; - classData.methods.append(method); - } } - else - classData.msignals.append(method); + } + else if (element.tagName() == "signal") + { + Method method; + method.name = element.attribute("name"); + method.type = Method::_Signal; + method.arguments = extractArguments(element, classData); + method.noReply = false; + method.async = false; + classData.msignals.append(method); } else if (element.tagName() == "property") { @@ -669,12 +673,17 @@ void MethodGenerator::writeMethodDeclaration(const Method& method, bool pureVirt TQValueList<Argument>::const_iterator endIt = method.arguments.end(); for (; it != endIt;) { - if (!(*it).isPrimitive && (*it).direction == Argument::In) + if (!(*it).isPrimitive && ((*it).direction == Argument::In || method.type == Method::_Signal)) + { stream << "const "; + } stream << (*it).signature; - if (!(*it).isPrimitive || (*it).direction == Argument::Out) stream << "&"; + if (!(*it).isPrimitive || ((*it).direction == Argument::Out && method.type != Method::_Signal)) + { + stream << "&"; + } stream << " " << (*it).name; @@ -903,23 +912,25 @@ void MethodGenerator::writeMethodCall(const Class& classData, void MethodGenerator::writeSignalEmitter(const Class& classData, const Method& method, TQTextStream& stream) { + if (method.type != Method::_Signal) + { + return; + } + stream << "bool " << classData.name << "::emit" << method.name << "("; TQValueList<Argument>::const_iterator it = method.arguments.begin(); TQValueList<Argument>::const_iterator endIt = method.arguments.end(); for (; it != endIt;) { - if (!(*it).isPrimitive && (*it).direction == Argument::In) - stream << "const "; - + stream << "const "; stream << (*it).signature; - - if (!(*it).isPrimitive || (*it).direction == Argument::Out) stream << "&"; - - stream << " " << (*it).name; - + stream << "& " << (*it).name; ++it; - if (it != endIt) stream << ", "; + if (it != endIt) + { + stream << ", "; + } } stream << ")" << endl; @@ -938,39 +949,36 @@ void MethodGenerator::writeSignalEmitter(const Class& classData, it = method.arguments.begin(); for (; it != endIt; ++it) { - if ((*it).direction == Argument::In) + if (!(*it).annotatedType.isEmpty()) { - if (!(*it).annotatedType.isEmpty()) + // TODO: error handling + stream << " TQT_DBusData " << (*it).name << "Data;" << endl; + stream << " if (TQT_DBusDataConverter:convertToTQT_DBusData<" + << (*it).annotatedType << ">(" + << (*it).name << ", " << (*it).name << "Data" + << ") != TQT_DBusDataConverter::Success) return false;" + << endl; + stream << " message << " << (*it).name << "Data"; + } + else if (!(*it).accessor.isEmpty()) + { + stream << " message << TQT_DBusData::from" << (*it).accessor; + if (!(*it).subAccessor.isEmpty()) { - // TODO: error handling - stream << " TQT_DBusData " << (*it).name << "Data;" << endl; - stream << " if (TQT_DBusDataConverter:convertToTQT_DBusData<" - << (*it).annotatedType << ">(" - << (*it).name << ", " << (*it).name << "Data" - << ") != TQT_DBusDataConverter::Success) return false;" - << endl; - stream << " message << " << (*it).name << "Data"; + stream << "(" << (*it).containerClass; } - else if (!(*it).accessor.isEmpty()) - { - stream << " message << TQT_DBusData::from" << (*it).accessor; - if (!(*it).subAccessor.isEmpty()) - { - stream << "(" << (*it).containerClass; - } - stream << "(" << (*it).name << ")"; + stream << "(" << (*it).name << ")"; - if (!(*it).subAccessor.isEmpty()) - { - stream << ")"; - } + if (!(*it).subAccessor.isEmpty()) + { + stream << ")"; } - else - stream << " message << " << (*it).name; - - stream << ";" << endl; } + else + stream << " message << " << (*it).name; + + stream << ";" << endl; } stream << endl; @@ -1140,7 +1148,28 @@ void MethodGenerator::writeSignalHandler(const Class& classData, stream << "if (message.member() == \"" << (*it).name << "\")" << endl; stream << " {" << endl; - writeVariables(" ", *it, stream); + int count = 0; + TQValueList<Argument>::const_iterator it1 = (*it).arguments.begin(); + TQValueList<Argument>::const_iterator endIt1 = (*it).arguments.end(); + for (; it1 != endIt1; ++it1) + { + stream << " " << (*it1).signature << " _" << (*it1).name; + + if (!(*it1).accessor.isEmpty()) + { + stream << TQString::fromUtf8(" = message[%1].to").arg(count++); + stream << (*it1).accessor; + if (!(*it1).subAccessor.isEmpty()) + { + stream << TQString("().to%1").arg((*it1).subAccessor); + } + + stream << "()"; + } + + stream << ";" << endl; + } + stream << endl; writeSignalEmit(*it, stream); diff --git a/src/tools/dbusxml2qt3/methodgen.h b/src/tools/dbusxml2qt3/methodgen.h index 9954fb2..7ee4ce6 100644 --- a/src/tools/dbusxml2qt3/methodgen.h +++ b/src/tools/dbusxml2qt3/methodgen.h @@ -58,7 +58,14 @@ public: class Method { public: + enum Type + { + _Method, + _Signal + }; + TQString name; + Type type; TQValueList<Argument> arguments; bool noReply; bool async; |