Generate DBusBaseNode class to handle the empty nodes.

- Prevent showing Introspection in empty nodes
- fix method generation for objectpath array in signature like a{oa{sa{sv}}}
- Hide Introspectable interface if there is no interface in the node
- Add support for multiple nodes introspection
- addChildNode function to support multiple nodes

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
pull/8/head
Emanoil Kotsev 5 years ago committed by Michele Calgaro
parent e9bf60b236
commit 7d49292176
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -347,6 +347,7 @@ static void writeSourceIncludes(const Class& classData, Class::Role role,
case Class::Node: case Class::Node:
includes["TQt"].insertString("<tqdom.h>"); includes["TQt"].insertString("<tqdom.h>");
includes["TQt"].insertString("<tqmap.h>"); includes["TQt"].insertString("<tqmap.h>");
includes["TQt"].insertString("<tqstringlist.h>");
includes["tqdbus"].insertString("<tqdbusconnection.h>"); includes["tqdbus"].insertString("<tqdbusconnection.h>");
includes["tqdbus"].insertString("<tqdbusmessage.h>"); includes["tqdbus"].insertString("<tqdbusmessage.h>");
break; break;
@ -440,6 +441,7 @@ static void openClassDeclaration(const Class& classData,
stream << endl; stream << endl;
stream << " bool registerObject(const TQT_DBusConnection& connection, " stream << " bool registerObject(const TQT_DBusConnection& connection, "
<< "const TQString& path);" << endl; << "const TQString& path);" << endl;
stream << " void addChildNode(const TQString& child);" << endl;
stream << endl; stream << endl;
stream << " void unregisterObject();" << endl; stream << " void unregisterObject();" << endl;
stream << endl; stream << endl;

@ -119,11 +119,14 @@ int main(int argc, char** argv)
{ {
hasIntrospectable = true; hasIntrospectable = true;
} }
else
{
interfaces << classData; interfaces << classData;
} }
} }
} }
} }
}
if (interfaces.isEmpty()) if (interfaces.isEmpty())
{ {
@ -398,6 +401,34 @@ int main(int argc, char** argv)
headerStream, sourceStream); headerStream, sourceStream);
ClassGenerator::finishStreams(baseName, headerStream, sourceStream); ClassGenerator::finishStreams(baseName, headerStream, sourceStream);
// create dummy node to handle the path hierarchy
if ( nameParts.size() > 1 ) {
TQTextStream headerStreamDBusBaseNode;
TQTextStream sourceStreamDBusBaseNode;
TQString baseName = "DBusBase";
Class classDataDBusBaseNode;
classDataDBusBaseNode.name = baseName + "Node";
TQValueList<Class> interfacesDBusBase = TQValueList<Class>();
TQString baseNameDBusBaseNode = baseName.lower() + "Node";
if (!ClassGenerator::initStreams(baseNameDBusBaseNode, headerStreamDBusBaseNode, sourceStreamDBusBaseNode))
{
std::cerr << "dbusxml2qt3: interface files, using base name '"
<< baseNameDBusBaseNode.local8Bit().data()
<< "', could not be opened for writing"
<< std::endl;
exit(4);
}
ClassGenerator::generateNode(classDataDBusBaseNode,
interfacesDBusBase, baseNameDBusBaseNode,
headerStreamDBusBaseNode, sourceStreamDBusBaseNode);
ClassGenerator::finishStreams(baseNameDBusBaseNode, headerStreamDBusBaseNode, sourceStreamDBusBaseNode);
}
} }
return 0; return 0;

