overte-AleziaKurdis/assignment-client/src/AssignmentClientApp.cpp
Seth Alves 4b3183d820 AssignmentClients accept an id on the command-line.
AssignmentClientMonitor now has a NodeList.  It stores its local port
in shared memory, like the DomainServer does.  As it spawns children,
it addes Nodes to the NodeList for each one.  The children send status
updates to the Monitor.  The Monitor will notice if there are no
spares and fork another child.
2015-02-19 17:44:06 -08:00

84 lines
2.2 KiB
C++

//
// AssignmentClientapp.cpp
// assignment-client/src
//
// Created by Seth Alves on 2/19/15.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QCommandLineParser>
#include <LogHandler.h>
#include <SharedUtil.h>
#include "Assignment.h"
#include "AssignmentClient.h"
#include "AssignmentClientMonitor.h"
#include "AssignmentClientApp.h"
AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) :
QApplication(argc, argv)
{
# ifndef WIN32
setvbuf(stdout, NULL, _IOLBF, 0);
# endif
// use the verbose message handler in Logging
qInstallMessageHandler(LogHandler::verboseMessageHandler);
// parse command-line
QCommandLineParser parser;
parser.setApplicationDescription("High Fidelity Assignment Client");
parser.addHelpOption();
const QCommandLineOption helpOption = parser.addHelpOption();
const QCommandLineOption numChildsOption("n", "number of children to fork", "child-count");
parser.addOption(numChildsOption);
const QCommandLineOption idOption("i", "assignment client id", "uuid");
parser.addOption(idOption);
if (!parser.parse(QCoreApplication::arguments())) {
qCritical() << parser.errorText() << endl;
parser.showHelp();
Q_UNREACHABLE();
}
if (parser.isSet(helpOption)) {
parser.showHelp();
Q_UNREACHABLE();
}
if (parser.isSet(numChildsOption) && parser.isSet(idOption)) {
qCritical() << "using both -i and -n doesn't make sense.";
parser.showHelp();
Q_UNREACHABLE();
}
unsigned int numForks = 0;
if (parser.isSet(numChildsOption)) {
numForks = parser.value(numChildsOption).toInt();
}
QUuid nodeUUID = QUuid::createUuid();
if (parser.isSet(idOption)) {
nodeUUID = QUuid(parser.value(idOption));
}
if (numForks) {
AssignmentClientMonitor monitor(argc, argv, numForks);
monitor.exec();
} else {
AssignmentClient client(argc, argv, nodeUUID);
client.exec();
}
}
AssignmentClientApp::~AssignmentClientApp() {
}