Formatting application context

This commit is contained in:
Klaus Basan
2015-04-26 19:24:54 +02:00
committed by Mathew Sutcliffe
parent 3ecf37dda4
commit 05be0ecb37
2 changed files with 31 additions and 44 deletions

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2013
* This Source Code Form is subject to the terms of the Mozilla Public * swift Project Community / Contributors
* 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/. */ * 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 "context_application_impl.h" #include "context_application_impl.h"
#include "context_runtime.h" #include "context_runtime.h"
@@ -16,16 +20,17 @@ using namespace BlackMisc;
namespace BlackCore namespace BlackCore
{ {
/*
* Init this context
*/
CContextApplication::CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContextApplication::CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime) :
IContextApplication(mode, runtime) IContextApplication(mode, runtime)
{} {}
/* CContextApplication *CContextApplication::registerWithDBus(CDBusServer *server)
* Log a message {
*/ if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) { return this; }
server->addObject(IContextApplication::ObjectPath(), this);
return this;
}
void CContextApplication::logMessage(const CStatusMessage &message, const Event::COriginator &origin) void CContextApplication::logMessage(const CStatusMessage &message, const Event::COriginator &origin)
{ {
if (!origin.isFromSameProcess()) if (!origin.isFromSameProcess())
@@ -35,30 +40,21 @@ namespace BlackCore
emit this->messageLogged(message, origin); emit this->messageLogged(message, origin);
} }
/*
* Ping, is DBus alive?
*/
qint64 CContextApplication::ping(qint64 token) const qint64 CContextApplication::ping(qint64 token) const
{ {
return token; return token;
} }
/*
* Component has changed
*/
void CContextApplication::notifyAboutComponentChange(uint component, uint action) void CContextApplication::notifyAboutComponentChange(uint component, uint action)
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << QString::number(component) << QString::number(action); CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << QString::number(component) << QString::number(action);
this->componentChanged(component, action); this->componentChanged(component, action);
} }
/*
* String to file
*/
bool CContextApplication::writeToFile(const QString &fileName, const QString &content) bool CContextApplication::writeToFile(const QString &fileName, const QString &content)
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25); CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName << content.left(25);
if (fileName.isEmpty()) return false; if (fileName.isEmpty()) { return false; }
QFile file(fileName); QFile file(fileName);
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{ {
@@ -66,12 +62,12 @@ namespace BlackCore
out << content; out << content;
return true; return true;
} }
else return false; else
{
return false;
}
} }
/*
* File to string
*/
QString CContextApplication::readFromFile(const QString &fileName) QString CContextApplication::readFromFile(const QString &fileName)
{ {
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName; CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << fileName;
@@ -87,18 +83,12 @@ namespace BlackCore
return content; return content;
} }
/*
* Remove file
*/
bool CContextApplication::removeFile(const QString &fileName) bool CContextApplication::removeFile(const QString &fileName)
{ {
if (fileName.isEmpty()) return false; if (fileName.isEmpty()) return false;
return QFile::remove(fileName); return QFile::remove(fileName);
} }
/*
* Check file
*/
bool CContextApplication::existsFile(const QString &fileName) bool CContextApplication::existsFile(const QString &fileName)
{ {
if (fileName.isEmpty()) return false; if (fileName.isEmpty()) return false;

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2013
* This Source Code Form is subject to the terms of the Mozilla Public * swift Project Community / Contributors
* 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/. */ * 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.
*/
#ifndef BLACKCORE_CONTEXTAPPLICATION_IMPL_H #ifndef BLACKCORE_CONTEXTAPPLICATION_IMPL_H
#define BLACKCORE_CONTEXTAPPLICATION_IMPL_H #define BLACKCORE_CONTEXTAPPLICATION_IMPL_H
@@ -15,9 +19,7 @@ namespace BlackCore
{ {
class CRuntime; class CRuntime;
/*! //! Application context
* Application context
*/
class BLACKCORE_EXPORT CContextApplication : public IContextApplication class BLACKCORE_EXPORT CContextApplication : public IContextApplication
{ {
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME) Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAPPLICATION_INTERFACENAME)
@@ -55,13 +57,8 @@ namespace BlackCore
CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime); CContextApplication(CRuntimeConfig::ContextMode mode, CRuntime *runtime);
//! Register myself in DBus, fail safe //! Register myself in DBus, fail safe
CContextApplication *registerWithDBus(CDBusServer *server) CContextApplication *registerWithDBus(CDBusServer *server);
{
if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) { return this; }
server->addObject(IContextApplication::ObjectPath(), this);
return this;
}
}; };
} } // namespace
#endif // guard #endif // guard