@ -152,7 +152,7 @@ static bool parseDBusSignature(const TQString& signature, Argument& argument)
if (!parseDBusSignature(dictSignature.left(1), key)) return false; if (!parseDBusSignature(dictSignature.left(1), key)) return false;
Argument value; Argument value;
if (parseDBusSignature(dictSignature.mid(1), value)) if (parseDBusSignature(dictSignature.mid(1), value) && !dictSignature.startsWith("oa"))
{ {
if (!value.subAccessor.isEmpty()) if (!value.subAccessor.isEmpty())
{ {
@ -535,6 +535,14 @@ static void writeNodeInitialization(const Class& classData,
stream << " return true;" << endl; stream << " return true;" << endl;
stream << "}" << endl; stream << "}" << endl;
stream << endl; stream << endl;
stream << "void " << classData.name
<< "::addChildNode(const TQString& child)" << endl;
stream << "{" << endl;
stream << " m_private->childrenNodes.append(child);" << endl;
stream << "}" << endl;
stream << endl;
} }
static void writeNodeIntrospection(const Class& classData, static void writeNodeIntrospection(const Class& classData,
@ -550,11 +558,14 @@ static void writeNodeIntrospection(const Class& classData,
stream << " {" << endl; stream << " {" << endl;
stream << " nodeElement.setAttribute ( \"name\", objectPath );" << endl; stream << " nodeElement.setAttribute ( \"name\", objectPath );" << endl;
stream << " }" << endl; stream << " }" << endl;
stream << " // Introspectable is added by default. Show it only if there is interface" << endl;
stream << " if (interfaces.count()>1) {" << endl;
stream << " TQDomElement interfaceElement = doc.createElement(\"interface\");" stream << " TQDomElement interfaceElement = doc.createElement(\"interface\");"
<< endl; << endl;
stream << " org::freedesktop::DBus::IntrospectableInterface" stream << " org::freedesktop::DBus::IntrospectableInterface"
<< "::buildIntrospectionData(interfaceElement);" << endl; << "::buildIntrospectionData(interfaceElement);" << endl;
stream << " nodeElement.appendChild(interfaceElement);" << endl; stream << " nodeElement.appendChild(interfaceElement);" << endl;
stream << " }" << endl;
TQValueList<Class>::const_iterator it = interfaces.begin(); TQValueList<Class>::const_iterator it = interfaces.begin();
TQValueList<Class>::const_iterator endIt = interfaces.end(); TQValueList<Class>::const_iterator endIt = interfaces.end();
@ -563,13 +574,22 @@ static void writeNodeIntrospection(const Class& classData,
if ((*it).dbusName == "org.freedesktop.DBus.Introspectable") continue; if ((*it).dbusName == "org.freedesktop.DBus.Introspectable") continue;
stream << endl; stream << endl;
stream << " interfaceElement = doc.createElement(\"interface\");" stream << " TQDomElement interfaceElement = doc.createElement(\"interface\");"
<< endl; << endl;
stream << " " << (*it).namespaces.join("::") + "::" + (*it).name stream << " " << (*it).namespaces.join("::") + "::" + (*it).name
<< "Interface::buildIntrospectionData(interfaceElement);" << endl; << "Interface::buildIntrospectionData(interfaceElement);" << endl;
stream << " nodeElement.appendChild(interfaceElement);" << endl; stream << " nodeElement.appendChild(interfaceElement);" << endl;
} }
stream << endl;
stream << " if (!childrenNodes.isEmpty()) {" << endl;
stream << " for (TQStringList::Iterator it = childrenNodes.begin(); it != childrenNodes.end(); ++it ) {" << endl;
stream << " TQDomElement nodeElement1 = doc.createElement(\"node\");" << endl;
stream << " nodeElement1.setAttribute ( \"name\", *it );" << endl;
stream << " nodeElement.appendChild(nodeElement1);" << endl;
stream << " }" << endl;
stream << " }" << endl;
stream << endl; stream << endl;
stream << " doc.appendChild(nodeElement);" << endl; stream << " doc.appendChild(nodeElement);" << endl;
stream << endl; stream << endl;
@ -1763,6 +1783,7 @@ void MethodGenerator::writeNodePrivate(const Class& classData, TQTextStream& str
stream << endl; stream << endl;
stream << " TQT_DBusConnection connection;" << endl; stream << " TQT_DBusConnection connection;" << endl;
stream << " TQString objectPath;" << endl; stream << " TQString objectPath;" << endl;
stream << " TQStringList childrenNodes;" << endl;
stream << endl; stream << endl;
stream << "protected:" << endl; stream << "protected:" << endl;

Loading…
Cancel
Save