summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAaron McCarthy <aaron.mccarthy@nokia.com>2011-03-21 17:15:39 +1000
committerAaron McCarthy <aaron.mccarthy@nokia.com>2011-03-21 17:23:44 +1000
commit4879306444075bb59788463822f529b3940d7804 (patch)
tree79dec629e9d894dfdcb4d3b6a6875aeac6adc27a /tools
parent3b0987224b6120788d146bf8e1e483668130b0cb (diff)
Add ndefhandlergen tool.
This tool facilitates generating the platform specific registration files required to implement NDEF message handlers on both Symbian^3 and Maemo6 platforms.
Diffstat (limited to 'tools')
-rw-r--r--tools/ndefhandlergen/main.cpp213
-rw-r--r--tools/ndefhandlergen/ndefhandlergen.pro26
-rw-r--r--tools/ndefhandlergen/templates.qrc9
-rw-r--r--tools/ndefhandlergen/templates/maemo6/maemo6.conf6
-rw-r--r--tools/ndefhandlergen/templates/maemo6/maemo6.postinst10
-rw-r--r--tools/ndefhandlergen/templates/maemo6/maemo6.prerm7
-rw-r--r--tools/ndefhandlergen/templates/maemo6/maemo6.service4
-rw-r--r--tools/ndefhandlergen/templates/symbian/symbian.xml15
-rw-r--r--tools/tools.pro4
9 files changed, 294 insertions, 0 deletions
diff --git a/tools/ndefhandlergen/main.cpp b/tools/ndefhandlergen/main.cpp
new file mode 100644
index 0000000000..591e7d2f74
--- /dev/null
+++ b/tools/ndefhandlergen/main.cpp
@@ -0,0 +1,213 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Qt Mobility Components.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QCoreApplication>
+#include <QtCore/QResource>
+#include <QtCore/QDir>
+
+#include <QtCore/QDebug>
+
+static const QLatin1String applicationNameTag("%APPNAME%");
+static const QLatin1String applicationPathTag("%APPPATH%");
+static const QLatin1String dataTypeTag("%DATATYPE%");
+
+struct Data
+{
+ QString templateName;
+ QString applicationName;
+ QString applicationPath;
+ QString dataType;
+ QString matchString;
+};
+
+void showHelp()
+{
+ qWarning("Generate platform specific NFC message handler registration files.\n"
+ "Usage: nfcxmlgen [options]\n"
+ "\n"
+ " -template TEMPLATE Template to use.\n"
+ " -appname APPNAME Name of the application.\n"
+ " -apppath APPPATH Path to installed application binary.\n"
+ " -datatype DATATYPE URN of the NDEF message type to match.\n"
+ " -match MATCHSTRING Platform specific match string.\n"
+ "\n"
+ "The -datatype and -match options are mutually exclusive.\n");
+
+ QDir templates(QLatin1String(":/templates"));
+ qWarning("Available templates: %s\n", qPrintable(templates.entryList().join(QLatin1String(", "))));
+}
+
+bool processTemplateFile(const QString &templateFile, const QString &outputFile, const Data &data)
+{
+ QResource resource(templateFile);
+ if (!resource.isValid())
+ return false;
+
+ QString templateData =
+ QString::fromUtf8(reinterpret_cast<const char *>(resource.data()), resource.size());
+
+ templateData.replace(applicationNameTag, data.applicationName);
+ templateData.replace(applicationPathTag, data.applicationPath);
+ templateData.replace(dataTypeTag, data.matchString);
+
+ QFile output(outputFile);
+ if (!output.open(QIODevice::WriteOnly))
+ return false;
+
+ output.write(templateData.toUtf8());
+ output.close();
+
+ qWarning("%s", qPrintable(templateData));
+
+ return true;
+}
+
+bool generateSymbian(Data data)
+{
+ const QString outputFile = QLatin1String("ndefhandler_") + data.applicationName +
+ QLatin1String(".xml");
+
+ if (data.matchString.isEmpty())
+ data.matchString = data.dataType;
+
+ return processTemplateFile(QLatin1String("/templates/symbian/symbian.xml"), outputFile, data);
+}
+
+
+
+bool generateMaemo6(Data data)
+{
+ const QString outputFile = QLatin1String("ndefhandler_") + data.applicationName;
+
+ if (data.matchString.isEmpty())
+ data.matchString = data.dataType + QLatin1String("[1:*];");
+
+ bool success = false;
+
+ success |= processTemplateFile(QLatin1String("/templates/maemo6/maemo6.conf"),
+ outputFile + QLatin1String(".conf"), data);
+ success |= processTemplateFile(QLatin1String("/templates/maemo6/maemo6.service"),
+ outputFile + QLatin1String(".service"), data);
+ success |= processTemplateFile(QLatin1String("/templates/maemo6/maemo6.postinst"),
+ outputFile + QLatin1String(".postinst"), data);
+ success |= processTemplateFile(QLatin1String("/templates/maemo6/maemo6.prerm"),
+ outputFile + QLatin1String(".prerm"), data);
+
+ return success;
+}
+
+bool checkInput(const Data &data)
+{
+ if (data.templateName.isEmpty()) {
+ qWarning("Error: -template option must be provided.\n");
+ return false;
+ }
+ if (data.templateName != QLatin1String("symbian") &&
+ data.templateName != QLatin1String("maemo6")) {
+ qWarning("Error: Invalid template name specified, %s\n", qPrintable(data.templateName));
+ return false;
+ }
+ if (data.applicationName.isEmpty()) {
+ qWarning("Error: -appname option must be provided.\n");
+ return false;
+ }
+ if (data.templateName == QLatin1String("maemo6") && data.applicationPath.isEmpty()) {
+ qWarning("Error: -apppath option must be provided.\n");
+ return false;
+ }
+ if (!data.dataType.isEmpty() && !data.matchString.isEmpty()) {
+ qWarning("Error: -datatype and -match are mutually exclusive.\n");
+ return false;
+ }
+
+ return true;
+}
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication a(argc, argv);
+
+ Data data;
+
+ QListIterator<QString> i(a.arguments());
+ if (i.hasNext())
+ i.next(); // skip over first argument
+
+ if (!i.hasNext()) {
+ showHelp();
+ return 0;
+ }
+
+ while (i.hasNext()) {
+ const QString &arg = i.next();
+
+ if (arg == QLatin1String("-template") && i.hasNext()) {
+ data.templateName = i.next();
+ } else if (arg == QLatin1String("-appname") && i.hasNext()) {
+ data.applicationName = i.next();
+ } else if (arg == QLatin1String("-apppath") && i.hasNext()) {
+ data.applicationPath = i.next();
+ } else if (arg == QLatin1String("-datatype") && i.hasNext()) {
+ data.dataType = i.next();
+ } else if (arg == QLatin1String("-match") && i.hasNext()) {
+ data.matchString = i.next();
+ } else if (arg == QLatin1String("-help")) {
+ showHelp();
+ return 0;
+ } else {
+ qWarning("Unknown Option %s\n", qPrintable(arg));
+ }
+ }
+
+ if (!checkInput(data)) {
+ showHelp();
+ return 1;
+ }
+
+ bool success = false;
+
+ if (data.templateName == QLatin1String("symbian"))
+ success = generateSymbian(data);
+ else if (data.templateName == QLatin1String("maemo6"))
+ success = generateMaemo6(data);
+
+ return success ? 0 : 1;
+}
diff --git a/tools/ndefhandlergen/ndefhandlergen.pro b/tools/ndefhandlergen/ndefhandlergen.pro
new file mode 100644
index 0000000000..6c80a6ef0f
--- /dev/null
+++ b/tools/ndefhandlergen/ndefhandlergen.pro
@@ -0,0 +1,26 @@
+QT += core
+
+QT -= gui
+
+TARGET = ndefhandlergen
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += main.cpp
+
+RESOURCES += \
+ templates.qrc
+
+OTHER_FILES += \
+ templates/symbian/symbian.xml \
+ templates/maemo6/maemo6.conf \
+ templates/maemo6/maemo6.service \
+ templates/maemo6/maemo6.postinst \
+ templates/maemo6/maemo6.prerm
+
+include(../../common.pri)
+include(../../features/deploy.pri)
+
diff --git a/tools/ndefhandlergen/templates.qrc b/tools/ndefhandlergen/templates.qrc
new file mode 100644
index 0000000000..eabc5283c1
--- /dev/null
+++ b/tools/ndefhandlergen/templates.qrc
@@ -0,0 +1,9 @@
+<RCC>
+ <qresource prefix="/">
+ <file>templates/maemo6/maemo6.conf</file>
+ <file>templates/maemo6/maemo6.postinst</file>
+ <file>templates/maemo6/maemo6.prerm</file>
+ <file>templates/maemo6/maemo6.service</file>
+ <file>templates/symbian/symbian.xml</file>
+ </qresource>
+</RCC>
diff --git a/tools/ndefhandlergen/templates/maemo6/maemo6.conf b/tools/ndefhandlergen/templates/maemo6/maemo6.conf
new file mode 100644
index 0000000000..b7ed1c8442
--- /dev/null
+++ b/tools/ndefhandlergen/templates/maemo6/maemo6.conf
@@ -0,0 +1,6 @@
+<busconfig>
+ <!-- we trust that no one else is going to squat on our service -->
+ <policy context="default">
+ <allow own="com.nokia.qtmobility.nfc.%APPNAME%"/>
+ </policy>
+</busconfig>
diff --git a/tools/ndefhandlergen/templates/maemo6/maemo6.postinst b/tools/ndefhandlergen/templates/maemo6/maemo6.postinst
new file mode 100644
index 0000000000..1aaa542ea4
--- /dev/null
+++ b/tools/ndefhandlergen/templates/maemo6/maemo6.postinst
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+dbus-send --system --type=method_call --dest=com.nokia.nfc / \
+ com.nokia.nfc.Manager.RegisterNDEFHandler \
+ string:system \
+ string:com.nokia.qtmobility.nfc.%APPNAME% \
+ objpath:/com/nokia/nfc/ndefhandler \
+ string:any \
+ string:"%DATATYPE%" \
+ string:%APPNAME%
diff --git a/tools/ndefhandlergen/templates/maemo6/maemo6.prerm b/tools/ndefhandlergen/templates/maemo6/maemo6.prerm
new file mode 100644
index 0000000000..aa1159331d
--- /dev/null
+++ b/tools/ndefhandlergen/templates/maemo6/maemo6.prerm
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+dbus-send --system --type=method_call --dest=com.nokia.nfc / \
+ com.nokia.nfc.Manager.UnregisterNDEFHandler \
+ string:system \
+ string:com.nokia.qtmobility.nfc.%APPNAME% \
+ objpath:/com/nokia/nfc/ndefhandler
diff --git a/tools/ndefhandlergen/templates/maemo6/maemo6.service b/tools/ndefhandlergen/templates/maemo6/maemo6.service
new file mode 100644
index 0000000000..39bbe3914c
--- /dev/null
+++ b/tools/ndefhandlergen/templates/maemo6/maemo6.service
@@ -0,0 +1,4 @@
+[D-BUS Service]
+Name=com.nokia.qtmobility.nfc.%APPNAME%
+Exec=%APPPATH%
+User=user
diff --git a/tools/ndefhandlergen/templates/symbian/symbian.xml b/tools/ndefhandlergen/templates/symbian/symbian.xml
new file mode 100644
index 0000000000..7ca8f0a77a
--- /dev/null
+++ b/tools/ndefhandlergen/templates/symbian/symbian.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<SFW version="1.1">
+ <service>
+ <name>%APPNAME%</name>
+ <ipcaddress>%APPNAME%</ipcaddress>
+ <description>NFC NDEF message handler for %APPNAME%</description>
+ <interface>
+ <name>com.nokia.symbian.NdefMessageHandler</name>
+ <version>1.0</version>
+ <description>NFC NDEF message handler for %APPNAME%</description>
+ <capabilities></capabilities>
+ <customproperty key="datatype">%DATATYPE%</customproperty>
+ </interface>
+ </service>
+</SFW>
diff --git a/tools/tools.pro b/tools/tools.pro
index ba62bddbfc..b4e66a0170 100644
--- a/tools/tools.pro
+++ b/tools/tools.pro
@@ -12,3 +12,7 @@ contains(mobility_modules,serviceframework) {
contains(mobility_modules,publishsubscribe) {
SUBDIRS += vsexplorer qcrmlgen #P&S API
}
+
+contains(mobility_modules,connectivity) {
+ SUBDIRS += ndefhandlergen
+}