diff options
author | Rainer Keller <rainer.keller@digia.com> | 2013-06-10 12:33:32 +0200 |
---|---|---|
committer | Rainer Keller <rainer.keller@digia.com> | 2013-06-18 13:09:26 +0300 |
commit | 8495323475d78d76bf501f7d5c1966a3ca935fc3 (patch) | |
tree | 8bebf8012f1c2942b4d66a2869f4894010b8307f | |
parent | ec869fdb0a427fcfbb67d6126a69c1c980d2d60b (diff) |
Add platform information to config file
The config file may contain information about base system and platform.
The new option --show-platform prints these to stdout.
Change-Id: Idd64ca4527e808a83b8c10e6621b6ef431329110
Reviewed-by: Samuli Piippo <samuli.piippo@digia.com>
-rw-r--r-- | main.cpp | 46 | ||||
-rw-r--r-- | process.cpp | 37 | ||||
-rw-r--r-- | process.h | 10 |
3 files changed, 66 insertions, 27 deletions
@@ -6,6 +6,7 @@ #include <errno.h> #include <QStringList> #include <QSocketNotifier> +#include <QFile> #include <sys/socket.h> #include <sys/un.h> #include <unistd.h> @@ -109,6 +110,43 @@ static int findFirstFreePort(Utils::PortList range) return -1; } +static Config parseConfigFile() +{ + Config config; + config.base = config.platform = QLatin1String("unknown"); + +#ifdef Q_OS_ANDROID + QFile f("/system/bin/appcontroller.conf"); +#else + QFile f("/etc/appcontroller.conf"); +#endif + + if (!f.open(QFile::ReadOnly)) { + qWarning("Could not read config file."); + return config; + } + + while (!f.atEnd()) { + QString line = f.readLine(); + if (line.startsWith("env=")) { + QString sub = line.mid(4).simplified(); + int index = sub.indexOf('='); + if (index < 2) { + // ignore + } else + config.env[sub.left(index)] = sub.mid(index+1); + } else if (line.startsWith("append=")) { + config.args += line.mid(7).simplified(); + } else if (line.startsWith("base=")) { + config.base = line.mid(5).simplified(); + } else if (line.startsWith("platform=")) { + config.platform = line.mid(9).simplified(); + } + } + f.close(); + return config; +} + int main(int argc, char **argv) { // Save arguments before QCoreApplication handles them @@ -126,6 +164,8 @@ int main(int argc, char **argv) return 1; } + Config config = parseConfigFile(); + while (!args.isEmpty()) { if (args[0] == "--start") { if (args.size() < 2) { @@ -169,6 +209,11 @@ int main(int argc, char **argv) } else if (args[0] == "--stop") { stop(); return 0; + } else if (args[0] == "--show-platform") { + printf("base:%s\nplatform:%s\n", + config.base.toLocal8Bit().constData(), + config.platform.toLocal8Bit().constData()); + return 0; } else { qWarning("unknown argument: %s", args.first().toLocal8Bit().constData()); return 1; @@ -182,6 +227,7 @@ int main(int argc, char **argv) } Process process; + process.setConfig(config); if (debug) process.setDebug(); process.setSocketNotifier(new QSocketNotifier(serverSocket, QSocketNotifier::Read, &process)); diff --git a/process.cpp b/process.cpp index cb1ab2f..97781ac 100644 --- a/process.cpp +++ b/process.cpp @@ -87,35 +87,13 @@ void Process::startup(QStringList args) { QProcessEnvironment pe = QProcessEnvironment::systemEnvironment(); -#ifdef Q_OS_ANDROID - QFile f("/system/bin/appcontroller.conf"); -#else - QFile f("/etc/appcontroller.conf"); -#endif - - if (!f.open(QFile::ReadOnly)) { - qWarning("Could not read config file."); + foreach (const QString &key, mConfig.env.keys()) { + qDebug() << key << mConfig.env.value(key); + pe.insert(key, mConfig.env.value(key)); } - while (!f.atEnd()) { - QString line = f.readLine(); - if (line.startsWith("env=")) { - QString sub = line.mid(4).simplified(); - int index = sub.indexOf('='); - if (index < 2) { - // ignore - } else { - pe.insert(sub.left(index), sub.mid(index+1)); - qDebug() << sub.left(index) << sub.mid(index+1); - } - } else if (line.startsWith("append=")) { - args += line.mid(7).simplified(); - qDebug() << args; - } - } - - // env=... - // append=... + args.append(mConfig.args); + qDebug() << args; mProcess->setProcessEnvironment(pe); QString binary = args.first(); @@ -160,3 +138,8 @@ void Process::setSocketNotifier(QSocketNotifier *s) { connect(s, SIGNAL(activated(int)), this, SLOT(incomingConnection(int))); } + +void Process::setConfig(const Config &config) +{ + mConfig = config; +} @@ -1,8 +1,16 @@ #include <QObject> #include <QProcess> +#include <QMap> class QSocketNotifier; +struct Config { + QString base; + QString platform; + QMap<QString,QString> env; + QStringList args; +}; + class Process : public QObject { Q_OBJECT @@ -12,6 +20,7 @@ public: void start(const QStringList &args); void setSocketNotifier(QSocketNotifier*); void setDebug(); + void setConfig(const Config &); public slots: void stop(); private slots: @@ -25,4 +34,5 @@ private: QProcess *mProcess; int mDebuggee; bool mDebug; + Config mConfig; }; |