refs #199, simplified initialization of runtime

This commit is contained in:
Klaus Basan
2014-04-08 17:57:10 +02:00
parent 8fc2c5c8a6
commit 20ad5d39ce

View File

@@ -229,8 +229,7 @@ namespace BlackCore
BlackMisc::registerMetadata(); BlackMisc::registerMetadata();
BlackMisc::initResources(); BlackMisc::initResources();
// upfront reading of settings, as DBus server alread relies on // upfront reading of settings, as DBus server already relies on settings
// settings
CContextSettings *settings = nullptr; CContextSettings *settings = nullptr;
QString dbusServerAddress; QString dbusServerAddress;
if (config.hasLocalSettings()) if (config.hasLocalSettings())
@@ -240,6 +239,10 @@ namespace BlackCore
dbusServerAddress = settings->getNetworkSettings().getDBusServerAddress(); dbusServerAddress = settings->getNetworkSettings().getDBusServerAddress();
} }
// DBus
if (config.requiresDBusSever()) this->initDBusServer(dbusServerAddress);
if (config.requiresDBusConnection()) this->initDBusConnection();
// contexts // contexts
switch (config.getModeSettings()) switch (config.getModeSettings())
{ {
@@ -247,83 +250,73 @@ namespace BlackCore
this->m_contextSettings = settings; this->m_contextSettings = settings;
break; break;
case CRuntimeConfig::LocalInDbusServer: case CRuntimeConfig::LocalInDbusServer:
this->initDBusServer(dbusServerAddress); {
this->m_contextSettings = settings->registerWithDBus(this->m_dbusServer); this->m_contextSettings = settings->registerWithDBus(this->m_dbusServer);
QDBusConnection *con = new QDBusConnection(this->m_dbusServer->getDBusConnection());
con->connect(BlackCore::CDBusServer::ServiceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
"widgetGuiStarting", this->m_contextSettings, SIGNAL(widgetGuiStarting()));
con->connect(BlackCore::CDBusServer::ServiceName, IContextApplication::ObjectPath(), IContextApplication::InterfaceName(),
"widgetGuiTerminating", this->m_contextSettings, SIGNAL(widgetGuiTerminating()));
}
break; break;
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
this->initDBusConnection();
this->m_contextSettings = new BlackCore::CContextSettingsProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSettings(), this); this->m_contextSettings = new BlackCore::CContextSettingsProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSettings(), this);
break; break;
default: default:
break; qFatal("Always initialize a settings context");
} }
switch (config.getModeApplication()) switch (config.getModeApplication())
{ {
case CRuntimeConfig::Local: case CRuntimeConfig::Local:
this->m_contextApplication = new CContextApplication(config.getModeApplication(), this);
break;
case CRuntimeConfig::LocalInDbusServer: case CRuntimeConfig::LocalInDbusServer:
this->initDBusServer(dbusServerAddress);
this->m_contextApplication = (new CContextApplication(config.getModeApplication(), this))->registerWithDBus(this->m_dbusServer); this->m_contextApplication = (new CContextApplication(config.getModeApplication(), this))->registerWithDBus(this->m_dbusServer);
break; break;
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
this->initDBusConnection();
this->m_contextApplication = new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeApplication(), this); this->m_contextApplication = new BlackCore::CContextApplicationProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeApplication(), this);
break; break;
default: default:
break; qFatal("Always initialize an application context");
} }
switch (config.getModeAudio()) switch (config.getModeAudio())
{ {
case CRuntimeConfig::Local: case CRuntimeConfig::Local:
this->m_contextAudio = new CContextAudio(config.getModeAudio(), this);
break;
case CRuntimeConfig::LocalInDbusServer: case CRuntimeConfig::LocalInDbusServer:
this->initDBusServer(dbusServerAddress);
this->m_contextAudio = (new CContextAudio(config.getModeAudio(), this))->registerWithDBus(this->m_dbusServer); this->m_contextAudio = (new CContextAudio(config.getModeAudio(), this))->registerWithDBus(this->m_dbusServer);
break; break;
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
this->initDBusConnection();
this->m_contextAudio = new BlackCore::CContextAudioProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeAudio(), this); this->m_contextAudio = new BlackCore::CContextAudioProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeAudio(), this);
break; break;
default: default:
break; break; // audio not mandatory
} }
switch (config.getModeNetwork()) switch (config.getModeNetwork())
{ {
case CRuntimeConfig::Local: case CRuntimeConfig::Local:
this->m_contextNetwork = new CContextNetwork(config.getModeNetwork(), this);
break;
case CRuntimeConfig::LocalInDbusServer: case CRuntimeConfig::LocalInDbusServer:
this->initDBusServer(dbusServerAddress);
this->m_contextNetwork = (new CContextNetwork(config.getModeNetwork(), this))->registerWithDBus(this->m_dbusServer); this->m_contextNetwork = (new CContextNetwork(config.getModeNetwork(), this))->registerWithDBus(this->m_dbusServer);
break; break;
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
this->initDBusConnection();
this->m_contextNetwork = new BlackCore::CContextNetworkProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeNetwork(), this); this->m_contextNetwork = new BlackCore::CContextNetworkProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeNetwork(), this);
break; break;
default: default:
break; break; // network not mandatory
} }
switch (config.getModeSimulator()) switch (config.getModeSimulator())
{ {
case CRuntimeConfig::Local: case CRuntimeConfig::Local:
this->m_contextSimulator = new CContextSimulator(config.getModeSimulator(), this);
break;
case CRuntimeConfig::LocalInDbusServer: case CRuntimeConfig::LocalInDbusServer:
this->initDBusServer(dbusServerAddress);
this->m_contextSimulator = (new CContextSimulator(config.getModeSimulator(), this))->registerWithDBus(this->m_dbusServer); this->m_contextSimulator = (new CContextSimulator(config.getModeSimulator(), this))->registerWithDBus(this->m_dbusServer);
break; break;
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
this->initDBusConnection();
this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSimulator(), this); this->m_contextSimulator = new BlackCore::CContextSimulatorProxy(BlackCore::CDBusServer::ServiceName, this->m_dbusConnection, config.getModeSimulator(), this);
break; break;
default: default:
break; break; // network not mandatory
} }
// post inits, wiring things among context (e.g. signal slots) // post inits, wiring things among context (e.g. signal slots)