summaryrefslogtreecommitdiff
path: root/src/pmtime/main.cpp
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
commit47e6e7c84f008a53061e661f31ae96629bc694ef (patch)
tree648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /src/pmtime/main.cpp
downloadpcp-debian.tar.gz
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'src/pmtime/main.cpp')
-rw-r--r--src/pmtime/main.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/pmtime/main.cpp b/src/pmtime/main.cpp
new file mode 100644
index 0000000..3e85e63
--- /dev/null
+++ b/src/pmtime/main.cpp
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2014, Red Hat.
+ * Copyright (c) 2006, Ken McDonell. All Rights Reserved.
+ * Copyright (c) 2006-2007, Aconex. All Rights Reserved.
+ *
+ * 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.
+ */
+#include <QtGui/QApplication>
+#include <pcp/pmapi.h>
+#include <pcp/impl.h>
+#include "timelord.h"
+#include "pmtime.h"
+
+static pmOptions opts;
+static pmLongOptions longopts[] = {
+ PMAPI_OPTIONS_HEADER("Options"),
+ PMOPT_GUIPORT,
+ PMOPT_VERSION,
+ PMOPT_HELP,
+ PMAPI_OPTIONS_END
+};
+
+static void setupEnvironment(void)
+{
+ char *value;
+ QString confirm = pmGetConfig("PCP_BIN_DIR");
+ confirm.prepend("PCP_XCONFIRM_PROG=");
+ confirm.append(QChar(__pmPathSeparator()));
+ confirm.append("pmquery");
+ if ((value = strdup((const char *)confirm.toAscii())) != NULL)
+ putenv(value);
+ if (getenv("PCP_STDERR") == NULL && // do not overwrite, for QA
+ ((value = strdup("PCP_STDERR=DISPLAY")) != NULL))
+ putenv(value);
+
+ QCoreApplication::setOrganizationName("PCP");
+ QCoreApplication::setApplicationName("pmtime");
+}
+
+int main(int argc, char **argv)
+{
+ int autoport = 0;
+
+ QApplication a(argc, argv);
+ setupEnvironment();
+
+ opts.short_options = "D:p:V?";
+ opts.long_options = longopts;
+ pmGetOptions(argc, argv, &opts);
+ if (opts.errors || opts.optind != argc) {
+ pmUsageMessage(&opts);
+ exit(1);
+ }
+
+ if (!opts.guiport) {
+ char *endnum, *envstr;
+
+ autoport = 1;
+ if ((envstr = getenv("PMTIME_PORT")) == NULL) {
+ opts.guiport = PmTime::BasePort;
+ } else {
+ opts.guiport = strtol(envstr, &endnum, 0);
+ if (*endnum != '\0' || opts.guiport < 0) {
+ pmprintf(
+ "%s: PMTIME_PORT must be a numeric port number (not %s)\n",
+ pmProgname, envstr);
+ pmflush();
+ exit(1);
+ }
+ }
+ }
+
+ console = new Console;
+ TimeLord tl(&a);
+ do {
+ if (tl.listen(QHostAddress::LocalHost, opts.guiport))
+ break;
+ opts.guiport++;
+ } while (autoport && (opts.guiport >= 0));
+
+ if (!opts.guiport || tl.isListening() == false) {
+ if (!autoport)
+ pmprintf("%s: cannot find an available port\n", pmProgname);
+ else
+ pmprintf("%s: cannot connect to requested port (%d)\n",
+ pmProgname, opts.guiport);
+ pmflush();
+ exit(1);
+ } else if (autoport) { /* write to stdout for client */
+ char name[32];
+ int c = snprintf(name, sizeof(name), "port=%u\n", opts.guiport);
+ if (write(fileno(stdout), name, c + 1) < 0) {
+ if (errno != EPIPE) {
+ pmprintf("%s: cannot write port for client: %s\n",
+ pmProgname, strerror(errno));
+ pmflush();
+ }
+ exit(1);
+ }
+ }
+
+ PmTimeLive hc;
+ PmTimeArch ac;
+ tl.setContext(&hc, &ac);
+
+ hc.init();
+ if (!pmDebug) hc.disableConsole();
+ else hc.popup(1);
+
+ ac.init();
+ if (!pmDebug) ac.disableConsole();
+ else ac.popup(1);
+
+ a.exec();
+ return 0;
+}