mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
sample console-based client to demonstrate INetwork interface (refs #22)
This commit is contained in:
7
samples/cli_client/CMakeLists.txt
Normal file
7
samples/cli_client/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
FILE(GLOB SRC *.cpp)
|
||||
SET(HEADERS *.h)
|
||||
|
||||
ADD_EXECUTABLE(sample_cli_client ${SRC})
|
||||
|
||||
TARGET_LINK_LIBRARIES(sample_cli_client blackmisc ${QT_LIBRARIES})
|
||||
SET_TARGET_PROPERTIES(sample_cli_client PROPERTIES PROJECT_LABEL "Samples - CLI Client")
|
||||
422
samples/cli_client/client.cpp
Normal file
422
samples/cli_client/client.cpp
Normal file
@@ -0,0 +1,422 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "client.h"
|
||||
#include "blackmisc/context.h"
|
||||
#include <iostream>
|
||||
#include <QStringList>
|
||||
|
||||
Client::Client()
|
||||
: m_net(BlackMisc::IContext::getInstance().singleton<BlackCore::INetwork>())
|
||||
{
|
||||
using namespace BlackCore;
|
||||
connect(m_net, &INetwork::atcPositionUpdate, this, &Client::atcPositionUpdate);
|
||||
connect(m_net, &INetwork::atcDisconnected, this, &Client::atcDisconnected);
|
||||
connect(m_net, &INetwork::connectionStatusIdle, this, &Client::connectionStatusIdle);
|
||||
connect(m_net, &INetwork::connectionStatusConnecting, this, &Client::connectionStatusConnecting);
|
||||
connect(m_net, &INetwork::connectionStatusConnected, this, &Client::connectionStatusConnected);
|
||||
connect(m_net, &INetwork::connectionStatusDisconnected, this, &Client::connectionStatusDisconnected);
|
||||
connect(m_net, &INetwork::connectionStatusError, this, &Client::connectionStatusError);
|
||||
connect(m_net, &INetwork::ipQueryReplyReceived, this, &Client::ipQueryReplyReceived);
|
||||
connect(m_net, &INetwork::freqQueryReplyReceived, this, &Client::freqQueryReplyReceived);
|
||||
connect(m_net, &INetwork::serverQueryReplyReceived, this, &Client::serverQueryReplyReceived);
|
||||
connect(m_net, &INetwork::atcQueryReplyReceived, this, &Client::atcQueryReplyReceived);
|
||||
connect(m_net, &INetwork::atisQueryReplyReceived, this, &Client::atisQueryReplyReceived);
|
||||
connect(m_net, &INetwork::nameQueryReplyReceived, this, &Client::nameQueryReplyReceived);
|
||||
connect(m_net, &INetwork::capabilitiesQueryReplyReceived, this, &Client::capabilitiesQueryReplyReceived);
|
||||
connect(m_net, &INetwork::freqQueryRequestReceived, this, &Client::freqQueryRequestReceived);
|
||||
connect(m_net, &INetwork::nameQueryRequestReceived, this, &Client::nameQueryRequestReceived);
|
||||
connect(m_net, &INetwork::kicked, this, &Client::kicked);
|
||||
connect(m_net, &INetwork::metarReceived, this, &Client::metarReceived);
|
||||
connect(m_net, &INetwork::pilotDisconnected, this, &Client::pilotDisconnected);
|
||||
connect(m_net, &INetwork::planeInfoReceived, this, &Client::planeInfoReceived);
|
||||
connect(m_net, &INetwork::planeInfoRequestReceived, this, &Client::planeInfoRequestReceived);
|
||||
connect(m_net, &INetwork::pong, this, &Client::pong);
|
||||
connect(m_net, &INetwork::radioTextMessageReceived, this, &Client::radioTextMessageReceived);
|
||||
connect(m_net, &INetwork::privateTextMessageReceived, this, &Client::privateTextMessageReceived);
|
||||
|
||||
connect(this, &Client::setServerDetails, m_net, &INetwork::setServerDetails);
|
||||
connect(this, &Client::setUserCredentials, m_net, &INetwork::setUserCredentials);
|
||||
connect(this, &Client::setCallsign, m_net, &INetwork::setCallsign);
|
||||
connect(this, &Client::setRealName, m_net, &INetwork::setRealName);
|
||||
connect(this, &Client::initiateConnection, m_net, &INetwork::initiateConnection);
|
||||
connect(this, &Client::terminateConnection, m_net, &INetwork::terminateConnection);
|
||||
connect(this, &Client::sendPrivateTextMessage, m_net, &INetwork::sendPrivateTextMessage);
|
||||
connect(this, &Client::sendRadioTextMessage, m_net, &INetwork::sendRadioTextMessage);
|
||||
connect(this, &Client::sendIpQuery, m_net, &INetwork::sendIpQuery);
|
||||
connect(this, &Client::sendFreqQuery, m_net, &INetwork::sendFreqQuery);
|
||||
connect(this, &Client::sendServerQuery, m_net, &INetwork::sendServerQuery);
|
||||
connect(this, &Client::sendAtcQuery, m_net, &INetwork::sendAtcQuery);
|
||||
connect(this, &Client::sendAtisQuery, m_net, &INetwork::sendAtisQuery);
|
||||
connect(this, &Client::sendNameQuery, m_net, &INetwork::sendNameQuery);
|
||||
connect(this, &Client::sendCapabilitiesQuery, m_net, &INetwork::sendCapabilitiesQuery);
|
||||
connect(this, &Client::replyToFreqQuery, m_net, &INetwork::replyToFreqQuery);
|
||||
connect(this, &Client::replyToNameQuery, m_net, &INetwork::replyToNameQuery);
|
||||
connect(this, &Client::requestPlaneInfo, m_net, &INetwork::requestPlaneInfo);
|
||||
connect(this, &Client::sendPlaneInfo, m_net, &INetwork::sendPlaneInfo);
|
||||
connect(this, &Client::ping, m_net, &INetwork::ping);
|
||||
connect(this, &Client::requestMetar, m_net, &INetwork::requestMetar);
|
||||
connect(this, &Client::requestWeatherData, m_net, &INetwork::requestWeatherData);
|
||||
|
||||
using namespace std::placeholders;
|
||||
m_commands["help"] = std::bind(&Client::help, this, _1);
|
||||
m_commands["echo"] = std::bind(&Client::echo, this, _1);
|
||||
m_commands["exit"] = std::bind(&Client::exit, this, _1);
|
||||
m_commands["setserver"] = std::bind(&Client::setServerDetailsCmd, this, _1);
|
||||
m_commands["setuser"] = std::bind(&Client::setUserCredentialsCmd, this, _1);
|
||||
m_commands["setcallsign"] = std::bind(&Client::setCallsignCmd, this, _1);
|
||||
m_commands["setrealname"] = std::bind(&Client::setRealNameCmd, this, _1);
|
||||
m_commands["initconnect"] = std::bind(&Client::initiateConnectionCmd, this, _1);
|
||||
m_commands["termconnect"] = std::bind(&Client::terminateConnectionCmd, this, _1);
|
||||
m_commands["privmsg"] = std::bind(&Client::sendPrivateTextMessageCmd, this, _1);
|
||||
m_commands["textmsg"] = std::bind(&Client::sendRadioTextMessageCmd, this, _1);
|
||||
m_commands["ip"] = std::bind(&Client::sendIpQueryCmd, this, _1);
|
||||
m_commands["freq"] = std::bind(&Client::sendFreqQueryCmd, this, _1);
|
||||
m_commands["server"] = std::bind(&Client::sendServerQueryCmd, this, _1);
|
||||
m_commands["atc"] = std::bind(&Client::sendAtcQueryCmd, this, _1);
|
||||
m_commands["atis"] = std::bind(&Client::sendAtisQueryCmd, this, _1);
|
||||
m_commands["name"] = std::bind(&Client::sendNameQueryCmd, this, _1);
|
||||
m_commands["caps"] = std::bind(&Client::sendCapabilitiesQueryCmd, this, _1);
|
||||
m_commands["freqreply"] = std::bind(&Client::replyToFreqQueryCmd, this, _1);
|
||||
m_commands["namereply"] = std::bind(&Client::replyToNameQueryCmd, this, _1);
|
||||
m_commands["planeinfo"] = std::bind(&Client::requestPlaneInfoCmd, this, _1);
|
||||
m_commands["planeinforeply"] = std::bind(&Client::sendPlaneInfoCmd, this, _1);
|
||||
m_commands["ping"] = std::bind(&Client::pingCmd, this, _1);
|
||||
m_commands["metar"] = std::bind(&Client::requestMetarCmd, this, _1);
|
||||
m_commands["weather"] = std::bind(&Client::requestWeatherDataCmd, this, _1);
|
||||
}
|
||||
|
||||
void Client::command(QString line)
|
||||
{
|
||||
QTextStream stream (&line, QIODevice::ReadOnly);
|
||||
QString cmd;
|
||||
stream >> cmd;
|
||||
|
||||
auto found = m_commands.find(cmd);
|
||||
if (found == m_commands.end())
|
||||
{
|
||||
std::cout << "No such command" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
(*found)(stream);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/************ Commands *************/
|
||||
/****************************************************************************/
|
||||
|
||||
void Client::help(QTextStream&)
|
||||
{
|
||||
std::cout << "Commands:" << std::endl;
|
||||
auto keys = m_commands.keys();
|
||||
for (auto i = keys.begin(); i != keys.end(); ++i)
|
||||
{
|
||||
std::cout << " " << i->toStdString() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Client::echo(QTextStream& line)
|
||||
{
|
||||
std::cout << "echo: " << line.readAll().toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::exit(QTextStream&)
|
||||
{
|
||||
emit quit();
|
||||
}
|
||||
|
||||
void Client::setServerDetailsCmd(QTextStream& args)
|
||||
{
|
||||
QString hostname;
|
||||
quint16 port;
|
||||
args >> hostname >> port;
|
||||
emit setServerDetails(hostname, port);
|
||||
}
|
||||
|
||||
void Client::setUserCredentialsCmd(QTextStream& args)
|
||||
{
|
||||
QString username;
|
||||
QString password;
|
||||
args >> username >> password;
|
||||
emit setUserCredentials(username, password);
|
||||
}
|
||||
|
||||
void Client::setCallsignCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit setCallsign(callsign);
|
||||
}
|
||||
|
||||
void Client::setRealNameCmd(QTextStream& args)
|
||||
{
|
||||
emit setRealName(args.readAll());
|
||||
}
|
||||
|
||||
void Client::initiateConnectionCmd(QTextStream&)
|
||||
{
|
||||
emit initiateConnection();
|
||||
}
|
||||
|
||||
void Client::terminateConnectionCmd(QTextStream&)
|
||||
{
|
||||
emit terminateConnection();
|
||||
}
|
||||
|
||||
void Client::sendPrivateTextMessageCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
args.skipWhiteSpace();
|
||||
emit sendPrivateTextMessage(callsign, args.readAll());
|
||||
}
|
||||
|
||||
void Client::sendRadioTextMessageCmd(QTextStream& args)
|
||||
{
|
||||
QString freqsBlob;
|
||||
args >> freqsBlob;
|
||||
QStringList freqStrings = freqsBlob.split("|");
|
||||
QVector<BlackMisc::PhysicalQuantities::CFrequency> freqs;
|
||||
for (auto i = freqStrings.begin(); i != freqStrings.end(); ++i)
|
||||
{
|
||||
freqs.push_back(BlackMisc::PhysicalQuantities::CFrequency(i->toDouble(), BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()));
|
||||
}
|
||||
emit sendRadioTextMessage(freqs, args.readAll());
|
||||
}
|
||||
|
||||
void Client::sendIpQueryCmd(QTextStream&)
|
||||
{
|
||||
emit sendIpQuery();
|
||||
}
|
||||
|
||||
void Client::sendFreqQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendFreqQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::sendServerQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendServerQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::sendAtcQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendAtcQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::sendAtisQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendAtisQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::sendNameQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendNameQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::sendCapabilitiesQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit sendCapabilitiesQuery(callsign);
|
||||
}
|
||||
|
||||
void Client::replyToFreqQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
double num;
|
||||
args >> callsign >> num;
|
||||
BlackMisc::PhysicalQuantities::CFrequency freq (num, BlackMisc::PhysicalQuantities::CFrequencyUnit::kHz());
|
||||
emit replyToFreqQuery(callsign, freq);
|
||||
}
|
||||
|
||||
void Client::replyToNameQueryCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
QString realname;
|
||||
args >> callsign >> realname;
|
||||
emit replyToNameQuery(callsign, realname);
|
||||
}
|
||||
|
||||
void Client::requestPlaneInfoCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit requestPlaneInfo(callsign);
|
||||
}
|
||||
|
||||
void Client::sendPlaneInfoCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
QString acTypeICAO;
|
||||
QString airlineICAO;
|
||||
QString livery;
|
||||
args >> callsign >> acTypeICAO >> airlineICAO >> livery;
|
||||
emit sendPlaneInfo(callsign, acTypeICAO, airlineICAO, livery);
|
||||
}
|
||||
|
||||
void Client::pingCmd(QTextStream& args)
|
||||
{
|
||||
QString callsign;
|
||||
args >> callsign;
|
||||
emit ping(callsign);
|
||||
}
|
||||
|
||||
void Client::requestMetarCmd(QTextStream& args)
|
||||
{
|
||||
QString airportICAO;
|
||||
args >> airportICAO;
|
||||
emit requestMetar(airportICAO);
|
||||
}
|
||||
|
||||
void Client::requestWeatherDataCmd(QTextStream& args)
|
||||
{
|
||||
QString airportICAO;
|
||||
args >> airportICAO;
|
||||
emit requestWeatherData(airportICAO);
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/************ Slots to receive signals from INetwork *************/
|
||||
/****************************************************************************/
|
||||
|
||||
void Client::atcPositionUpdate(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
|
||||
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range)
|
||||
{
|
||||
std::cout << "POSITION " << callsign.toStdString() << " " << freq << " " << pos << " " << range << std::endl;
|
||||
}
|
||||
|
||||
void Client::atcDisconnected(const QString& callsign)
|
||||
{
|
||||
std::cout << "ATC_DISCONNECTED " << callsign.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::connectionStatusIdle()
|
||||
{
|
||||
std::cout << "CONN_STATUS_IDLE" << std::endl;
|
||||
}
|
||||
|
||||
void Client::connectionStatusConnecting()
|
||||
{
|
||||
std::cout << "CONN_STATUS_CONNECTING" << std::endl;
|
||||
}
|
||||
|
||||
void Client::connectionStatusConnected()
|
||||
{
|
||||
std::cout << "CONN_STATUS_CONNECTED" << std::endl;
|
||||
}
|
||||
|
||||
void Client::connectionStatusDisconnected()
|
||||
{
|
||||
std::cout << "CONN_STATUS_DISCONNECTED" << std::endl;
|
||||
}
|
||||
|
||||
void Client::connectionStatusError()
|
||||
{
|
||||
std::cout << "CONN_STATUS_ERROR" << std::endl;
|
||||
}
|
||||
|
||||
void Client::ipQueryReplyReceived(const QString& ip)
|
||||
{
|
||||
std::cout << "IP_REPLY " << ip.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::freqQueryReplyReceived(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq)
|
||||
{
|
||||
std::cout << "FREQ_REPLY " << callsign.toStdString() << " " << freq << std::endl;
|
||||
}
|
||||
|
||||
void Client::serverQueryReplyReceived(const QString& callsign, const QString& hostname)
|
||||
{
|
||||
std::cout << "SERVER_REPLY " << callsign.toStdString() << " " << hostname.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::atcQueryReplyReceived(const QString& callsign, bool isATC)
|
||||
{
|
||||
std::cout << "ATC_REPLY " << callsign.toStdString() << (isATC ? " yes" : " no") << std::endl;
|
||||
}
|
||||
|
||||
void Client::atisQueryReplyReceived(const QString& callsign, const QString& data)
|
||||
{
|
||||
std::cout << "ATIS_REPLY " << callsign.toStdString() << " " << data.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::nameQueryReplyReceived(const QString& callsign, const QString& realname)
|
||||
{
|
||||
std::cout << "NAME_REPLY " << callsign.toStdString() << " " << realname.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::capabilitiesQueryReplyReceived(const QString& callsign, quint32 flags)
|
||||
{
|
||||
std::cout << "CAPS_REPLY " << callsign.toStdString() << " " << flags << std::endl;
|
||||
}
|
||||
|
||||
void Client::freqQueryRequestReceived(const QString& callsign)
|
||||
{
|
||||
std::cout << "FREQ_QUERY " << callsign.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::nameQueryRequestReceived(const QString& callsign)
|
||||
{
|
||||
std::cout << "NAME_QUERY " << callsign.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::kicked(const QString& msg)
|
||||
{
|
||||
std::cout << "KICKED " << msg.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::metarReceived(const QString& data)
|
||||
{
|
||||
std::cout << "METAR " << data.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::pilotDisconnected(const QString& callsign)
|
||||
{
|
||||
std::cout << "PILOT_DISCONNECTED " << callsign.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::planeInfoReceived(const QString& callsign, const QString& acTypeICAO, const QString& airlineICAO, const QString& livery)
|
||||
{
|
||||
std::cout << "PLANE_INFO_REPLY " << callsign.toStdString() << " " << acTypeICAO.toStdString() << " " << airlineICAO.toStdString() << " " << livery.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::planeInfoRequestReceived(const QString& callsign)
|
||||
{
|
||||
std::cout << "PLANE_INFO_QUERY " << callsign.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::pong(const QString& callsign, const BlackMisc::PhysicalQuantities::CTime& elapsedTime)
|
||||
{
|
||||
std::cout << "PONG " << callsign.toStdString() << " " << elapsedTime << std::endl;
|
||||
}
|
||||
|
||||
void Client::radioTextMessageReceived(const QString& callsign, const QString& msg, const QVector<BlackMisc::PhysicalQuantities::CFrequency>& freqs)
|
||||
{
|
||||
QString freqsBlob = freqs[0].toQString();
|
||||
for (auto i = freqs.begin() + 1; i != freqs.end(); ++i)
|
||||
{
|
||||
freqsBlob.append("|");
|
||||
freqsBlob.append(i->toQString());
|
||||
}
|
||||
std::cout << "TEXT_MSG " << callsign.toStdString() << " " << freqsBlob.toStdString() << " " << msg.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
void Client::privateTextMessageReceived(const QString& fromCallsign, const QString& toCallsign, const QString& msg)
|
||||
{
|
||||
std::cout << "PRIV_MSG " << fromCallsign.toStdString() << " -> " << toCallsign.toStdString() << msg.toStdString() << std::endl;
|
||||
}
|
||||
111
samples/cli_client/client.h
Normal file
111
samples/cli_client/client.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef __BLACKSAMPLE_CLI_CLIENT_H__
|
||||
#define __BLACKSAMPLE_CLI_CLIENT_H__
|
||||
|
||||
#include <QObject>
|
||||
#include <QTextStream>
|
||||
#include <QMap>
|
||||
#include <functional>
|
||||
#include "blackcore/network.h"
|
||||
|
||||
class Client : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Client();
|
||||
|
||||
signals:
|
||||
void quit();
|
||||
|
||||
public slots:
|
||||
void command(QString line);
|
||||
|
||||
private: //commands
|
||||
void help(QTextStream& args);
|
||||
void echo(QTextStream& args);
|
||||
void exit(QTextStream& args);
|
||||
void setServerDetailsCmd(QTextStream& args);
|
||||
void setUserCredentialsCmd(QTextStream& args);
|
||||
void setCallsignCmd(QTextStream& args);
|
||||
void setRealNameCmd(QTextStream& args);
|
||||
void initiateConnectionCmd(QTextStream& args);
|
||||
void terminateConnectionCmd(QTextStream& args);
|
||||
void sendPrivateTextMessageCmd(QTextStream& args);
|
||||
void sendRadioTextMessageCmd(QTextStream& args);
|
||||
void sendIpQueryCmd(QTextStream& args);
|
||||
void sendFreqQueryCmd(QTextStream& args);
|
||||
void sendServerQueryCmd(QTextStream& args);
|
||||
void sendAtcQueryCmd(QTextStream& args);
|
||||
void sendAtisQueryCmd(QTextStream& args);
|
||||
void sendNameQueryCmd(QTextStream& args);
|
||||
void sendCapabilitiesQueryCmd(QTextStream& args);
|
||||
void replyToFreqQueryCmd(QTextStream& args);
|
||||
void replyToNameQueryCmd(QTextStream& args);
|
||||
void requestPlaneInfoCmd(QTextStream& args);
|
||||
void sendPlaneInfoCmd(QTextStream& args);
|
||||
void pingCmd(QTextStream& args);
|
||||
void requestMetarCmd(QTextStream& args);
|
||||
void requestWeatherDataCmd(QTextStream& args);
|
||||
|
||||
signals: //to send to INetwork
|
||||
void setServerDetails(const QString& hostname, quint16 port);
|
||||
void setUserCredentials(const QString& username, const QString& password);
|
||||
void setCallsign(const QString& callsign);
|
||||
void setRealName(const QString& name);
|
||||
void initiateConnection();
|
||||
void terminateConnection();
|
||||
void sendPrivateTextMessage(const QString& callsign, const QString& msg);
|
||||
void sendRadioTextMessage(const QVector<BlackMisc::PhysicalQuantities::CFrequency>& freqs, const QString& msg);
|
||||
void sendIpQuery();
|
||||
void sendFreqQuery(const QString& callsign);
|
||||
void sendServerQuery(const QString& callsign);
|
||||
void sendAtcQuery(const QString& callsign);
|
||||
void sendAtisQuery(const QString& callsign);
|
||||
void sendNameQuery(const QString& callsign);
|
||||
void sendCapabilitiesQuery(const QString& callsign);
|
||||
void replyToFreqQuery(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq);
|
||||
void replyToNameQuery(const QString& callsign, const QString& realname);
|
||||
void requestPlaneInfo(const QString& callsign);
|
||||
void sendPlaneInfo(const QString& callsign, const QString& acTypeICAO, const QString& airlineICAO, const QString& livery);
|
||||
void ping(const QString& callsign);
|
||||
void requestMetar(const QString& airportICAO);
|
||||
void requestWeatherData(const QString& airportICAO);
|
||||
|
||||
public slots: //to receive from INetwork
|
||||
void atcPositionUpdate(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
|
||||
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range);
|
||||
void atcDisconnected(const QString& callsign);
|
||||
void connectionStatusIdle();
|
||||
void connectionStatusConnecting();
|
||||
void connectionStatusConnected();
|
||||
void connectionStatusDisconnected();
|
||||
void connectionStatusError();
|
||||
void ipQueryReplyReceived(const QString& ip);
|
||||
void freqQueryReplyReceived(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq);
|
||||
void serverQueryReplyReceived(const QString& callsign, const QString& hostname);
|
||||
void atcQueryReplyReceived(const QString& callsign, bool isATC);
|
||||
void atisQueryReplyReceived(const QString& callsign, const QString& data);
|
||||
void nameQueryReplyReceived(const QString& callsign, const QString& realname);
|
||||
void capabilitiesQueryReplyReceived(const QString& callsign, quint32 flags);
|
||||
void freqQueryRequestReceived(const QString& callsign);
|
||||
void nameQueryRequestReceived(const QString& callsign);
|
||||
void kicked(const QString& msg);
|
||||
void metarReceived(const QString& data);
|
||||
void pilotDisconnected(const QString& callsign);
|
||||
void planeInfoReceived(const QString& callsign, const QString& acTypeICAO, const QString& airlineICAO, const QString& livery);
|
||||
void planeInfoRequestReceived(const QString& callsign);
|
||||
void pong(const QString& callsign, const BlackMisc::PhysicalQuantities::CTime& elapsedTime);
|
||||
void radioTextMessageReceived(const QString& callsign, const QString& msg, const QVector<BlackMisc::PhysicalQuantities::CFrequency>& freqs);
|
||||
void privateTextMessageReceived(const QString& fromCallsign, const QString& toCallsign, const QString& msg);
|
||||
|
||||
private:
|
||||
QMap<QString, std::function<void(QTextStream&)>> m_commands;
|
||||
BlackCore::INetwork* m_net;
|
||||
};
|
||||
|
||||
#endif //__BLACKSAMPLE_CLI_CLIENT_H__
|
||||
27
samples/cli_client/main.cpp
Normal file
27
samples/cli_client/main.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "blackcore/network_vatlib.h"
|
||||
#include "client.h"
|
||||
#include "reader.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QTextCodec>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QCoreApplication app (argc, argv);
|
||||
BlackMisc::CApplicationContext myApplicationContext;
|
||||
BlackMisc::IContext::getInstance().setSingleton(new BlackMisc::CDebug());
|
||||
BlackMisc::IContext::getInstance().setSingleton<BlackCore::INetwork>(new BlackCore::NetworkVatlib());
|
||||
|
||||
Client client;
|
||||
LineReader reader;
|
||||
QObject::connect(&reader, SIGNAL(command(const QString&)), &client, SLOT(command(const QString&)));
|
||||
QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate()));
|
||||
QObject::connect(&client, SIGNAL(quit()), &app, SLOT(quit()));
|
||||
|
||||
reader.start();
|
||||
app.exec();
|
||||
}
|
||||
21
samples/cli_client/reader.cpp
Normal file
21
samples/cli_client/reader.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "reader.h"
|
||||
#include <QFile>
|
||||
|
||||
void LineReader::run()
|
||||
{
|
||||
QFile file;
|
||||
file.open(stdin, QIODevice::ReadOnly | QIODevice::Text);
|
||||
forever
|
||||
{
|
||||
QString line = file.readLine();
|
||||
if (! line.isEmpty())
|
||||
{
|
||||
emit command(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
26
samples/cli_client/reader.h
Normal file
26
samples/cli_client/reader.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef __BLACKSAMPLE_CLI_CLIENT_READER_H__
|
||||
#define __BLACKSAMPLE_CLI_CLIENT_READER_H__
|
||||
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
class LineReader : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
LineReader() {}
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
signals:
|
||||
void command(const QString& line);
|
||||
};
|
||||
|
||||
#endif //__BLACKSAMPLE_CLI_CLIENT_READER_H__
|
||||
27
samples/cli_client/sample_cli_client.pro
Normal file
27
samples/cli_client/sample_cli_client.pro
Normal file
@@ -0,0 +1,27 @@
|
||||
QT += core
|
||||
QT -= gui
|
||||
|
||||
TARGET = sample_cli_client
|
||||
TEMPLATE = app
|
||||
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
DEPENDPATH += . ../../src
|
||||
INCLUDEPATH += . ../../src
|
||||
|
||||
SOURCES += *.cpp
|
||||
HEADERS += *.h
|
||||
|
||||
LIBS += -L../../lib -lblackcore -lblackmisc
|
||||
LIBS += -L../../../vatlib -lvatlib
|
||||
|
||||
win32:!win32-g++*: PRE_TARGETDEPS += ../../lib/blackmisc.lib \
|
||||
../../lib/blackcore.lib \
|
||||
../../../vatlib/vatlib.lib
|
||||
else: PRE_TARGETDEPS += ../../lib/libblackmisc.a \
|
||||
../../lib/libblackcore.a \
|
||||
../../../vatlib/libvatlib.a
|
||||
#TODO standardize dependency locations
|
||||
|
||||
DESTDIR = ../../bin
|
||||
Reference in New Issue
Block a user