refs #429 Remove console version of swiftcore

This commit is contained in:
Roland Winklmeier
2015-05-23 17:47:03 +02:00
parent 141d256306
commit 0ee967a066
7 changed files with 0 additions and 306 deletions

View File

@@ -1,95 +0,0 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "tool.h"
#include "blackcore/context_runtime.h"
#include "blackcore/context_settings.h"
#include "blackcore/context_application.h"
#include "blackcore/context_application_impl.h"
#include "blackmisc/icons.h"
#include "blackmisc/worker.h"
#include "blackmisc/networkutils.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/project.h"
#include "blackmisc/loghandler.h"
#include <QtConcurrent/QtConcurrent>
#include <QMetaType>
#include <QMetaMethod>
#include <QApplication>
#include <QIcon>
#include <QTextStream>
using namespace BlackMisc;
using namespace BlackCore;
/*!
* DBus tests, tests marshalling / unmarshalling of many value classes.
* Forks two processes and sends data via DBus among them.
*/
int main(int argc, char *argv[])
{
CRuntime::registerMetadata(); // register metadata
QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412
QTextStream cin(stdin);
QTextStream cout(stdout);
cout << BlackMisc::CProject::version() << " " << BlackMisc::CProject::compiledInfo() << endl;
QIcon icon(BlackMisc::CIcons::swiftNova24());
QApplication::setWindowIcon(icon);
CLogHandler::instance()->install();
CLogHandler::instance()->enableConsoleOutput(false); // default disable
CLogHandler::instance()->handlerForPattern(
CLogPattern().withSeverityAtOrAbove(CStatusMessage::SeverityInfo)
)->enableConsoleOutput(true); // enable for info
cout << "1 + la/ra .. session DBus server (default)" << endl;
cout << "2 + la/ra .. system DBus server" << endl;
cout << "3 + la/ra .. P2P DBus server" << endl;
cout << "la .. local audio, audio runs in this core here (default)" << endl;
cout << "ra .. remote audio, audio runs in the GUI or elsewhere" << endl;
cout << "x .. exit" << endl;
QString input = cin.readLine().toLower().trimmed();
// configure DBus server
QString dBusAddress = CDBusServer::sessionDBusServer();
if (input.startsWith("2"))
{
dBusAddress = CDBusServer::systemDBusServer();
}
else if (input.startsWith("3"))
{
cout << "found: " << BlackMisc::CNetworkUtils::getKnownIpAddresses().join(' ') << endl;
cout << "enter ip/port, e.g. 127.0.0.1:45000 (default)" << endl;
dBusAddress = cin.readLine().toLower();
dBusAddress = CDBusServer::p2pAddress(dBusAddress);
}
else if (input.startsWith("x"))
{
return 0;
}
// with remote audio
bool remoteAudio = input.contains("ra");
CRuntime *coreRuntime = remoteAudio ?
new CRuntime(CRuntimeConfig::forCoreAllLocalInDBusNoAudio(dBusAddress), &a) :
new CRuntime(CRuntimeConfig::forCoreAllLocalInDBus(dBusAddress), &a);
// tool to allow input indepent from event loop
cout << "Will start server loop ... " << endl;
BlackMisc::CWorker *worker = BlackMisc::CWorker::fromTask(coreRuntime, "BlackMiscTest::Tool::serverLoop", [coreRuntime]()
{
BlackMiscTest::Tool::serverLoop(coreRuntime);
});
Q_UNUSED(worker);
cout << "Server event loop, pid: " << BlackMiscTest::Tool::getPid() << " Thread id: " << QThread::currentThreadId() << endl;
// end
return a.exec();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

View File

@@ -1,28 +0,0 @@
include ($$SourceRoot/config.pri)
include ($$SourceRoot/build.pri)
# widgets required for icon
QT += core dbus network xml multimedia gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = swiftcore
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG += blackmisc blacksound blackinput blackcore
DEPENDPATH += . $$SourceRoot/src/blackmisc \
$$SourceRoot/src/blacksound \
$$SourceRoot/src/blackcore \
$$SourceRoot/src/blackinput
INCLUDEPATH += . $$SourceRoot/src
HEADERS += *.h
SOURCES += *.cpp
OTHER_FILES += swiftcore.ico swiftcore.rc
win32: RC_FILE = swiftcore.rc
DESTDIR = $$BuildRoot/bin
include ($$SourceRoot/libraries.pri)

View File

@@ -1 +0,0 @@
IDI_ICON1 ICON DISCARDABLE "swiftcore.ico"

View File

@@ -1,146 +0,0 @@
#include "tool.h"
#include "blackcore/context_all_interfaces.h"
#include "blackmisc/propertyindexallclasses.h"
#include "blackmisc/aviation/aviation.h"
#include "blackmisc/pq/pq.h"
#include "blackmisc/loghandler.h"
#include "blackmisc/worker.h"
#include "blacksound/soundgenerator.h"
#include <QTextStream>
#include <QString>
#include <QFuture>
#include <QMetaObject>
#include <QGenericReturnArgument>
#include <QGenericArgument>
#include <QtConcurrent/QtConcurrent>
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Audio;
namespace BlackMiscTest
{
/*
* Send data to testservice, this sends data to the slots on the server
*/
void Tool::serverLoop(CRuntime *runtime)
{
QTextStream qtout(stdout);
qtout << "Running on server here " << Tool::getPid() << " thread: " << QThread::currentThreadId() << endl;
Q_ASSERT(runtime);
QThread::sleep(3); // time in secs, let the DBus server startup
// log initial severity
CLogSubscriber applicationMessageSubscriber, audioMessageSubscriber, networkMessageSubscriber, ownAircraftMessageSubscriber, settingsMessageSubscriber, simulatorMessageSubscriber;
CStatusMessage::StatusSeverity messageSeverity = CStatusMessage::SeverityInfo;
auto refreshSubscriptionSeverities = [ & ]()
{
applicationMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextApplication()).withSeverityAtOrAbove(messageSeverity));
audioMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextAudio()).withSeverityAtOrAbove(messageSeverity));
networkMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextNetwork()).withSeverityAtOrAbove(messageSeverity));
ownAircraftMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextOwnAircraft()).withSeverityAtOrAbove(messageSeverity));
settingsMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextSettings()).withSeverityAtOrAbove(messageSeverity));
simulatorMessageSubscriber.changeSubscription(CLogPattern::allOf(runtime->getIContextSimulator()).withSeverityAtOrAbove(messageSeverity));
};
refreshSubscriptionSeverities();
//
// Server loop
//
QTextStream qtin(stdin);
QString line;
while (line != "x" && runtime)
{
qtout << "-------------" << endl;
qtout << "Connected with network: " << BlackMisc::boolToYesNo(runtime->getIContextNetwork()->isConnected()) << endl;
qtout << "Thread id: " << QThread::currentThreadId() << endl;
qtout << "-------------" << endl;
qtout << "x .. to exit" << endl;
qtout << "0 .. settings 1 .. vatlib audio devices 2 .. Qt audio devices" << endl;
qtout << "h .. further commands" << endl;
qtout << "-------------" << endl;
line = qtin.readLine().toLower().trimmed();
if (line.startsWith("0"))
{
qtout << "-------------" << endl;
QString ret1;
QMetaObject::invokeMethod(runtime->getIContextSettings(), "getSettingsFileName",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QString, ret1));
qtout << "Settings: " << ret1 << endl;
QMetaObject::invokeMethod(runtime->getIContextSettings(), "getSettingsAsJsonString",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QString, ret1));
qtout << "JSON " << ret1 << endl;
}
else if (line.startsWith("1"))
{
qtout << "-------------" << endl;
qtout << "vatlib audio devices" << endl;
CAudioDeviceInfoList devices;
QMetaObject::invokeMethod(runtime->getIContextAudio(), "getAudioDevices",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Audio::CAudioDeviceInfoList, devices));
qtout << devices << endl;
}
else if (line.startsWith("2"))
{
qtout << "-------------" << endl;
qtout << "Qt audio devices" << endl;
BlackSound::CSoundGenerator::printAllQtSoundDevices(qtout);
}
else if (line.startsWith("level"))
{
line = line.replace("level", "").trimmed();
messageSeverity = CStatusMessage::stringToSeverity(line);
refreshSubscriptionSeverities();
qtout << "Changed level to " << CStatusMessage::severityToString(messageSeverity) << endl;
}
else if (line.startsWith("meta"))
{
BlackMisc::displayAllUserMetatypesTypes(qtout);
}
else if (line.startsWith("log"))
{
line.replace("log", "");
bool enable = line.endsWith("e");
if (line.startsWith("app") || line.startsWith("all")) { applicationMessageSubscriber.enableConsoleOutput(enable); }
if (line.startsWith("aud") || line.startsWith("all")) { audioMessageSubscriber.enableConsoleOutput(enable); }
if (line.startsWith("net") || line.startsWith("all")) { networkMessageSubscriber.enableConsoleOutput(enable); }
if (line.startsWith("own") || line.startsWith("all")) { ownAircraftMessageSubscriber.enableConsoleOutput(enable); }
if (line.startsWith("set") || line.startsWith("all")) { settingsMessageSubscriber.enableConsoleOutput(enable); }
if (line.startsWith("sim") || line.startsWith("all")) { simulatorMessageSubscriber.enableConsoleOutput(enable); }
}
else if (line.startsWith("h"))
{
qtout << "1) logging severity levels:" << endl;
qtout << " d, i, w, e example: level d for debug level" << endl;
qtout << "2) logging for contexts:" << endl;
qtout << " log + context + [e]nabled / [d]isabled" << endl;
qtout << " contexts: app / aud / net / own (aircraft) / set / sim / all" << endl;
qtout << " examples: logappd, lognete, logsimd, logalle" << endl;
qtout << "3) display metadata data: meta" << endl;
qtout << "4) all . commands can be used, e.g. .com1 127.35" << endl;
qtout << endl;
}
else if (line.startsWith("."))
{
// handle dot commands
bool c = runtime->parseCommandLine(line, COriginator("foo"));
if (c) { qtout << "Handled command " << line; }
else { qtout << "Not handled " << line; }
qtout << endl;
}
}
QCoreApplication::quit();
}
} // namespace

View File

@@ -1,35 +0,0 @@
#ifndef BLACKMISCTEST_Tool_H
#define BLACKMISCTEST_Tool_H
#include "blackcore/context_runtime.h"
#include <QCoreApplication>
#include <QProcess>
#include <QDBusConnection>
namespace BlackMiscTest
{
/*!
* Supporting functions for running the tests
*/
class Tool
{
private:
//! Constructor
Tool() {}
public:
//! Get process id
static qint64 getPid()
{
return QCoreApplication::applicationPid();
}
//! Server loop
static void serverLoop(BlackCore::CRuntime *runtime);
};
} // namespace
#endif // guard