Branch: master

81cebe1f 2019-06-20 04:56:56 Michele Calgaro
Fixed direction of signals in generated code. This resolves issue #19.
This commit is partially based on work done by Emanoil Kotsev <deloptes@...>.

Signed-off-by: Michele Calgaro <michele.calgaro@...>
Signed-off-by: Emanoil Kotsev <deloptes@...>
M src/tools/dbusxml2qt3/methodgen.cpp
M src/tools/dbusxml2qt3/methodgen.h

src/tools/dbusxml2qt3/methodgen.cpp

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 @@
             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 @@
         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 = hasAnnotation(element, "org.freedesktop.DBus.GLib.Async");
+            classData.methods.append(method);
+            if (method.async) {
+                method.async = false;
+                classData.methods.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;
-
-            if (element.tagName() == "method")
-            {
-                method.async = hasAnnotation(element, "org.freedesktop.DBus.GLib.Async");
-                classData.methods.append(method);
-                if (method.async) {
-                    method.async = false;
-                    classData.methods.append(method);
-                }
-            }
-            else
-                classData.msignals.append(method);
+            classData.msignals.append(method);
         }
         else if (element.tagName() == "property")
         {
@@ -669,12 +673,17 @@
     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::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 @@
     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())
-                {
-                    stream << "(" << (*it).containerClass;
-                }
-
-                stream << "(" << (*it).name << ")";
-
-                if (!(*it).subAccessor.isEmpty())
-                {
-                    stream << ")";
-                }
-            }
-            else
-                stream << "    message << " << (*it).name;
-
-            stream << ";" << endl;
+            // 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())
+            {
+                stream << "(" << (*it).containerClass;
+            }
+
+            stream << "(" << (*it).name << ")";
+
+            if (!(*it).subAccessor.isEmpty())
+            {
+                stream << ")";
+            }
+        }
+        else
+            stream << "    message << " << (*it).name;
+
+        stream << ";" << endl;
     }
     stream << endl;
 
@@ -1140,7 +1148,28 @@
         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);

src/tools/dbusxml2qt3/methodgen.h

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 @@
 class Method
 {
 public:
+    enum Type
+    {
+        _Method,
+        _Signal
+    };
+
     TQString name;
+    Type type;
     TQValueList<Argument> arguments;
     bool noReply;
     bool async;
4e267fc5 2019-06-22 05:40:13 Emanoil Kotsev
Handle primitives in signals properly (not const)

Signed-off-by: Emanoil Kotsev <deloptes@...>
Signed-off-by: Michele Calgaro <michele.calgaro@...>
M src/tools/dbusxml2qt3/methodgen.cpp

src/tools/dbusxml2qt3/methodgen.cpp

diff --git a/src/tools/dbusxml2qt3/methodgen.cpp b/src/tools/dbusxml2qt3/methodgen.cpp
index ac3d569..89c3677 100644
--- a/src/tools/dbusxml2qt3/methodgen.cpp
+++ b/src/tools/dbusxml2qt3/methodgen.cpp
@@ -923,9 +923,20 @@
     TQValueList<Argument>::const_iterator endIt = method.arguments.end();
     for (; it != endIt;)
     {
-        stream << "const ";
+        if (!(*it).isPrimitive)
+        {
+            stream << "const ";
+        }
+
         stream << (*it).signature;
-        stream << "& " << (*it).name;
+
** Diff limit reached (max: 250 lines) **