#include <QByteArray>
#include <QString>
#include <QVarLengthArray>
#include <QFile>
#include <QProcess>
#include <QMetaObject>
#include <QList>
#include <QRegExp>
#include <QCoreApplication>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "qdbusconnection.h"
Include dependency graph for qdbuscpp2xml.cpp:

Go to the source code of this file.
Classes | |
| class | MocParser |
Defines | |
| #define | PROGRAMNAME "dbuscpp2xml" |
| #define | PROGRAMVERSION "0.1" |
| #define | PROGRAMCOPYRIGHT "Copyright (C) 2006 Trolltech ASA. All rights reserved." |
Functions | |
| QDBUS_EXPORT QString | qDBusGenerateMetaObjectXml (QString interface, const QMetaObject *mo, const QMetaObject *base, int flags) |
| static void | showHelp () |
| static void | showVersion () |
| static void | parseCmdLine (QStringList &arguments) |
| int | main (int argc, char **argv) |
Variables | |
| static const char | docTypeHeader [] |
| static QString | outputFile |
| static int | flags |
| static const char | help [] |
| #define PROGRAMCOPYRIGHT "Copyright (C) 2006 Trolltech ASA. All rights reserved." |
| #define PROGRAMNAME "dbuscpp2xml" |
Definition at line 50 of file qdbuscpp2xml.cpp.
Referenced by MocParser::loadStringData(), main(), parseCmdLine(), MocParser::parseError(), showVersion(), and writeHeader().
| #define PROGRAMVERSION "0.1" |
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
Definition at line 349 of file qdbuscpp2xml.cpp.
References QCoreApplication::arguments(), QList< T >::at(), QFile::close(), QProcess::closeWriteChannel(), QByteArray::constData(), QByteArray::contains(), QList< T >::count(), QFile::decodeName(), docTypeHeader, QIODevice::errorString(), QProcess::exitCode(), QProcess::exitStatus(), flags, i, QString::isEmpty(), QProcess::NormalExit, MocParser::objects, QFile::open(), outputFile, MocParser::parse(), parseCmdLine(), PROGRAMNAME, qDBusGenerateMetaObjectXml(), QProcess::readAllStandardError(), QIODevice::readLine(), QIODevice::ReadOnly, QFile::setFileName(), QProcess::start(), QString::toLocal8Bit(), QProcess::waitForFinished(), QProcess::waitForStarted(), QIODevice::write(), and QIODevice::WriteOnly.
00350 { 00351 QCoreApplication app(argc, argv); 00352 QStringList args = app.arguments(); 00353 00354 MocParser parser; 00355 parseCmdLine(args); 00356 00357 for (int i = 1; i < args.count(); ++i) { 00358 const QString arg = args.at(i); 00359 if (arg.startsWith(QLatin1Char('-'))) 00360 continue; 00361 00362 QFile f(arg); 00363 if (!f.open(QIODevice::ReadOnly)) { 00364 fprintf(stderr, PROGRAMNAME ": could not open '%s': %s\n", 00365 qPrintable(arg), qPrintable(f.errorString())); 00366 return 1; 00367 } 00368 00369 f.readLine(); 00370 00371 QByteArray line = f.readLine(); 00372 if (line.contains("Meta object code from reading C++ file")) 00373 // this is a moc-generated file 00374 parser.parse(argv[i], &f, 3); 00375 else { 00376 // run moc on this file 00377 QProcess proc; 00378 proc.start(QLatin1String("moc"), QStringList() << QFile::decodeName(argv[i])); 00379 00380 if (!proc.waitForStarted()) { 00381 fprintf(stderr, PROGRAMNAME ": could not execute moc! Aborting.\n"); 00382 return 1; 00383 } 00384 00385 proc.closeWriteChannel(); 00386 00387 if (!proc.waitForFinished() || proc.exitStatus() != QProcess::NormalExit || 00388 proc.exitCode() != 0) { 00389 // output the moc errors: 00390 fprintf(stderr, "%s", proc.readAllStandardError().constData()); 00391 fprintf(stderr, PROGRAMNAME ": exit code %d from moc. Aborting\n", proc.exitCode()); 00392 return 1; 00393 } 00394 fprintf(stderr, "%s", proc.readAllStandardError().constData()); 00395 00396 parser.parse(argv[i], &proc, 1); 00397 } 00398 00399 f.close(); 00400 } 00401 00402 QFile output; 00403 if (outputFile.isEmpty()) { 00404 output.open(stdout, QIODevice::WriteOnly); 00405 } else { 00406 output.setFileName(outputFile); 00407 if (!output.open(QIODevice::WriteOnly)) { 00408 fprintf(stderr, PROGRAMNAME ": could not open output file '%s': %s", 00409 qPrintable(outputFile), qPrintable(output.errorString())); 00410 return 1; 00411 } 00412 } 00413 00414 output.write(docTypeHeader); 00415 output.write("<node>\n"); 00416 foreach (QMetaObject mo, parser.objects) { 00417 QString xml = qDBusGenerateMetaObjectXml(QString(), &mo, &QObject::staticMetaObject, 00418 flags); 00419 output.write(xml.toLocal8Bit()); 00420 } 00421 output.write("</node>\n"); 00422 00423 return 0; 00424 }
Here is the call graph for this function:

| static void parseCmdLine | ( | QStringList & | arguments | ) | [static] |
Definition at line 280 of file qdbuscpp2xml.cpp.
References QList< T >::at(), c, QList< T >::count(), QDBusConnection::ExportNonScriptableContents, QDBusConnection::ExportNonScriptableProperties, QDBusConnection::ExportNonScriptableSignals, QDBusConnection::ExportNonScriptableSlots, QDBusConnection::ExportScriptableContents, QDBusConnection::ExportScriptableProperties, QDBusConnection::ExportScriptableSignals, QDBusConnection::ExportScriptableSlots, flags, i, outputFile, printf, showHelp(), showVersion(), QString::startsWith(), and QList< T >::takeAt().
Referenced by main().
00281 { 00282 for (int i = 1; i < arguments.count(); ++i) { 00283 const QString arg = arguments.at(i); 00284 00285 if (arg == QLatin1String("--help")) 00286 showHelp(); 00287 00288 if (!arg.startsWith(QLatin1Char('-'))) 00289 continue; 00290 00291 char c = arg.count() == 2 ? arg.at(1).toLatin1() : char(0); 00292 switch (c) { 00293 case 'P': 00294 flags |= QDBusConnection::ExportNonScriptableProperties; 00295 // fall through 00296 case 'p': 00297 flags |= QDBusConnection::ExportScriptableProperties; 00298 break; 00299 00300 case 'S': 00301 flags |= QDBusConnection::ExportNonScriptableSignals; 00302 // fall through 00303 case 's': 00304 flags |= QDBusConnection::ExportScriptableSignals; 00305 break; 00306 00307 case 'M': 00308 flags |= QDBusConnection::ExportNonScriptableSlots; 00309 // fall through 00310 case 'm': 00311 flags |= QDBusConnection::ExportScriptableSlots; 00312 break; 00313 00314 case 'A': 00315 flags |= QDBusConnection::ExportNonScriptableContents; 00316 // fall through 00317 case 'a': 00318 flags |= QDBusConnection::ExportScriptableContents; 00319 break; 00320 00321 case 'o': 00322 if (arguments.count() < i + 2 || arguments.at(i + 1).startsWith(QLatin1Char('-'))) { 00323 printf("-o expects a filename\n"); 00324 exit(1); 00325 } 00326 outputFile = arguments.takeAt(i + 1); 00327 break; 00328 00329 case 'h': 00330 case '?': 00331 showHelp(); 00332 break; 00333 00334 case 'V': 00335 showVersion(); 00336 break; 00337 00338 default: 00339 printf("unknown option: \"%s\"\n", qPrintable(arg)); 00340 exit(1); 00341 } 00342 } 00343 00344 if (flags == 0) 00345 flags = QDBusConnection::ExportScriptableContents 00346 | QDBusConnection::ExportNonScriptableContents; 00347 }
Here is the call graph for this function:

| QDBUS_EXPORT QString qDBusGenerateMetaObjectXml | ( | QString | interface, | |
| const QMetaObject * | mo, | |||
| const QMetaObject * | base, | |||
| int | flags | |||
| ) |
| static void showHelp | ( | ) | [static] |
| static void showVersion | ( | ) | [static] |
Definition at line 273 of file qdbuscpp2xml.cpp.
References printf, PROGRAMNAME, and PROGRAMVERSION.
Referenced by parseCmdLine().
00274 { 00275 printf("%s version %s\n", PROGRAMNAME, PROGRAMVERSION); 00276 printf("D-Bus QObject-to-XML converter\n"); 00277 exit(0); 00278 }
const char docTypeHeader[] [static] |
Initial value:
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\" "
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
Definition at line 42 of file qdbuscpp2xml.cpp.
Referenced by main().
int flags [static] |
Definition at line 55 of file qdbuscpp2xml.cpp.
const char help[] [static] |
Initial value:
"Usage: " PROGRAMNAME " [options...] [files...]\n"
"Parses the C++ source or header file containing a QObject-derived class and\n"
"produces the D-Bus Introspection XML."
"\n"
"Options:\n"
" -p|-s|-m Only parse scriptable Properties, Signals and Methods (slots)\n"
" -P|-S|-M Parse all Properties, Signals and Methods (slots)\n"
" -a Output all scriptable contents (equivalent to -psm)\n"
" -A Output all contents (equivalent to -PSM)\n"
" -o <filename> Write the output to file <filename>\n"
" -h Show this information\n"
" -V Show the program version and quit.\n"
"\n"
Definition at line 57 of file qdbuscpp2xml.cpp.
Referenced by QVFb::createHelpMenu(), QApplication::notify(), QAccessibleWidgetEx::setHelp(), QAccessibleWidget::setHelp(), and showHelp().
QString outputFile [static] |
1.5.1