2006-03-06 15:27:56 +00:00
|
|
|
/* -*- C++ -*-
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2006 Trolltech AS. All rights reserved.
|
|
|
|
|
* Author: Thiago Macieira <thiago.macieira@trolltech.com>
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/qbytearray.h>
|
|
|
|
|
#include <QtCore/qdatetime.h>
|
|
|
|
|
#include <QtCore/qfile.h>
|
|
|
|
|
#include <QtCore/qstring.h>
|
2006-03-28 18:56:08 +00:00
|
|
|
#include <QtCore/qstringlist.h>
|
2006-03-06 15:27:56 +00:00
|
|
|
#include <QtCore/qtextstream.h>
|
|
|
|
|
#include <QtCore/qset.h>
|
|
|
|
|
|
|
|
|
|
#include <dbus/qdbus.h>
|
2006-06-04 15:52:05 +00:00
|
|
|
#include "../src/qdbusmetaobject_p.h"
|
|
|
|
|
#include "../src/qdbusintrospection_p.h"
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
#define PROGRAMNAME "dbusidl2cpp"
|
2006-05-02 14:00:27 +00:00
|
|
|
#define PROGRAMVERSION "0.4"
|
2006-03-06 15:27:56 +00:00
|
|
|
#define PROGRAMCOPYRIGHT "Copyright (C) 2006 Trolltech AS. All rights reserved."
|
|
|
|
|
|
|
|
|
|
#define ANNOTATION_NO_WAIT "org.freedesktop.DBus.Method.NoReply"
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static const char cmdlineOptions[] = "a:c:hmNp:vV";
|
|
|
|
|
static const char *globalClassName;
|
2006-03-06 15:27:56 +00:00
|
|
|
static const char *proxyFile;
|
|
|
|
|
static const char *adaptorFile;
|
|
|
|
|
static const char *inputFile;
|
|
|
|
|
static bool skipNamespaces;
|
|
|
|
|
static bool verbose;
|
2006-03-28 18:56:08 +00:00
|
|
|
static bool includeMocs;
|
2006-03-06 15:27:56 +00:00
|
|
|
static QStringList wantedInterfaces;
|
|
|
|
|
|
|
|
|
|
static const char help[] =
|
|
|
|
|
"Usage: " PROGRAMNAME " [options...] [idl-or-xml-file] [interfaces...]\n"
|
|
|
|
|
"Produces the C++ code to implement the interfaces defined in the input file.\n"
|
|
|
|
|
"If no options are given, the code is written to the standard output.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Options:\n"
|
|
|
|
|
" -a <filename> Write the adaptor code to <filename>\n"
|
2006-03-28 18:56:08 +00:00
|
|
|
" -c <classname> Use <classname> as the class name for the generated classes\n"
|
2006-03-06 15:27:56 +00:00
|
|
|
" -h Show this information\n"
|
2006-03-28 18:56:08 +00:00
|
|
|
" -m Generate #include \"filename.moc\" statements in the .cpp files\n"
|
2006-03-06 15:27:56 +00:00
|
|
|
" -N Don't use namespaces\n"
|
|
|
|
|
" -p <filename> Write the proxy code to <filename>\n"
|
|
|
|
|
" -v Be verbose.\n"
|
|
|
|
|
" -V Show the program version and quit.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"If the file name given to the options -a and -p does not end in .cpp or .h, the\n"
|
|
|
|
|
"program will automatically append the suffixes and produce both files.\n";
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static const char includeList[] =
|
|
|
|
|
"#include <QtCore/QByteArray>\n"
|
|
|
|
|
"#include <QtCore/QList>\n"
|
|
|
|
|
"#include <QtCore/QMap>\n"
|
|
|
|
|
"#include <QtCore/QString>\n"
|
|
|
|
|
"#include <QtCore/QStringList>\n"
|
|
|
|
|
"#include <QtCore/QVariant>\n";
|
|
|
|
|
|
|
|
|
|
static const char forwardDeclarations[] =
|
|
|
|
|
"class QByteArray;\n"
|
|
|
|
|
"template<class T> class QList;\n"
|
|
|
|
|
"template<class Key, class Value> class QMap;\n"
|
|
|
|
|
"class QString;\n"
|
|
|
|
|
"class QStringList;\n"
|
|
|
|
|
"class QVariant;\n";
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
static void showHelp()
|
|
|
|
|
{
|
|
|
|
|
printf("%s", help);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void showVersion()
|
|
|
|
|
{
|
|
|
|
|
printf("%s version %s\n", PROGRAMNAME, PROGRAMVERSION);
|
|
|
|
|
printf("D-Bus binding tool for Qt\n");
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void parseCmdLine(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
opterr = true;
|
|
|
|
|
while ((c = getopt(argc, argv, cmdlineOptions)) != -1)
|
|
|
|
|
switch (c)
|
|
|
|
|
{
|
|
|
|
|
case 'a':
|
|
|
|
|
adaptorFile = optarg;
|
|
|
|
|
break;
|
2006-03-28 18:56:08 +00:00
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
|
globalClassName = optarg;
|
|
|
|
|
break;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
|
verbose = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
case 'm':
|
|
|
|
|
includeMocs = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
case 'N':
|
|
|
|
|
skipNamespaces = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
|
showHelp();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
|
showVersion();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'p':
|
|
|
|
|
proxyFile = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
|
exit(1);
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (optind != argc)
|
|
|
|
|
inputFile = argv[optind++];
|
|
|
|
|
|
|
|
|
|
while (optind != argc)
|
|
|
|
|
wantedInterfaces << QString::fromLocal8Bit(argv[optind++]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QDBusIntrospection::Interfaces readInput()
|
|
|
|
|
{
|
|
|
|
|
QFile input(QFile::decodeName(inputFile));
|
2006-03-28 18:56:08 +00:00
|
|
|
if (inputFile && QLatin1String("-") != inputFile)
|
2006-03-06 15:27:56 +00:00
|
|
|
input.open(QIODevice::ReadOnly);
|
|
|
|
|
else
|
|
|
|
|
input.open(stdin, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
|
|
QByteArray data = input.readAll();
|
|
|
|
|
|
|
|
|
|
// check if the input is already XML
|
|
|
|
|
data = data.trimmed();
|
|
|
|
|
if (data.startsWith("<!DOCTYPE ") || data.startsWith("<?xml") ||
|
|
|
|
|
data.startsWith("<node") || data.startsWith("<interface"))
|
|
|
|
|
// already XML
|
|
|
|
|
return QDBusIntrospection::parseInterfaces(QString::fromUtf8(data));
|
|
|
|
|
|
|
|
|
|
fprintf(stderr, "Cannot process input. Stop.\n");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cleanInterfaces(QDBusIntrospection::Interfaces &interfaces)
|
|
|
|
|
{
|
|
|
|
|
if (!wantedInterfaces.isEmpty()) {
|
|
|
|
|
QDBusIntrospection::Interfaces::Iterator it = interfaces.begin();
|
|
|
|
|
while (it != interfaces.end())
|
|
|
|
|
if (!wantedInterfaces.contains(it.key()))
|
|
|
|
|
it = interfaces.erase(it);
|
|
|
|
|
else
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// produce a header name from the file name
|
|
|
|
|
static QString header(const char *name)
|
|
|
|
|
{
|
|
|
|
|
if (!name || (name[0] == '-' && name[1] == '\0'))
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
QString retval = QFile::decodeName(name);
|
|
|
|
|
if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc"))
|
|
|
|
|
retval.append(".h");
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// produce a cpp name from the file name
|
|
|
|
|
static QString cpp(const char *name)
|
|
|
|
|
{
|
|
|
|
|
if (!name || (name[0] == '-' && name[1] == '\0'))
|
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
|
|
QString retval = QFile::decodeName(name);
|
|
|
|
|
if (!retval.endsWith(".h") && !retval.endsWith(".cpp") && !retval.endsWith(".cc"))
|
|
|
|
|
retval.append(".cpp");
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QTextStream &writeHeader(QTextStream &ts, bool changesWillBeLost)
|
|
|
|
|
{
|
|
|
|
|
ts << "/*" << endl
|
|
|
|
|
<< " * This file was generated by " PROGRAMNAME " version " PROGRAMVERSION << endl
|
|
|
|
|
<< " * when processing input file " << (inputFile ? inputFile : "<stdin>") << endl
|
|
|
|
|
<< " *" << endl
|
|
|
|
|
<< " * " PROGRAMNAME " is " PROGRAMCOPYRIGHT << endl
|
|
|
|
|
<< " *" << endl
|
|
|
|
|
<< " * This is an auto-generated file." << endl;
|
|
|
|
|
|
|
|
|
|
if (changesWillBeLost)
|
|
|
|
|
ts << " * Do not edit! All changes made to it will be lost." << endl;
|
|
|
|
|
|
|
|
|
|
ts << " */" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum ClassType { Proxy, Adaptor };
|
|
|
|
|
static QString classNameForInterface(const QString &interface, ClassType classType)
|
|
|
|
|
{
|
2006-03-28 18:56:08 +00:00
|
|
|
if (globalClassName)
|
|
|
|
|
return QLatin1String(globalClassName);
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
QStringList parts = interface.split('.');
|
|
|
|
|
|
|
|
|
|
QString retval;
|
|
|
|
|
if (classType == Proxy)
|
|
|
|
|
foreach (QString part, parts) {
|
|
|
|
|
part[0] = part[0].toUpper();
|
|
|
|
|
retval += part;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
retval = parts.last();
|
|
|
|
|
retval[0] = retval[0].toUpper();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (classType == Proxy)
|
|
|
|
|
retval += "Interface";
|
|
|
|
|
else
|
|
|
|
|
retval += "Adaptor";
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static QByteArray qtTypeName(const QString &signature)
|
2006-03-06 15:27:56 +00:00
|
|
|
{
|
2006-03-28 18:56:08 +00:00
|
|
|
QVariant::Type type = QDBusUtil::signatureToType(signature);
|
|
|
|
|
if (type == QVariant::Invalid)
|
|
|
|
|
qFatal("Got unknown type `%s'", qPrintable(signature));
|
|
|
|
|
|
|
|
|
|
return QVariant::typeToName(type);
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static QString nonConstRefArg(const QByteArray &arg)
|
2006-03-06 15:27:56 +00:00
|
|
|
{
|
2006-03-28 18:56:08 +00:00
|
|
|
return QLatin1String(arg + " &");
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static QString templateArg(const QByteArray &arg)
|
2006-03-06 15:27:56 +00:00
|
|
|
{
|
2006-03-28 18:56:08 +00:00
|
|
|
if (!arg.endsWith('>'))
|
|
|
|
|
return QLatin1String(arg);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
return QLatin1String(arg + ' ');
|
|
|
|
|
}
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
static QString constRefArg(const QByteArray &arg)
|
|
|
|
|
{
|
|
|
|
|
if (!arg.startsWith('Q'))
|
|
|
|
|
return QLatin1String(arg + ' ');
|
|
|
|
|
else
|
|
|
|
|
return QString("const %1 &").arg( QLatin1String(arg) );
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QStringList makeArgNames(const QDBusIntrospection::Arguments &inputArgs,
|
|
|
|
|
const QDBusIntrospection::Arguments &outputArgs =
|
|
|
|
|
QDBusIntrospection::Arguments())
|
|
|
|
|
{
|
|
|
|
|
QStringList retval;
|
|
|
|
|
for (int i = 0; i < inputArgs.count(); ++i) {
|
|
|
|
|
const QDBusIntrospection::Argument &arg = inputArgs.at(i);
|
|
|
|
|
QString name = arg.name;
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = QString("in%1").arg(i);
|
|
|
|
|
while (retval.contains(name))
|
|
|
|
|
name += "_";
|
|
|
|
|
retval << name;
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < outputArgs.count(); ++i) {
|
|
|
|
|
const QDBusIntrospection::Argument &arg = outputArgs.at(i);
|
|
|
|
|
QString name = arg.name;
|
|
|
|
|
if (name.isEmpty())
|
|
|
|
|
name = QString("out%1").arg(i);
|
|
|
|
|
while (retval.contains(name))
|
|
|
|
|
name += "_";
|
|
|
|
|
retval << name;
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writeArgList(QTextStream &ts, const QStringList &argNames,
|
|
|
|
|
const QDBusIntrospection::Arguments &inputArgs,
|
|
|
|
|
const QDBusIntrospection::Arguments &outputArgs = QDBusIntrospection::Arguments())
|
|
|
|
|
{
|
|
|
|
|
// input args:
|
|
|
|
|
bool first = true;
|
|
|
|
|
int argPos = 0;
|
|
|
|
|
for (int i = 0; i < inputArgs.count(); ++i) {
|
|
|
|
|
const QDBusIntrospection::Argument &arg = inputArgs.at(i);
|
2006-03-28 18:56:08 +00:00
|
|
|
QString type = constRefArg(qtTypeName(arg.type));
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
|
ts << ", ";
|
|
|
|
|
ts << type << argNames.at(argPos++);
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argPos++;
|
|
|
|
|
|
|
|
|
|
// output args
|
|
|
|
|
// yes, starting from 1
|
|
|
|
|
for (int i = 1; i < outputArgs.count(); ++i) {
|
|
|
|
|
const QDBusIntrospection::Argument &arg = outputArgs.at(i);
|
|
|
|
|
QString name = arg.name;
|
|
|
|
|
|
|
|
|
|
if (!first)
|
|
|
|
|
ts << ", ";
|
2006-03-28 18:56:08 +00:00
|
|
|
ts << nonConstRefArg(qtTypeName(arg.type)) << argNames.at(argPos++);
|
2006-03-06 15:27:56 +00:00
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
static QString propertyGetter(const QDBusIntrospection::Property &property)
|
|
|
|
|
{
|
|
|
|
|
QString getter = property.annotations.value("com.trolltech.QtDBus.propertyGetter");
|
|
|
|
|
if (getter.isEmpty()) {
|
|
|
|
|
getter = property.name;
|
|
|
|
|
getter[0] = getter[0].toLower();
|
|
|
|
|
}
|
|
|
|
|
return getter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString propertySetter(const QDBusIntrospection::Property &property)
|
|
|
|
|
{
|
|
|
|
|
QString setter = property.annotations.value("com.trolltech.QtDBus.propertySetter");
|
|
|
|
|
if (setter.isEmpty()) {
|
|
|
|
|
setter = "set" + property.name;
|
|
|
|
|
setter[3] = setter[3].toUpper();
|
|
|
|
|
}
|
|
|
|
|
return setter;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
static QString stringify(const QString &data)
|
|
|
|
|
{
|
|
|
|
|
QString retval;
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i < data.length(); ++i) {
|
|
|
|
|
retval += '\"';
|
|
|
|
|
for ( ; i < data.length() && data[i] != QChar('\n'); ++i)
|
|
|
|
|
if (data[i] == '\"')
|
|
|
|
|
retval += "\\\"";
|
|
|
|
|
else
|
|
|
|
|
retval += data[i];
|
2006-05-29 18:17:09 +00:00
|
|
|
retval += "\\n\"\n";
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writeProxy(const char *proxyFile, const QDBusIntrospection::Interfaces &interfaces)
|
|
|
|
|
{
|
|
|
|
|
// open the file
|
2006-03-28 18:56:08 +00:00
|
|
|
QString headerName = header(proxyFile);
|
|
|
|
|
QFile file(headerName);
|
|
|
|
|
if (!headerName.isEmpty())
|
2006-03-06 15:27:56 +00:00
|
|
|
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
|
|
|
|
else
|
|
|
|
|
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
|
2006-03-28 18:56:08 +00:00
|
|
|
QTextStream hs(&file);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
QString cppName = cpp(proxyFile);
|
|
|
|
|
QByteArray cppData;
|
|
|
|
|
QTextStream cs(&cppData);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// write the header:
|
2006-03-28 18:56:08 +00:00
|
|
|
writeHeader(hs, true);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// include guards:
|
|
|
|
|
QString includeGuard;
|
2006-03-28 18:56:08 +00:00
|
|
|
if (!headerName.isEmpty()) {
|
|
|
|
|
includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_'));
|
2006-03-06 15:27:56 +00:00
|
|
|
int pos = includeGuard.lastIndexOf('/');
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
includeGuard = includeGuard.mid(pos + 1);
|
|
|
|
|
} else {
|
|
|
|
|
includeGuard = QString("QDBUSIDL2CPP_PROXY");
|
|
|
|
|
}
|
|
|
|
|
includeGuard = QString("%1_%2%3")
|
|
|
|
|
.arg(includeGuard)
|
|
|
|
|
.arg(getpid())
|
|
|
|
|
.arg(QDateTime::currentDateTime().toTime_t());
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "#ifndef " << includeGuard << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "#define " << includeGuard << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
// include our stuff:
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "#include <QtCore/QObject>" << endl
|
|
|
|
|
<< includeList
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "#include <dbus/qdbus.h>" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
if (cppName != headerName) {
|
|
|
|
|
writeHeader(cs, false);
|
|
|
|
|
cs << "#include \"" << headerName << "\"" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
foreach (const QDBusIntrospection::Interface *interface, interfaces) {
|
2006-03-28 18:56:08 +00:00
|
|
|
QString className = classNameForInterface(interface->name, Proxy);
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
// comment:
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "/*" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< " * Proxy class for interface " << interface->name << endl
|
|
|
|
|
<< " */" << endl;
|
2006-03-28 18:56:08 +00:00
|
|
|
cs << "/*" << endl
|
|
|
|
|
<< " * Implementation of interface class " << className << endl
|
|
|
|
|
<< " */" << endl
|
|
|
|
|
<< endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// class header:
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "class " << className << ": public QDBusAbstractInterface" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "{" << endl
|
2006-03-28 18:56:08 +00:00
|
|
|
<< " Q_OBJECT" << endl;
|
|
|
|
|
|
|
|
|
|
// the interface name
|
|
|
|
|
hs << "public:" << endl
|
|
|
|
|
<< " static inline const char *staticInterfaceName()" << endl
|
|
|
|
|
<< " { return \"" << interface->name << "\"; }" << endl
|
|
|
|
|
<< endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
// constructors/destructors:
|
|
|
|
|
hs << "public:" << endl
|
|
|
|
|
<< " explicit " << className << "(QDBusAbstractInterfacePrivate *p);" << endl
|
|
|
|
|
<< endl
|
|
|
|
|
<< " ~" << className << "();" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
cs << className << "::" << className << "(QDBusAbstractInterfacePrivate *p)" << endl
|
|
|
|
|
<< " : QDBusAbstractInterface(p)" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl
|
|
|
|
|
<< className << "::~" << className << "()" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
// properties:
|
|
|
|
|
foreach (const QDBusIntrospection::Property &property, interface->properties) {
|
|
|
|
|
QByteArray type = qtTypeName(property.type);
|
|
|
|
|
QString templateType = templateArg(type);
|
|
|
|
|
QString constRefType = constRefArg(type);
|
|
|
|
|
QString getter = propertyGetter(property);
|
|
|
|
|
QString setter = propertySetter(property);
|
|
|
|
|
|
|
|
|
|
hs << " Q_PROPERTY(" << type << " " << property.name;
|
|
|
|
|
|
|
|
|
|
// getter:
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Write)
|
|
|
|
|
// it's readble
|
|
|
|
|
hs << " READ " << getter;
|
|
|
|
|
|
|
|
|
|
// setter
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Read)
|
|
|
|
|
// it's writeable
|
|
|
|
|
hs << " WRITE " << setter;
|
|
|
|
|
|
|
|
|
|
hs << ")" << endl;
|
|
|
|
|
|
|
|
|
|
// getter:
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Write) {
|
|
|
|
|
hs << " inline " << type << " " << getter << "() const" << endl;
|
|
|
|
|
if (type != "QVariant")
|
|
|
|
|
hs << " { return qvariant_cast< " << type << " >(internalPropGet(\""
|
|
|
|
|
<< property.name << "\")); }" << endl;
|
|
|
|
|
else
|
|
|
|
|
hs << " { return internalPropGet(\"" << property.name << "\"); }" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setter:
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Read) {
|
|
|
|
|
hs << " inline void " << setter << "(" << constRefArg(type) << "value)" << endl
|
|
|
|
|
<< " { internalPropSet(\"" << property.name
|
|
|
|
|
<< "\", qVariantFromValue(value)); }" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hs << endl;
|
|
|
|
|
}
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// methods:
|
2006-05-02 14:00:27 +00:00
|
|
|
hs << "public Q_SLOTS: // METHODS" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
foreach (const QDBusIntrospection::Method &method, interface->methods) {
|
|
|
|
|
bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true";
|
|
|
|
|
if (isAsync && !method.outputArgs.isEmpty()) {
|
|
|
|
|
fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n",
|
|
|
|
|
qPrintable(method.name), qPrintable(interface->name));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " inline ";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "Q_DECL_DEPRECATED ";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
if (isAsync)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "Q_ASYNC void ";
|
2006-03-06 15:27:56 +00:00
|
|
|
else if (method.outputArgs.isEmpty())
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "QDBusReply<void> ";
|
2006-03-06 15:27:56 +00:00
|
|
|
else {
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "QDBusReply<" << templateArg(qtTypeName(method.outputArgs.first().type)) << "> ";
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << method.name << "(";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
QStringList argNames = makeArgNames(method.inputArgs, method.outputArgs);
|
2006-03-28 18:56:08 +00:00
|
|
|
writeArgList(hs, argNames, method.inputArgs, method.outputArgs);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << ")" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< " {" << endl;
|
|
|
|
|
|
|
|
|
|
if (method.outputArgs.count() > 1)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " QDBusMessage reply = call(QLatin1String(\"";
|
2006-03-06 15:27:56 +00:00
|
|
|
else if (!isAsync)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " return call(QLatin1String(\"";
|
2006-03-06 15:27:56 +00:00
|
|
|
else
|
2006-04-29 17:22:47 +00:00
|
|
|
hs << " call(NoWaitForReply, QLatin1String(\"";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
// rebuild the method input signature:
|
2006-03-06 15:27:56 +00:00
|
|
|
QString signature = QChar('.');
|
|
|
|
|
foreach (const QDBusIntrospection::Argument &arg, method.inputArgs)
|
2006-03-28 18:56:08 +00:00
|
|
|
signature += arg.type;
|
2006-03-06 15:27:56 +00:00
|
|
|
if (signature.length() == 1)
|
|
|
|
|
signature.clear();
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << method.name << signature << "\")";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
int argPos = 0;
|
|
|
|
|
for (int i = 0; i < method.inputArgs.count(); ++i)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << ", " << argNames.at(argPos++);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-04-29 17:22:47 +00:00
|
|
|
// close the QDBusIntrospection::call call
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << ");" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
argPos++;
|
|
|
|
|
if (method.outputArgs.count() > 1) {
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " if (reply.type() == QDBusMessage::ReplyMessage) {" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// yes, starting from 1
|
|
|
|
|
for (int i = 1; i < method.outputArgs.count(); ++i)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " " << argNames.at(argPos++) << " = qvariant_cast<"
|
|
|
|
|
<< templateArg(qtTypeName(method.outputArgs.at(i).type))
|
2006-03-06 15:27:56 +00:00
|
|
|
<< ">(reply.at(" << i << "));" << endl;
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " }" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< " return reply;" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// close the function:
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << " }" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
hs << "Q_SIGNALS: // SIGNALS" << endl;
|
2006-03-28 18:56:08 +00:00
|
|
|
foreach (const QDBusIntrospection::Signal &signal, interface->signals_) {
|
|
|
|
|
hs << " ";
|
|
|
|
|
if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
|
|
|
|
|
hs << "Q_DECL_DEPRECATED ";
|
|
|
|
|
|
|
|
|
|
hs << "void " << signal.name << "(";
|
|
|
|
|
|
|
|
|
|
QStringList argNames = makeArgNames(signal.outputArgs);
|
|
|
|
|
writeArgList(hs, argNames, signal.outputArgs);
|
|
|
|
|
|
|
|
|
|
hs << ");" << endl; // finished for header
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
// close the class:
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "};" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!skipNamespaces) {
|
|
|
|
|
QStringList last;
|
|
|
|
|
QDBusIntrospection::Interfaces::ConstIterator it = interfaces.constBegin();
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
QStringList current;
|
|
|
|
|
QString name;
|
|
|
|
|
if (it != interfaces.constEnd()) {
|
|
|
|
|
current = it->constData()->name.split('.');
|
|
|
|
|
name = current.takeLast();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < current.count() && i < last.count() && current.at(i) == last.at(i))
|
|
|
|
|
++i;
|
|
|
|
|
|
|
|
|
|
// i parts matched
|
|
|
|
|
// close last.count() - i namespaces:
|
|
|
|
|
for (int j = i; j < last.count(); ++j)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << QString((last.count() - j - 1 + i) * 2, ' ') << "}" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// open current.count() - i namespaces
|
|
|
|
|
for (int j = i; j < current.count(); ++j)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << QString(j * 2, ' ') << "namespace " << current.at(j) << " {" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// add this class:
|
|
|
|
|
if (!name.isEmpty()) {
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << QString(current.count() * 2, ' ')
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "typedef ::" << classNameForInterface(it->constData()->name, Proxy)
|
|
|
|
|
<< " " << name << ";" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (it == interfaces.constEnd())
|
|
|
|
|
break;
|
|
|
|
|
++it;
|
|
|
|
|
last = current;
|
|
|
|
|
} while (true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// close the include guard
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "#endif" << endl;
|
|
|
|
|
|
|
|
|
|
if (includeMocs)
|
|
|
|
|
cs << endl
|
|
|
|
|
<< "#include \"" << proxyFile << ".moc\"" << endl;
|
|
|
|
|
|
|
|
|
|
cs.flush();
|
|
|
|
|
hs.flush();
|
|
|
|
|
if (headerName == cppName)
|
|
|
|
|
file.write(cppData);
|
|
|
|
|
else {
|
|
|
|
|
// write to cpp file
|
|
|
|
|
QFile f(cppName);
|
|
|
|
|
f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
|
|
|
|
f.write(cppData);
|
|
|
|
|
}
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void writeAdaptor(const char *adaptorFile, const QDBusIntrospection::Interfaces &interfaces)
|
|
|
|
|
{
|
|
|
|
|
// open the file
|
|
|
|
|
QString headerName = header(adaptorFile);
|
|
|
|
|
QFile file(headerName);
|
|
|
|
|
if (!headerName.isEmpty())
|
|
|
|
|
file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
|
|
|
|
else
|
|
|
|
|
file.open(stdout, QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
|
QTextStream hs(&file);
|
|
|
|
|
|
|
|
|
|
QString cppName = cpp(adaptorFile);
|
|
|
|
|
QByteArray cppData;
|
|
|
|
|
QTextStream cs(&cppData);
|
|
|
|
|
|
|
|
|
|
// write the headers
|
|
|
|
|
writeHeader(hs, false);
|
|
|
|
|
|
|
|
|
|
// include guards:
|
|
|
|
|
QString includeGuard;
|
|
|
|
|
if (!headerName.isEmpty()) {
|
|
|
|
|
includeGuard = headerName.toUpper().replace(QChar('.'), QChar('_'));
|
|
|
|
|
int pos = includeGuard.lastIndexOf('/');
|
|
|
|
|
if (pos != -1)
|
|
|
|
|
includeGuard = includeGuard.mid(pos + 1);
|
|
|
|
|
} else {
|
|
|
|
|
includeGuard = QString("QDBUSIDL2CPP_ADAPTOR");
|
|
|
|
|
}
|
|
|
|
|
includeGuard = QString("%1_%2%3")
|
|
|
|
|
.arg(includeGuard)
|
|
|
|
|
.arg(getpid())
|
|
|
|
|
.arg(QDateTime::currentDateTime().toTime_t());
|
|
|
|
|
hs << "#ifndef " << includeGuard << endl
|
|
|
|
|
<< "#define " << includeGuard << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
// include our stuff:
|
|
|
|
|
hs << "#include <QtCore/QObject>" << endl;
|
|
|
|
|
if (cppName == headerName)
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "#include <QtCore/QMetaObject>" << endl
|
|
|
|
|
<< "#include <QtCore/QVariant>" << endl;
|
|
|
|
|
hs << "#include <dbus/qdbus.h>" << endl;
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
if (cppName != headerName) {
|
|
|
|
|
writeHeader(cs, false);
|
|
|
|
|
cs << "#include \"" << headerName << "\"" << endl
|
|
|
|
|
<< "#include <QtCore/QMetaObject>" << endl
|
2006-03-28 18:56:08 +00:00
|
|
|
<< includeList
|
2006-03-06 15:27:56 +00:00
|
|
|
<< endl;
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << forwardDeclarations;
|
|
|
|
|
} else {
|
|
|
|
|
hs << includeList;
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << endl;
|
|
|
|
|
|
2006-03-06 15:27:56 +00:00
|
|
|
foreach (const QDBusIntrospection::Interface *interface, interfaces) {
|
|
|
|
|
QString className = classNameForInterface(interface->name, Adaptor);
|
|
|
|
|
|
|
|
|
|
// comment:
|
|
|
|
|
hs << "/*" << endl
|
|
|
|
|
<< " * Adaptor class for interface " << interface->name << endl
|
|
|
|
|
<< " */" << endl;
|
|
|
|
|
cs << "/*" << endl
|
|
|
|
|
<< " * Implementation of adaptor class " << className << endl
|
|
|
|
|
<< " */" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
// class header:
|
|
|
|
|
hs << "class " << className << ": public QDBusAbstractAdaptor" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " Q_OBJECT" << endl
|
|
|
|
|
<< " Q_CLASSINFO(\"D-Bus Interface\", \"" << interface->name << "\")" << endl
|
|
|
|
|
<< " Q_CLASSINFO(\"D-Bus Introspection\", \"\"" << endl
|
|
|
|
|
<< stringify(interface->introspection)
|
|
|
|
|
<< " \"\")" << endl
|
|
|
|
|
<< "public:" << endl
|
|
|
|
|
<< " " << className << "(QObject *parent);" << endl
|
|
|
|
|
<< " virtual ~" << className << "();" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
// constructor/destructor
|
|
|
|
|
cs << className << "::" << className << "(QObject *parent)" << endl
|
|
|
|
|
<< " : QDBusAbstractAdaptor(parent)" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " // constructor" << endl
|
|
|
|
|
<< " setAutoRelaySignals(true);" << endl
|
|
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl
|
|
|
|
|
<< className << "::~" << className << "()" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " // destructor" << endl
|
|
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
hs << "public: // PROPERTIES" << endl;
|
|
|
|
|
foreach (const QDBusIntrospection::Property &property, interface->properties) {
|
2006-03-28 18:56:08 +00:00
|
|
|
QByteArray type = qtTypeName(property.type);
|
2006-03-06 15:27:56 +00:00
|
|
|
QString constRefType = constRefArg(type);
|
2006-05-02 14:00:27 +00:00
|
|
|
QString getter = propertyGetter(property);
|
|
|
|
|
QString setter = propertySetter(property);
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
hs << " Q_PROPERTY(" << type << " " << property.name;
|
2006-03-06 15:27:56 +00:00
|
|
|
if (property.access != QDBusIntrospection::Property::Write)
|
|
|
|
|
hs << " READ " << getter;
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Read)
|
|
|
|
|
hs << " WRITE " << setter;
|
|
|
|
|
hs << ")" << endl;
|
|
|
|
|
|
|
|
|
|
// getter:
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Write) {
|
|
|
|
|
hs << " " << type << " " << getter << "() const;" << endl;
|
|
|
|
|
cs << type << " "
|
|
|
|
|
<< className << "::" << getter << "() const" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " // get the value of property " << property.name << endl
|
2006-05-02 14:00:27 +00:00
|
|
|
<< " return qvariant_cast< " << type <<" >(parent()->property(\"" << property.name << "\"));" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// setter
|
|
|
|
|
if (property.access != QDBusIntrospection::Property::Read) {
|
|
|
|
|
hs << " void " << setter << "(" << constRefType << "value);" << endl;
|
|
|
|
|
cs << "void " << className << "::" << setter << "(" << constRefType << "value)" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " // set the value of property " << property.name << endl
|
2006-05-02 14:00:27 +00:00
|
|
|
<< " parent()->setProperty(\"" << property.name << "\", value);" << endl
|
2006-03-06 15:27:56 +00:00
|
|
|
<< "}" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hs << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
hs << "public Q_SLOTS: // METHODS" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
foreach (const QDBusIntrospection::Method &method, interface->methods) {
|
|
|
|
|
bool isAsync = method.annotations.value(ANNOTATION_NO_WAIT) == "true";
|
|
|
|
|
if (isAsync && !method.outputArgs.isEmpty()) {
|
|
|
|
|
fprintf(stderr, "warning: method %s in interface %s is marked 'async' but has output arguments.\n",
|
|
|
|
|
qPrintable(method.name), qPrintable(interface->name));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hs << " ";
|
|
|
|
|
if (method.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
|
|
|
|
|
hs << "Q_DECL_DEPRECATED ";
|
2006-03-28 18:56:08 +00:00
|
|
|
|
|
|
|
|
QByteArray returnType;
|
2006-03-06 15:27:56 +00:00
|
|
|
if (isAsync) {
|
|
|
|
|
hs << "Q_ASYNC void ";
|
2006-03-28 18:56:08 +00:00
|
|
|
cs << "void ";
|
2006-03-06 15:27:56 +00:00
|
|
|
} else if (method.outputArgs.isEmpty()) {
|
|
|
|
|
hs << "void ";
|
|
|
|
|
cs << "void ";
|
|
|
|
|
} else {
|
2006-03-28 18:56:08 +00:00
|
|
|
returnType = qtTypeName(method.outputArgs.first().type);
|
|
|
|
|
hs << returnType << " ";
|
|
|
|
|
cs << returnType << " ";
|
2006-03-06 15:27:56 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
QString name = method.name;
|
2006-03-06 15:27:56 +00:00
|
|
|
hs << name << "(";
|
|
|
|
|
cs << className << "::" << name << "(";
|
|
|
|
|
|
|
|
|
|
QStringList argNames = makeArgNames(method.inputArgs, method.outputArgs);
|
|
|
|
|
writeArgList(hs, argNames, method.inputArgs, method.outputArgs);
|
|
|
|
|
writeArgList(cs, argNames, method.inputArgs, method.outputArgs);
|
|
|
|
|
|
|
|
|
|
hs << ");" << endl; // finished for header
|
|
|
|
|
cs << ")" << endl
|
|
|
|
|
<< "{" << endl
|
|
|
|
|
<< " // handle method call " << interface->name << "." << method.name << endl;
|
|
|
|
|
|
|
|
|
|
// create the return type
|
|
|
|
|
int j = method.inputArgs.count();
|
2006-03-28 18:56:08 +00:00
|
|
|
if (!returnType.isEmpty())
|
|
|
|
|
cs << " " << returnType << " " << argNames.at(j) << ";" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
// make the call
|
|
|
|
|
if (method.inputArgs.count() <= 10 && method.outputArgs.count() <= 1) {
|
|
|
|
|
// we can use QMetaObject::invokeMethod
|
2006-05-02 14:00:27 +00:00
|
|
|
static const char invoke[] = " QMetaObject::invokeMethod(parent(), \"";
|
2006-03-06 15:27:56 +00:00
|
|
|
cs << invoke << name << "\"";
|
|
|
|
|
|
|
|
|
|
if (!method.outputArgs.isEmpty())
|
|
|
|
|
cs << ", Q_RETURN_ARG("
|
2006-03-28 18:56:08 +00:00
|
|
|
<< qtTypeName(method.outputArgs.at(0).type)
|
2006-03-06 15:27:56 +00:00
|
|
|
<< ", "
|
|
|
|
|
<< argNames.at(method.inputArgs.count())
|
|
|
|
|
<< ")";
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < method.inputArgs.count(); ++i)
|
|
|
|
|
cs << ", Q_ARG("
|
2006-03-28 18:56:08 +00:00
|
|
|
<< qtTypeName(method.inputArgs.at(i).type)
|
2006-03-06 15:27:56 +00:00
|
|
|
<< ", "
|
|
|
|
|
<< argNames.at(i)
|
|
|
|
|
<< ")";
|
|
|
|
|
|
|
|
|
|
cs << ");" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cs << endl
|
|
|
|
|
<< " // Alternative:" << endl
|
|
|
|
|
<< " //";
|
|
|
|
|
if (!method.outputArgs.isEmpty())
|
|
|
|
|
cs << argNames.at(method.inputArgs.count()) << " = ";
|
2006-05-02 14:00:27 +00:00
|
|
|
cs << "static_cast<YourObjectType *>(parent())->" << name << "(";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
int argPos = 0;
|
|
|
|
|
bool first = true;
|
|
|
|
|
for (int i = 0; i < method.inputArgs.count(); ++i) {
|
|
|
|
|
cs << (first ? "" : ", ") << argNames.at(argPos++);
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
++argPos; // skip retval, if any
|
|
|
|
|
for (int i = 1; i < method.outputArgs.count(); ++i) {
|
|
|
|
|
cs << (first ? "" : ", ") << argNames.at(argPos++);
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cs << ");" << endl;
|
|
|
|
|
if (!method.outputArgs.isEmpty())
|
|
|
|
|
cs << " return " << argNames.at(method.inputArgs.count()) << ";" << endl;
|
|
|
|
|
cs << "}" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-02 14:00:27 +00:00
|
|
|
hs << "Q_SIGNALS: // SIGNALS" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
foreach (const QDBusIntrospection::Signal &signal, interface->signals_) {
|
|
|
|
|
hs << " ";
|
|
|
|
|
if (signal.annotations.value("org.freedesktop.DBus.Deprecated") == "true")
|
|
|
|
|
hs << "Q_DECL_DEPRECATED ";
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
hs << "void " << signal.name << "(";
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
QStringList argNames = makeArgNames(signal.outputArgs);
|
|
|
|
|
writeArgList(hs, argNames, signal.outputArgs);
|
|
|
|
|
|
|
|
|
|
hs << ");" << endl; // finished for header
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// close the class:
|
|
|
|
|
hs << "};" << endl
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// close the include guard
|
|
|
|
|
hs << "#endif" << endl;
|
2006-03-28 18:56:08 +00:00
|
|
|
|
|
|
|
|
if (includeMocs)
|
|
|
|
|
cs << endl
|
|
|
|
|
<< "#include \"" << adaptorFile << ".moc\"" << endl;
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
cs.flush();
|
|
|
|
|
hs.flush();
|
|
|
|
|
if (headerName == cppName)
|
|
|
|
|
file.write(cppData);
|
|
|
|
|
else {
|
|
|
|
|
// write to cpp file
|
|
|
|
|
QFile f(cppName);
|
|
|
|
|
f.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
|
|
|
|
|
f.write(cppData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
parseCmdLine(argc, argv);
|
|
|
|
|
|
|
|
|
|
QDBusIntrospection::Interfaces interfaces = readInput();
|
|
|
|
|
cleanInterfaces(interfaces);
|
|
|
|
|
|
|
|
|
|
writeProxy(proxyFile, interfaces);
|
|
|
|
|
|
|
|
|
|
if (adaptorFile)
|
|
|
|
|
writeAdaptor(adaptorFile, interfaces);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
2006-03-28 18:56:08 +00:00
|
|
|
\page dbusidl2cpp.html
|
|
|
|
|
\title QtDBus IDL compiler (dbusidl2cpp)
|
2006-03-06 15:27:56 +00:00
|
|
|
|
|
|
|
|
The QtDBus IDL compiler is a tool that can be used to parse interface descriptions and produce
|
|
|
|
|
static code representing those interfaces, which can then be used to make calls to remote
|
|
|
|
|
objects or implement said interfaces.
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
\c dbusidl2dcpp has two modes of operation, that correspond to the two possible outputs it can
|
|
|
|
|
produce: the interface (proxy) class or the adaptor class.The latter consists of both a C++
|
|
|
|
|
header and a source file, which are meant to be edited and adapted to your needs.
|
2006-03-06 15:27:56 +00:00
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
The \c dbusidl2dcpp tool is not meant to be run every time you compile your
|
2006-03-06 15:27:56 +00:00
|
|
|
application. Instead, it's meant to be used when developing the code or when the interface
|
|
|
|
|
changes.
|
|
|
|
|
|
2006-03-28 18:56:08 +00:00
|
|
|
The adaptor classes generated by \c dbusidl2cpp are just a skeleton that must be completed. It
|
2006-03-06 15:27:56 +00:00
|
|
|
generates, by default, calls to slots with the same name on the object the adaptor is attached
|
|
|
|
|
to. However, you may modify those slots or the property accessor functions to suit your needs.
|
|
|
|
|
*/
|