summaryrefslogtreecommitdiff
path: root/resourceqt-client/resourceqt-client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'resourceqt-client/resourceqt-client.cpp')
-rw-r--r--resourceqt-client/resourceqt-client.cpp224
1 files changed, 30 insertions, 194 deletions
diff --git a/resourceqt-client/resourceqt-client.cpp b/resourceqt-client/resourceqt-client.cpp
index 522ce8d..e2468c5 100644
--- a/resourceqt-client/resourceqt-client.cpp
+++ b/resourceqt-client/resourceqt-client.cpp
@@ -1,210 +1,46 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QString>
#include <QtCore/QStringList>
-#include <stdlib.h>
-#include <errno.h>
-#include <libgen.h>
-#include <getopt.h>
#include "client.h"
+#include "commandlineparser.h"
-class CommandLineParser
-{
-public:
- CommandLineParser(int argc, char** argv) {
- exitCode = 0;
- exitFlag = false;
- exeName = strdup(basename(argv[0]));
-
- resourcesAll = 0;
- resourcesOptional = 0;
- autoRelease = false;
- alwaysReply = false;
-
- parseArguments(argc, argv);
- }
-
- ~CommandLineParser() {
- if (exeName != NULL) {
- delete exeName;
- exeName = NULL;
- }
- }
-
-public:
- bool exitFlag;
- int exitCode;
-
- uint32_t resourcesAll;
- uint32_t resourcesOptional;
- QString applicationClass;
- bool autoRelease;
- bool alwaysReply;
-
- void printMessage(const char *fmt, ...) {
- va_list ap;
- char fmtbuf[512];
-
- snprintf(fmtbuf, sizeof(fmtbuf), "%s\n", fmt);
- va_start(ap, fmt);
- vprintf(fmtbuf, ap);
- va_end(ap);
- }
-
-private:
- char* exeName;
-
- void printError(const char *fmt, ...) {
- va_list ap;
- char fmtbuf[512];
-
- snprintf(fmtbuf, sizeof(fmtbuf), "%s\n", fmt);
- va_start(ap, fmt);
- vprintf(fmtbuf, ap);
- va_end(ap);
-
- exitCode = errno;
- exitFlag = true;
- }
-
- void parseArguments(int argc, char** argv) {
- int option;
-
- while ((option = getopt(argc, argv, "hm:o:")) != -1) {
- switch (option) {
- case 'h':
- usage(0);
- return;
- case 'm':
- parseModeValues(optarg);
- break;
- case 'o':
- resourcesOptional = Client::parseResourceList(optarg);
- break;
- default:
- usage(EINVAL);
- return;
- }
- }
+bool verbose = true;
- if ((optind != argc - 2) && (optind != argc - 1)) {
- usage(EINVAL);
- return;
- }
- else {
- applicationClass = parseClassString(argv[optind]);
- if (argc > optind + 1)
- resourcesAll = Client::parseResourceList(argv[optind+1]);
- else
- resourcesAll = 0;
- }
-
- if (!resourcesAll) {
- printMessage("No resources found, use add command to add some ...");
- }
-
- if ((resourcesAll | resourcesOptional) != resourcesAll) {
- printError("optional resources are not subset of all resources");
- }
- }
-
- char* parseClassString(char *str) {
- if (strcmp(str, "call") &&
- strcmp(str, "camera") &&
- strcmp(str, "ringtone") &&
- strcmp(str, "alarm") &&
- strcmp(str, "navigator") &&
- strcmp(str, "game") &&
- strcmp(str, "player") &&
- strcmp(str, "event") &&
- strcmp(str, "background")) {
- printError("invalid class '%s'", str);
- return NULL;
- }
-
- return str;
- }
-
- void parseModeValues(QString modeListStr) {
- if (!modeListStr.isEmpty() && !modeListStr.isNull()) {
- QStringList modeList = modeListStr.split(",", QString::SkipEmptyParts);
-
- for (int i = 0; i < modeList.count(); i++) {
- if (modeList[i] == "AutoRelease") {
- autoRelease = true;
- }
- else if (modeList[i] == "AlwaysReply") {
- alwaysReply = true;
- }
- else {
- const char* mode = qPrintable(modeList[i]);
- printMessage("Ignoring unknown mode '%s'!", mode);
- }
- }
- }
- }
-
- void usage(int theExitCode) {
- printf("usage: %s [-h] [-m mode-values]"
- "[-o optional-resources] [-s shared-resources -m shared-mask] "
- "class all-resources\n",
- exeName);
- printf("\toptions:\n");
- printf("\t h\tprint this help message and exit\n");
- printf("\t m\tmode values. See 'modes' below for the "
- "\n\t\tsyntax of <mode-values>\n");
- printf("\t o\toptional resources. See 'resources' below for the "
- "syntax of\n\t\t<optional-resources>\n");
- printf("\tclass:\n");
- printf("\t\tcall\t - for native or 3rd party telephony\n");
- printf("\t\tcamera\t - for photo applications\n");
- printf("\t\tringtone - for ringtones\n");
- printf("\t\talarm\t - for alarm clock\n");
- printf("\t\tnavigator - for mapping applications\n");
- printf("\t\tgame\t - for gaming\n");
- printf("\t\tplayer\t - for media playback/recording\n");
- printf("\t\tevent\t - for messaging and other event notifications\n");
- printf("\t\tbackground - for thumbnailing etc\n");
- printf("\tresources:\n");
- printf("\t comma separated list of the following resources\n");
- printf("\t\tAudioPlayback\n");
- printf("\t\tVideoPlayback\n");
- printf("\t\tAudioRecording\n");
- printf("\t\tVideoRecording\n");
- printf("\t\tVibra\n");
- printf("\t\tLeds\n");
- printf("\t\tBackLight\n");
- printf("\t\tSystemButton\n");
- printf("\t\tLockButton\n");
- printf("\t\tScaleButton\n");
- printf("\t\tSnapButton\n");
- printf("\t\tLensCover\n");
- printf("\t\tHeadsetButtons\n");
- printf("\t no whitespace allowed in the resource list.\n");
- printf("\tmodes:\n");
- printf("\t comma separated list of the following modes\n");
- printf("\t\tAutoRelease\n");
- printf("\t\tAlwaysReply\n");
- fflush(stdout);
-
- exitCode = theExitCode;
- exitFlag = true;
+void debugOutput(QtMsgType type, const char *msg)
+{
+ switch (type) {
+ case QtDebugMsg:
+ if (verbose)
+ fprintf(stderr, "Debug: %s\n", msg);
+ break;
+ case QtWarningMsg:
+ fprintf(stderr, "Warning: %s\n", msg);
+ break;
+ case QtCriticalMsg:
+ fprintf(stderr, "Critical: %s\n", msg);
+ break;
+ case QtFatalMsg:
+ fprintf(stderr, "Fatal: %s\n", msg);
+ abort();
}
-};
+}
int main(int argc, char *argv[])
{
- CommandLineParser parser(argc, argv);
-
- if (parser.exitFlag)
- return parser.exitCode;
-
+ qInstallMsgHandler(debugOutput);
QCoreApplication app(argc, argv);
+ CommandLineParser parser;
+ Client client;
+
+ if (!parser.parseArguments()) {
+ return 1;
+ }
- Client client(parser.applicationClass);
- if (!client.initialize(parser.resourcesAll, parser.resourcesOptional, parser.alwaysReply, parser.autoRelease)) {
- parser.printMessage("initialization failed!");
- return EINVAL;
+ if (!client.initialize(parser)) {
+ printf("Initialization failed\n");
+ return 2;
}
return app.exec();
}
+