Formatting

This commit is contained in:
Klaus Basan
2018-04-04 20:12:48 +02:00
committed by Roland Winklmeier
parent 291780244b
commit c1ac229875
3 changed files with 38 additions and 62 deletions

View File

@@ -161,61 +161,37 @@ namespace BlackCore
{
if (this->isDebugEnabled()) {CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; }
QString msg;
if (!server.getUser().hasCredentials())
{
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid user credentials");
}
else if (!this->ownAircraft().getAircraftIcaoCode().hasDesignator())
{
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid ICAO data for own aircraft");
}
else if (!CNetworkUtils::canConnect(server, msg, 5000))
{
return CStatusMessage(CStatusMessage::SeverityError, msg);
}
else if (m_network->isConnected())
{
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Already connected");
}
else if (this->isPendingConnection())
{
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Pending connection, please wait");
}
else
{
m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser());
const CSimulatedAircraft ownAircraft(this->ownAircraft());
m_network->presetServer(server);
if (!server.getUser().hasCredentials()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid user credentials"); }
if (!this->ownAircraft().getAircraftIcaoCode().hasDesignator()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Invalid ICAO data for own aircraft"); }
if (!CNetworkUtils::canConnect(server, msg, 5000)) { return CStatusMessage(CStatusMessage::SeverityError, msg); }
if (m_network->isConnected()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Already connected"); }
if (this->isPendingConnection()) { return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityError, "Pending connection, please wait"); }
// Fall back to observer mode, if no simulator is available or not simulating
if (!CBuildConfig::isLocalDeveloperDebugBuild() && !this->getIContextSimulator()->isSimulatorSimulating())
{
CLogMessage(this).info("No simulator connected or connected simulator not simulating. Falling back to observer mode");
mode = INetwork::LoginAsObserver;
}
m_currentStatus = INetwork::Connecting; // as semaphore we are going to connect
this->getIContextOwnAircraft()->updateOwnAircraftPilot(server.getUser());
const CSimulatedAircraft ownAircraft(this->ownAircraft());
m_network->presetServer(server);
m_network->presetLoginMode(mode);
m_network->presetCallsign(ownAircraft.getCallsign());
m_network->presetIcaoCodes(ownAircraft);
if (getIContextSimulator())
{
m_network->presetSimulatorInfo(getIContextSimulator()->getSimulatorPluginInfo());
}
else
{
m_network->presetSimulatorInfo(CSimulatorPluginInfo());
}
m_network->initiateConnection();
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort()));
// Fall back to observer mode, if no simulator is available or not simulating
if (!CBuildConfig::isLocalDeveloperDebugBuild() && !this->getIContextSimulator()->isSimulatorSimulating())
{
CLogMessage(this).info("No simulator connected or connected simulator not simulating. Falling back to observer mode");
mode = INetwork::LoginAsObserver;
}
m_network->presetLoginMode(mode);
m_network->presetCallsign(ownAircraft.getCallsign());
m_network->presetIcaoCodes(ownAircraft);
const CSimulatorPluginInfo sim = this->getIContextSimulator() ? this->getIContextSimulator()->getSimulatorPluginInfo() : CSimulatorPluginInfo();
m_network->presetSimulatorInfo(sim);
m_network->initiateConnection();
return CStatusMessage({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Connection pending " + server.getAddress() + " " + QString::number(server.getPort()));
}
CServer CContextNetwork::getConnectedServer() const
{
return this->isConnected() ?
m_network->getPresetServer() :
CServer();
return this->isConnected() ? m_network->getPresetServer() : CServer();
}
CStatusMessage CContextNetwork::disconnectFromNetwork()
@@ -300,7 +276,7 @@ namespace BlackCore
else
{
bool isNumber;
double frequencyMhz = receiver.toDouble(&isNumber);
const double frequencyMhz = receiver.toDouble(&isNumber);
if (isNumber)
{
CFrequency radioFrequency = CFrequency(frequencyMhz, CFrequencyUnit::MHz());

View File

@@ -86,12 +86,12 @@ namespace BlackMisc
double CAngle::piFactor() const
{
return Math::CMathUtils::round(this->value(CAngleUnit::rad()) / Math::CMathUtils::PI(), 6);
return Math::CMathUtils::round(this->value(CAngleUnit::rad()) / CMathUtils::PI(), 6);
}
const double &CAngle::PI()
{
return Math::CMathUtils::PI();
return CMathUtils::PI();
}
double CAngle::sin() const

View File

@@ -27,7 +27,7 @@ namespace XSwiftBus
class DataRefImpl
{
public:
DataRefImpl(char const* name) : m_ref(XPLMFindDataRef(name))
DataRefImpl(char const *name) : m_ref(XPLMFindDataRef(name))
{
if (! m_ref)
{
@@ -50,7 +50,7 @@ namespace XSwiftBus
class ArrayDataRefImpl
{
public:
ArrayDataRefImpl(char const* name, int size) : m_ref(XPLMFindDataRef(name)), m_size(size)
ArrayDataRefImpl(char const *name, int size) : m_ref(XPLMFindDataRef(name)), m_size(size)
{
if (! m_ref)
{
@@ -60,7 +60,7 @@ namespace XSwiftBus
}
template <typename T>
void implSetAll(std::vector<T> const&);
void implSetAll(std::vector<T> const &);
template <typename T>
std::vector<T> implGetAll() const;
@@ -126,7 +126,7 @@ namespace XSwiftBus
using DataRefType = typename DataRefTraits::type;
//! Set the value of the whole array (if it is writable)
void setAll(std::vector<DataRefType> const& a) { ArrayDataRefImpl::implSetAll(a); }
void setAll(std::vector<DataRefType> const &a) { ArrayDataRefImpl::implSetAll(a); }
//! Get the value of the whole array
std::vector<DataRefType> getAll() const { return ArrayDataRefImpl::implGetAll<DataRefType>(); }
@@ -158,18 +158,18 @@ namespace XSwiftBus
}
//! Set the value of the whole string (if it is writable)
void set(std::string const& s) { setSubstr(0, s); }
void set(std::string const &s) { setSubstr(0, s); }
//! Get the value of the whole string
std::string get() const { return getSubstr(0, DataRefTraits::size); }
//! Set the value of part of the string (if it is writable)
void setSubstr(size_t offset, std::string const& s)
void setSubstr(size_t offset, std::string const &s)
{ assert((s.size() + 1) <= (DataRefTraits::size - offset)); XPLMSetDatab(m_ref, s.c_str(), offset, s.size() + 1); }
//! Get the value of part of the string
std::string getSubstr(size_t offset, size_t size) const
{ std::string s (size, 0); XPLMGetDatab(m_ref, &s[0], (int)offset, (int)size); size = s.find(char(0)); if (size != std::string::npos) s.resize(size); return s; }
{ std::string s(size, 0); XPLMGetDatab(m_ref, &s[0], (int)offset, (int)size); size = s.find(char(0)); if (size != std::string::npos) s.resize(size); return s; }
private:
XPLMDataRef m_ref;
@@ -189,13 +189,13 @@ namespace XSwiftBus
inline double DataRefImpl::implGet<double>() const { return XPLMGetDatad(m_ref); }
template <>
inline void ArrayDataRefImpl::implSetAll<int>(std::vector<int> const& v) { assert((int)v.size() <= m_size); XPLMSetDatavi(m_ref, const_cast<int*>(&v[0]), 0, (int)v.size()); }
inline void ArrayDataRefImpl::implSetAll<int>(std::vector<int> const &v) { assert((int)v.size() <= m_size); XPLMSetDatavi(m_ref, const_cast<int *>(&v[0]), 0, (int)v.size()); }
template <>
inline void ArrayDataRefImpl::implSetAll<float>(std::vector<float> const& v) { assert((int)v.size() <= m_size); XPLMSetDatavf(m_ref, const_cast<float*>(&v[0]), 0, (int)v.size()); }
inline void ArrayDataRefImpl::implSetAll<float>(std::vector<float> const &v) { assert((int)v.size() <= m_size); XPLMSetDatavf(m_ref, const_cast<float *>(&v[0]), 0, (int)v.size()); }
template <>
inline std::vector<int> ArrayDataRefImpl::implGetAll<int>() const { std::vector<int> v (m_size); XPLMGetDatavi(m_ref, &v[0], 0, m_size); return v; }
inline std::vector<int> ArrayDataRefImpl::implGetAll<int>() const { std::vector<int> v(m_size); XPLMGetDatavi(m_ref, &v[0], 0, m_size); return v; }
template <>
inline std::vector<float> ArrayDataRefImpl::implGetAll<float>() const { std::vector<float> v (m_size); XPLMGetDatavf(m_ref, &v[0], 0, m_size); return v; }
inline std::vector<float> ArrayDataRefImpl::implGetAll<float>() const { std::vector<float> v(m_size); XPLMGetDatavf(m_ref, &v[0], 0, m_size); return v; }
template <>
inline void ArrayDataRefImpl::implSetAt<int>(int i, int d) { assert(i <= m_size); XPLMSetDatavi(m_ref, &d, i, 1); }