Renamed sample_blackgui -> swiftgui_standard and sample_blackcore -> swiftcore as discussed

This commit is contained in:
Klaus Basan
2014-08-03 01:56:04 +02:00
parent 18fe626db7
commit 34c9c5b7df
23 changed files with 13 additions and 37 deletions

80
src/swiftcore/main.cpp Normal file
View File

@@ -0,0 +1,80 @@
/* 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/networkutils.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/project.h"
#include <QtConcurrent/QtConcurrent>
#include <QMetaType>
#include <QMetaMethod>
#include <QApplication>
#include <QIcon>
#include <QTextStream>
/*!
* 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[])
{
// metadata are registered in runtime
QApplication a(argc, argv); // not QCoreApplication because of icon, http://qt-project.org/forums/viewthread/15412
QIcon icon(BlackMisc::CIcons::swiftNova24());
QApplication::setWindowIcon(icon);
QTextStream cin(stdin);
qDebug() << BlackMisc::CProject::version();
qDebug() << BlackMisc::CProject::compiledInfo();
qDebug();
qDebug() << "1 + la/ra .. session DBus server (default)";
qDebug() << "2 + la/ra .. system DBus server";
qDebug() << "3 + la/ra .. P2P DBus server";
qDebug() << "la .. local audio, audio runs in this core here (default)";
qDebug() << "ra .. remote audio, audio runs in the GUI or elsewhere";
qDebug() << "x .. exit";
QString input = cin.readLine().toLower().trimmed();
// configure DBus server
QString dBusAddress = BlackCore::CDBusServer::sessionDBusServer();
if (input.startsWith("2"))
{
dBusAddress = BlackCore::CDBusServer::systemDBusServer();
}
else if (input.startsWith("3"))
{
qDebug() << "found: " << BlackMisc::CNetworkUtils::getKnownIpAddresses();
qDebug() << "enter ip/port, e.g. 127.0.0.1:45000 (default)";
dBusAddress = cin.readLine().toLower();
dBusAddress = BlackCore::CDBusServer::p2pAddress(dBusAddress);
}
else if (input.startsWith("x"))
{
return 0;
}
// with remote audio
bool remoteAudio = input.contains("ra");
BlackCore::CRuntime *core = remoteAudio ?
new BlackCore::CRuntime(BlackCore::CRuntimeConfig::forCoreAllLocalInDBusNoAudio(dBusAddress), &a) :
new BlackCore::CRuntime(BlackCore::CRuntimeConfig::forCoreAllLocalInDBus(dBusAddress), &a);
// tool to allow input indepent from event loop
QtConcurrent::run(BlackMiscTest::Tool::serverLoop, core); // QFuture<void> future
qDebug() << "Server event loop, pid:" << BlackMiscTest::Tool::getPid() << "Thread id:" << QThread::currentThreadId();
// end
return a.exec();
}

BIN
src/swiftcore/swiftcore.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

View File

@@ -0,0 +1,38 @@
include (../../config.pri)
include (../../build.pri)
# widgets required for icon
QT += core dbus network xml multimedia gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = sample_blackcore
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG += blackmisc blacksound blackinput blackcore blacksim
DEPENDPATH += . ../../src/blackmisc ../../src/blacksound ../../src/blackcore ../../src/blacksim ../../src/blackinput
INCLUDEPATH += . ../../src
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
../../lib/blacksound.lib \
../../lib/blackcore.lib \
../../lib/blacksim.lib \
../../lib/blackinput.lib
else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
../../lib/libblacksound.a \
../../lib/libblackcore.a \
../../lib/libblacksim.a \
../../lib/libblackinput.a
DESTDIR = ../../bin
HEADERS += *.h
SOURCES += *.cpp
OTHER_FILES += swiftcore.ico swiftcore.rc
win32: RC_FILE = swiftcore.rc
include (../../libraries.pri)

View File

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

198
src/swiftcore/tool.cpp Normal file
View File

@@ -0,0 +1,198 @@
#include "tool.h"
#include "blackcore/context_all_interfaces.h"
#include "blackmisc/indexvariantmap.h"
#include "blackmisc/avallclasses.h"
#include "blackmisc/pqallquantities.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::PhysicalQuantities;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Audio;
namespace BlackMiscTest
{
/*
* Start a new process
*/
QProcess *Tool::startNewProcess(const QString &executable, const QStringList &arguments, QObject *parent)
{
QProcess *process = new QProcess(parent);
process->startDetached(executable, arguments);
return process;
}
/*
* Send data to testservice, this sends data to the slots on the server
*/
void Tool::serverLoop(BlackCore::CRuntime *runtime)
{
Q_ASSERT(runtime);
QThread::sleep(3); // let the DBus server startup
qDebug() << "Running on server here" << Tool::getPid() << "thread:" << QThread::currentThreadId();
//
// Server loop
//
QTextStream qtin(stdin);
QString line;
while (line != "x" && runtime)
{
BlackCore::IContextNetwork *networkContext = runtime->getIContextNetwork();
BlackCore::IContextAudio *audioContext = runtime->getIContextAudio();
BlackCore::IContextSettings *settingsContext = runtime->getIContextSettings();
BlackCore::IContextOwnAircraft *ownAircraftContext = runtime->getIContextOwnAircraft();
BlackCore::IContextApplication *applicationContext = runtime->getIContextApplication();
qDebug() << "-------------";
qDebug() << "Connected with network: " << networkContext->isConnected();
qDebug() << "Thread id:" << QThread::currentThreadId();
qDebug() << "-------------";
qDebug() << "x .. to exit 0 .. settings";
qDebug() << "1 .. ATC booked 2 .. ATC online";
qDebug() << "3 .. Aircrafts in range 4 .. my aircraft 5 .. voice rooms";
qDebug() << "6 .. vatlib audio devices 7 .. Qt audio devices";
qDebug() << "-------------";
qDebug() << "oe . redirect enabled od . disable redirect";
qDebug() << "-------------";
qDebug() << "signal / slot logging:";
qDebug() << "sig + context + [e]nabled/[d]isabled";
qDebug() << "slo + context + [e]nabled/[d]isabled";
qDebug() << "contexts: app / aud / net / own (aircraft) / set / sim / all";
qDebug() << "examples: sigappd, slonete, slosimd, sloalle";
qDebug() << "-------------";
line = qtin.readLine().toLower().trimmed();
if (line.startsWith("0"))
{
qDebug() << "-------------";
QString ret1;
QMetaObject::invokeMethod(settingsContext, "getSettingsFileName",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QString, ret1));
qDebug() << "Settings:" << ret1;
QMetaObject::invokeMethod(settingsContext, "getSettingsAsJsonString",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(QString, ret1));
qDebug() << "JSON" << ret1;
}
else if (line.startsWith("1"))
{
// remarks: use fully qualified name in Q_RETURN_ARG
qDebug() << "-------------";
qDebug() << "ATC booked";
CAtcStationList stations;
QMetaObject::invokeMethod(networkContext, "getAtcStationsBooked",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations));
qDebug() << stations;
}
else if (line.startsWith("2"))
{
qDebug() << "-------------";
qDebug() << "ATC online";
CAtcStationList stations;
QMetaObject::invokeMethod(networkContext, "getAtcStationsOnline",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Aviation::CAtcStationList, stations));
qDebug() << stations;
}
else if (line.startsWith("3"))
{
qDebug() << "-------------";
qDebug() << "aircrafts in range";
CAircraftList aircrafts;
QMetaObject::invokeMethod(networkContext, "getAircraftsInRange",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Aviation::CAircraftList, aircrafts));
qDebug() << aircrafts;
}
else if (line.startsWith("4"))
{
qDebug() << "-------------";
qDebug() << "my aircraft";
CAircraft aircraft;
QMetaObject::invokeMethod(ownAircraftContext, "getOwnAircraft",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Aviation::CAircraft, aircraft));
qDebug() << aircraft;
}
else if (line.startsWith("5"))
{
qDebug() << "-------------";
qDebug() << "voice rooms";
CVoiceRoomList voiceRooms;
QMetaObject::invokeMethod(audioContext, "getComVoiceRooms",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Audio::CVoiceRoomList, voiceRooms));
qDebug() << voiceRooms;
}
else if (line.startsWith("6"))
{
qDebug() << "-------------";
qDebug() << "vatlib audio devices";
CAudioDeviceList devices;
QMetaObject::invokeMethod(audioContext, "getAudioDevices",
Qt::BlockingQueuedConnection,
Q_RETURN_ARG(BlackMisc::Audio::CAudioDeviceList, devices));
qDebug() << devices;
}
else if (line.startsWith("7"))
{
qDebug() << "-------------";
qDebug() << "Qt audio devices";
BlackSound::CSoundGenerator::printAllQtSoundDevices();
}
else if (line.startsWith("oe"))
{
applicationContext->setOutputRedirectionLevel(IContextApplication::RedirectAllOutput);
applicationContext->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectAllOutput);
}
else if (line.startsWith("od"))
{
applicationContext->setOutputRedirectionLevel(IContextApplication::RedirectNone);
applicationContext->setStreamingForRedirectedOutputLevel(IContextApplication::RedirectNone);
}
else if (line.startsWith("sig"))
{
line.replace("signal", "");
line.replace("sig", "");
bool enable = line.endsWith("e");
if (line.startsWith("app")) runtime->signalLogForApplication(enable);
else if (line.startsWith("aud")) runtime->signalLogForAudio(enable);
else if (line.startsWith("net")) runtime->signalLogForNetwork(enable);
else if (line.startsWith("own")) runtime->signalLogForOwnAircraft(enable);
else if (line.startsWith("set")) runtime->signalLogForSettings(enable);
else if (line.startsWith("sim")) runtime->signalLogForSimulator(enable);
else if (line.startsWith("all")) runtime->signalLog(enable);
}
else if (line.startsWith("slo"))
{
line.replace("slot", "");
line.replace("slo", "");
bool enable = line.endsWith("e");
if (line.startsWith("app")) runtime->slotLogForApplication(enable);
else if (line.startsWith("aud")) runtime->slotLogForAudio(enable);
else if (line.startsWith("net")) runtime->slotLogForNetwork(enable);
else if (line.startsWith("own")) runtime->slotLogForOwnAircraft(enable);
else if (line.startsWith("set")) runtime->slotLogForSettings(enable);
else if (line.startsWith("sim")) runtime->slotLogForSimulator(enable);
else if (line.startsWith("all")) runtime->slotLog(enable);
}
}
QCoreApplication::quit();
}
} // namespace

38
src/swiftcore/tool.h Normal file
View File

@@ -0,0 +1,38 @@
#ifndef BLACKMISCTEST_Tool_H
#define BLACKMISCTEST_Tool_H
#include "blackcore/context_runtime.h"
#include <QCoreApplication>
#include <QProcess>
#include <QDBusConnection>
namespace BlackMiscTest
{
/*!
* \brief Supporting functions for running the tests
*/
class Tool
{
private:
//! \brief Constructor
Tool() {}
public:
//! \brief Get process id
static qint64 getPid()
{
return QCoreApplication::applicationPid();
}
//! Start a new process
static QProcess *startNewProcess(const QString &executable, const QStringList &arguments = QStringList(), QObject *parent = 0);
//! \brief Server loop
static void serverLoop(BlackCore::CRuntime *runtime);
};
} // namespace
#endif // guard