mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
refactor: Simplify calls by not chaining
This commit is contained in:
@@ -31,9 +31,13 @@ namespace swift::core::context
|
|||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CCoreFacadeConfig::Local:
|
case CCoreFacadeConfig::Local: return new CContextApplication(mode, parent);
|
||||||
case CCoreFacadeConfig::LocalInDBusServer:
|
case CCoreFacadeConfig::LocalInDBusServer:
|
||||||
return (new CContextApplication(mode, parent))->registerWithDBus(server);
|
{
|
||||||
|
auto *context = new CContextApplication(mode, parent);
|
||||||
|
context->registerWithDBus(server);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
case CCoreFacadeConfig::Remote:
|
case CCoreFacadeConfig::Remote:
|
||||||
return new CContextApplicationProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
return new CContextApplicationProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
||||||
case CCoreFacadeConfig::NotUsed:
|
case CCoreFacadeConfig::NotUsed:
|
||||||
|
|||||||
@@ -25,11 +25,10 @@ namespace swift::core::context
|
|||||||
: IContextApplication(mode, runtime), CIdentifiable(this)
|
: IContextApplication(mode, runtime), CIdentifiable(this)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
CContextApplication *CContextApplication::registerWithDBus(swift::misc::CDBusServer *server)
|
void CContextApplication::registerWithDBus(swift::misc::CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return this; }
|
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }
|
||||||
server->addObject(IContextApplication::ObjectPath(), this);
|
server->addObject(IContextApplication::ObjectPath(), this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
|
void CContextApplication::changeSettings(const CValueCachePacket &settings, const CIdentifier &origin)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace swift::core
|
|||||||
CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
CContextApplication(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||||
|
|
||||||
//! Register myself in DBus, fail safe
|
//! Register myself in DBus, fail safe
|
||||||
CContextApplication *registerWithDBus(swift::misc::CDBusServer *server);
|
void registerWithDBus(swift::misc::CDBusServer *server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
swift::misc::CIdentifierList m_registeredApplications;
|
swift::misc::CIdentifierList m_registeredApplications;
|
||||||
|
|||||||
@@ -60,14 +60,19 @@ namespace swift::core::context
|
|||||||
// ContextAudioEmpty would cause issue, as it is initializing "common parts" during shutdown
|
// ContextAudioEmpty would cause issue, as it is initializing "common parts" during shutdown
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CCoreFacadeConfig::Local:
|
case CCoreFacadeConfig::Local: return new CContextAudio(mode, runtime);
|
||||||
case CCoreFacadeConfig::LocalInDBusServer:
|
case CCoreFacadeConfig::LocalInDBusServer:
|
||||||
default: return (new CContextAudio(mode, runtime))->registerWithDBus(server);
|
{
|
||||||
|
auto *context = new CContextAudio(mode, runtime);
|
||||||
|
context->registerWithDBus(server);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
case CCoreFacadeConfig::Remote:
|
case CCoreFacadeConfig::Remote:
|
||||||
return new CContextAudioProxy(CDBusServer::coreServiceName(connection), connection, mode, runtime);
|
return new CContextAudioProxy(CDBusServer::coreServiceName(connection), connection, mode, runtime);
|
||||||
case CCoreFacadeConfig::NotUsed:
|
case CCoreFacadeConfig::NotUsed:
|
||||||
SWIFT_VERIFY_X(false, Q_FUNC_INFO, "Empty context not supported for audio (since AFV)");
|
SWIFT_VERIFY_X(false, Q_FUNC_INFO, "Empty context not supported for audio (since AFV)");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
default: SWIFT_VERIFY_X(false, Q_FUNC_INFO, "Unknown context mode"); return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ namespace swift::core
|
|||||||
void onChangedLocalDevices(const swift::misc::audio::CAudioDeviceInfoList &devices);
|
void onChangedLocalDevices(const swift::misc::audio::CAudioDeviceInfoList &devices);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Audio context interface
|
//! Audio context base class
|
||||||
class SWIFT_CORE_EXPORT CContextAudioBase : public IContextAudio, public swift::misc::CIdentifiable
|
class SWIFT_CORE_EXPORT CContextAudioBase : public IContextAudio, public swift::misc::CIdentifiable
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -24,13 +24,12 @@ namespace swift::core::context
|
|||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
CContextAudio *CContextAudio::registerWithDBus(CDBusServer *server)
|
void CContextAudio::registerWithDBus(CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return this; }
|
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }
|
||||||
|
|
||||||
// remark that registers all SIGNALS, not only the interface ons
|
// remark that registers all SIGNALS, not only the interface ons
|
||||||
server->addObject(IContextAudio::ObjectPath(), this);
|
server->addObject(IContextAudio::ObjectPath(), this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextAudio::registerDevices(const CAudioDeviceInfoList &devices)
|
void CContextAudio::registerDevices(const CAudioDeviceInfoList &devices)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace swift::core
|
|||||||
CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||||
|
|
||||||
//! Register myself in DBus
|
//! Register myself in DBus
|
||||||
CContextAudio *registerWithDBus(misc::CDBusServer *server);
|
void registerWithDBus(misc::CDBusServer *server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
misc::audio::CAudioDeviceInfoList m_registeredDevices;
|
misc::audio::CAudioDeviceInfoList m_registeredDevices;
|
||||||
|
|||||||
@@ -85,18 +85,6 @@ namespace swift::core::context
|
|||||||
"voiceClientFailure", this, SIGNAL(voiceClientFailure(swift::misc::CStatusMessage)));
|
"voiceClientFailure", this, SIGNAL(voiceClientFailure(swift::misc::CStatusMessage)));
|
||||||
Q_ASSERT(s);
|
Q_ASSERT(s);
|
||||||
|
|
||||||
/**
|
|
||||||
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
|
|
||||||
"changedAudioVolume", this, SIGNAL(changedAudioVolume(int)));
|
|
||||||
Q_ASSERT(s);
|
|
||||||
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
|
|
||||||
"changedOutputMute", this, SIGNAL(changedOutputMute(bool)));
|
|
||||||
Q_ASSERT(s);
|
|
||||||
s = connection.connect(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(),
|
|
||||||
"changedLocalAudioDevices", this,
|
|
||||||
SIGNAL(changedLocalAudioDevices(swift::misc::audio::CAudioDeviceInfoList)));
|
|
||||||
**/
|
|
||||||
|
|
||||||
this->relayBaseClassSignals(serviceName, connection, IContextAudio::ObjectPath(),
|
this->relayBaseClassSignals(serviceName, connection, IContextAudio::ObjectPath(),
|
||||||
IContextAudio::InterfaceName());
|
IContextAudio::InterfaceName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,13 @@ namespace swift::core::context
|
|||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CCoreFacadeConfig::Local:
|
case CCoreFacadeConfig::Local: return new CContextNetwork(mode, runtime);
|
||||||
case CCoreFacadeConfig::LocalInDBusServer:
|
case CCoreFacadeConfig::LocalInDBusServer:
|
||||||
return (new CContextNetwork(mode, runtime))->registerWithDBus(server);
|
{
|
||||||
|
auto *context = new CContextNetwork(mode, runtime);
|
||||||
|
context->registerWithDBus(server);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
case CCoreFacadeConfig::Remote:
|
case CCoreFacadeConfig::Remote:
|
||||||
return new CContextNetworkProxy(CDBusServer::coreServiceName(connection), connection, mode, runtime);
|
return new CContextNetworkProxy(CDBusServer::coreServiceName(connection), connection, mode, runtime);
|
||||||
case CCoreFacadeConfig::NotUsed:
|
case CCoreFacadeConfig::NotUsed:
|
||||||
|
|||||||
@@ -120,11 +120,10 @@ namespace swift::core::context
|
|||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
CContextNetwork *CContextNetwork::registerWithDBus(swift::misc::CDBusServer *server)
|
void CContextNetwork::registerWithDBus(swift::misc::CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) return this;
|
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; };
|
||||||
server->addObject(IContextNetwork::ObjectPath(), this);
|
server->addObject(IContextNetwork::ObjectPath(), this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextNetwork::setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider)
|
void CContextNetwork::setSimulationEnvironmentProvider(ISimulationEnvironmentProvider *provider)
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ namespace swift::core
|
|||||||
CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
CContextNetwork(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
||||||
|
|
||||||
//! Register myself in DBus
|
//! Register myself in DBus
|
||||||
CContextNetwork *registerWithDBus(swift::misc::CDBusServer *server);
|
void registerWithDBus(swift::misc::CDBusServer *server);
|
||||||
|
|
||||||
//! Set the provider
|
//! Set the provider
|
||||||
void setSimulationEnvironmentProvider(swift::misc::simulation::ISimulationEnvironmentProvider *provider);
|
void setSimulationEnvironmentProvider(swift::misc::simulation::ISimulationEnvironmentProvider *provider);
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ namespace swift::core::context
|
|||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CCoreFacadeConfig::Local:
|
case CCoreFacadeConfig::Local: return new CContextOwnAircraft(mode, parent);
|
||||||
case CCoreFacadeConfig::LocalInDBusServer:
|
case CCoreFacadeConfig::LocalInDBusServer:
|
||||||
return (new CContextOwnAircraft(mode, parent))->registerWithDBus(server);
|
{
|
||||||
|
auto *context = new CContextOwnAircraft(mode, parent);
|
||||||
|
context->registerWithDBus(server);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
case CCoreFacadeConfig::Remote:
|
case CCoreFacadeConfig::Remote:
|
||||||
return new CContextOwnAircraftProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
return new CContextOwnAircraftProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
||||||
case CCoreFacadeConfig::NotUsed:
|
case CCoreFacadeConfig::NotUsed:
|
||||||
|
|||||||
@@ -72,11 +72,10 @@ namespace swift::core::context
|
|||||||
|
|
||||||
CContextOwnAircraft::~CContextOwnAircraft() {}
|
CContextOwnAircraft::~CContextOwnAircraft() {}
|
||||||
|
|
||||||
CContextOwnAircraft *CContextOwnAircraft::registerWithDBus(CDBusServer *server)
|
void CContextOwnAircraft::registerWithDBus(CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return this; }
|
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }
|
||||||
server->addObject(IContextOwnAircraft::ObjectPath(), this);
|
server->addObject(IContextOwnAircraft::ObjectPath(), this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const
|
CSimulatedAircraft CContextOwnAircraft::getOwnAircraft() const
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ namespace swift::core
|
|||||||
CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
CContextOwnAircraft(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
||||||
|
|
||||||
//! Register myself in DBus
|
//! Register myself in DBus
|
||||||
CContextOwnAircraft *registerWithDBus(swift::misc::CDBusServer *server);
|
void registerWithDBus(swift::misc::CDBusServer *server);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
swift::misc::simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft
|
swift::misc::simulation::CSimulatedAircraft m_ownAircraft; //!< my aircraft
|
||||||
|
|||||||
@@ -35,9 +35,13 @@ namespace swift::core::context
|
|||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case CCoreFacadeConfig::Local:
|
case CCoreFacadeConfig::Local: return new CContextSimulator(mode, parent);
|
||||||
case CCoreFacadeConfig::LocalInDBusServer:
|
case CCoreFacadeConfig::LocalInDBusServer:
|
||||||
return (new CContextSimulator(mode, parent))->registerWithDBus(server);
|
{
|
||||||
|
auto *context = new CContextSimulator(mode, parent);
|
||||||
|
context->registerWithDBus(server);
|
||||||
|
return context;
|
||||||
|
}
|
||||||
case CCoreFacadeConfig::Remote:
|
case CCoreFacadeConfig::Remote:
|
||||||
return new CContextSimulatorProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
return new CContextSimulatorProxy(CDBusServer::coreServiceName(connection), connection, mode, parent);
|
||||||
case CCoreFacadeConfig::NotUsed:
|
case CCoreFacadeConfig::NotUsed:
|
||||||
|
|||||||
@@ -106,11 +106,10 @@ namespace swift::core::context
|
|||||||
else { m_validator->setCurrentSimulator(CSimulatorInfo::None, {}, {}); }
|
else { m_validator->setCurrentSimulator(CSimulatorInfo::None, {}, {}); }
|
||||||
}
|
}
|
||||||
|
|
||||||
CContextSimulator *CContextSimulator::registerWithDBus(CDBusServer *server)
|
void CContextSimulator::registerWithDBus(CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return this; }
|
if (!server || getMode() != CCoreFacadeConfig::LocalInDBusServer) { return; }
|
||||||
server->addObject(CContextSimulator::ObjectPath(), this);
|
server->addObject(CContextSimulator::ObjectPath(), this);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CContextSimulator::isSimulatorPluginAvailable() const
|
bool CContextSimulator::isSimulatorPluginAvailable() const
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ namespace swift::core
|
|||||||
CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
CContextSimulator(CCoreFacadeConfig::ContextMode, CCoreFacade *runtime);
|
||||||
|
|
||||||
//! Register myself in DBus
|
//! Register myself in DBus
|
||||||
CContextSimulator *registerWithDBus(swift::misc::CDBusServer *server);
|
void registerWithDBus(swift::misc::CDBusServer *server);
|
||||||
|
|
||||||
//! Simulator plugin available?
|
//! Simulator plugin available?
|
||||||
bool isSimulatorPluginAvailable() const;
|
bool isSimulatorPluginAvailable() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user