Make all dbus modules quit when the app quit

This commit is contained in:
李 翔 2018-02-04 21:25:17 +08:00
parent 0c31512548
commit fac7c6d530
13 changed files with 358 additions and 431 deletions

View File

@ -36,30 +36,23 @@ ThreadPool *ThreadPool::Instance()
return &threadPool;
}
QThread *ThreadPool::newThread()
QThread *ThreadPool::createNewThread()
{
QThread *thread = new QThread;
thread_pool.push_back(thread);
m_threadPool.push_back(thread);
return thread;
}
void ThreadPool::moveToNewThread(QObject *obj)
void ThreadPool::moveObjectToThread(QObject *obj)
{
QThread *work = newThread();
QThread *work = createNewThread();
obj->moveToThread(work);
work->start();
}
//QThread *ThreadPool::createNewThread()
//{
// QThread *thread = new QThread;
// thread_pool.push_back(thread);
// return thread;
//}
void ThreadPool::exitAllThreads()
{
foreach (QThread *thread, thread_pool) {
foreach (QThread *thread, m_threadPool) {
thread->quit();
thread->wait(2000);
}

View File

@ -29,14 +29,12 @@ public:
~ThreadPool();
static ThreadPool *Instance();
// QThread *createNewThread();
QThread *newThread();
void moveToNewThread(QObject *obj);
QThread *createNewThread();
void moveObjectToThread(QObject *obj);
void exitAllThreads();
private:
QList<QThread *> thread_pool;
QList<QThread *> m_threadPool;
};
#endif // THREADPOOL_H

View File

@ -48,7 +48,6 @@ SystemDispatcher::~SystemDispatcher() {
clean_thread = NULL;
}
qDebug() << "system dbus destroy..............";
this->exit_qt();
if (systemiface != NULL) {
delete systemiface;

1
debian/changelog vendored
View File

@ -17,5 +17,6 @@ kylin-assistant (1.0.0-0ubuntu1) bionic; urgency=low
* Add monitor for auto startup manager.
* Add monitor for file system.
* Add QDbus module(system dbus and session dbus).
* Make all dbus modules quit when the app quit.
-- lixiang <lixiang@kylinos.cn> Mon, 29 Jan 2018 17:54:44 +0800

View File

@ -33,107 +33,13 @@
#include <QDebug>
#include <QFileInfo>
#include <QDirIterator>
#include <QSet>
#include <glib.h>
#include <sys/stat.h>
#include <string.h>
#include "util.h"
//#include <gio/gio.h>
//static gboolean
//gsp_app_manager_xdg_dir_monitor (GFileMonitor *monitor,
// GFile *child,
// GFile *other_file,
// GFileMonitorEvent flags,
// gpointer data)
//{
//// GspAppManager *manager;
//// GspApp *old_app;
//// GspApp *app;
// GFile *parent;
// char *basename;
// char *dir;
// char *path;
// int index;
// manager = GSP_APP_MANAGER (data);
// basename = g_file_get_basename (child);
// if (!g_str_has_suffix (basename, ".desktop")) {
// /* not a desktop file, we can ignore */
// g_free (basename);
// return TRUE;
// }
// old_app = getAppStartupDataAccrodDesktopFileName (manager, basename);
// parent = g_file_get_parent (child);
// dir = g_file_get_path (parent);
// g_object_unref (parent);
// index = gsp_app_manager_get_dir_index (manager, dir);
// if (index < 0) {
// /* not a directory we know; should never happen, though */
// g_free (dir);
// return TRUE;
// }
// path = g_file_get_path (child);
// switch (flags) {
// case G_FILE_MONITOR_EVENT_CHANGED:
// case G_FILE_MONITOR_EVENT_CREATED:
// /* we just do as if it was a new file: GspApp is clever enough
// * to do the right thing */
// app = gsp_app_new (path, (unsigned int) index);
// /* we didn't have this app before, so add it */
// if (old_app == NULL && app != NULL) {
// gsp_app_manager_add (manager, app);
// g_object_unref (app);
// }
// /* else: it was just updated, GspApp took care of
// * sending the event */
// break;
// case G_FILE_MONITOR_EVENT_DELETED:
// if (!old_app) {
// /* it got deleted, but we don't know about it, so
// * nothing to do */
// break;
// }
// _gsp_app_manager_handle_delete (manager, old_app,
// basename, index);
// break;
// default:
// break;
// }
// g_free (path);
// g_free (dir);
// g_free (basename);
// return TRUE;
//}
//GFile *file;
//GDir *dir;
//const char *name;
//file = g_file_new_for_path (xdgdir->dir);
//GFileMonitor *monitor;
//monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
//g_object_unref (file);
//if (monitor) {
// g_signal_connect (monitor, "changed", G_CALLBACK (gsp_app_manager_xdg_dir_monitor), manager);
//}
//g_file_monitor_cancel (monitor);
//g_object_unref (monitor);
//monitor = NULL;
void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key)
{
char *C_value;
@ -143,15 +49,15 @@ void ensureCKeyInDesktopFil (GKeyFile *keyfile, const char *key)
* This is so that if the user logs into another locale they get their
* own description there rather then empty. It is not the C locale
* however, but the user created this entry herself so it's OK */
C_value = kylin_start_manager_key_file_get_string (keyfile, key);
C_value = kylin_start_manager_key_file_get_string(keyfile, key);
if (C_value == NULL || C_value [0] == '\0') {
buffer = kylin_start_manager_key_file_get_locale_string (keyfile, key);
if (buffer) {
kylin_start_manager_key_file_set_string (keyfile, key, buffer);
g_free (buffer);
}
buffer = kylin_start_manager_key_file_get_locale_string(keyfile, key);
if (buffer) {
kylin_start_manager_key_file_set_string(keyfile, key, buffer);
g_free(buffer);
}
}
g_free (C_value);
g_free(C_value);
}
inline QString getCurrentDesktopEnvironment()
@ -320,12 +226,37 @@ StartupData StartupWorker::getAppStartupDataAccrodDesktopFileName(QString &basen
return StartupData();
}
/*
* dir: fileList:
*/
void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList)
{
if (this->m_xdgMap.keys().contains(dir)) {
QSet<QString> nowAutoStartSet = QSet<QString>::fromList(fileList);
//canel auto start, add the desktop file to user config dir
for(const QString &startupItem: nowAutoStartSet - QSet<QString>::fromList(this->m_xdgMap.value(dir).fileList)) {
//qDebug() << "Add startupItem===="<<startupItem;
this->newStartupInfo(startupItem, this->m_xdgMap.value(dir).index);
}
//start auto start, remove the desktop file which in user config dir
for(const QString &startupItem: QSet<QString>::fromList(this->m_xdgMap.value(dir).fileList) - nowAutoStartSet) {
//qDebug() << "Removed startupItem===="<<startupItem;
StartupData info = getStartupInfoAccordDestkopFile(startupItem);
if (info.exec.isEmpty() && info.name.isEmpty())
continue;
info.enabled = true;
info.save_mask |= SAVE_MASK_ENABLED;
this->updateEnable(info.exec, info.enabled);
this->updateSaveMask(info.exec, info.save_mask);
this->readySaveDesktopInfo(info);
}
/*
//start auto start, remove the desktop file which in user config dir
foreach (QString orgFileAbsPath, this->m_xdgMap.value(dir).fileList) {
if (!fileList.contains(orgFileAbsPath)) {
qDebug() << "had removed orgFileAbsPath="<<orgFileAbsPath;
//had removed
StartupData info = getStartupInfoAccordDestkopFile(orgFileAbsPath);
if (info.exec.isEmpty() && info.name.isEmpty())
@ -342,9 +273,11 @@ void StartupWorker::updateGspXdgDir(const QString &dir, QStringList fileList)
foreach (QString nowFileAbsPath, fileList) {
if (!this->m_xdgMap[dir].fileList.contains(nowFileAbsPath)) {
//new added
qDebug() << "add new nowFileAbsPath="<<nowFileAbsPath;
this->newStartupInfo(nowFileAbsPath, this->m_xdgMap.value(dir).index);
}
}
*/
this->m_xdgMap[dir].fileList.clear();
this->m_xdgMap[dir].fileList = fileList;

View File

@ -66,6 +66,7 @@ bool FileSystemWatcher::clearWatcher()
return false;
}
}
void FileSystemWatcher::onMountDeviceFileContentsChanged()
{
QSet<QString> nowFileSet = getFileContentsLineByLine(DEVICE_MOUNT_PONINT_RECORD_FILE);

View File

@ -36,7 +36,6 @@ SessionService::~SessionService()
this->exitService();
}
QString SessionService::demoInfo()
{
return "QtSessionDbus";

View File

@ -18,6 +18,7 @@ SystemDbusProxy::SystemDbusProxy(QObject *parent) :
SystemDbusProxy::~SystemDbusProxy()
{
this->exitService();
m_handler->deleteLater();
}

View File

@ -69,5 +69,6 @@ void SystemService::sendCustomData(const CustomData &message)
void SystemService::exitService()
{
qDebug() << "ready to exit service";
qApp->exit(0);
}

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,10 @@
#include <QScopedPointer>
#include <QDBusInterface>
#include "../qdbusservice/systemdbus/data/systemdbusproxy.h"
#include "../qdbusservice/systemdbus/customdata.h"
#include "../qdbusservice/systemdbus/customdatalist.h"
class QTimer;
class SessionDispatcher;
class SystemDispatcher;
@ -328,9 +332,10 @@ signals:
void sendFileManagerData(bool locationReplacePathbar, bool autoMountMedia, bool autoOpenFolder, bool promptAutorunPrograms, int thumbnailIconSize, int thumbnailCacheTime, int thumbnailCacheSize);
private:
QDBusInterface *iface = nullptr;
SessionDispatcher *sessioninterface = nullptr;
SystemDispatcher *systeminterface = nullptr;
QDBusInterface *m_powerIface = nullptr;
SessionDispatcher *m_sessionInterface = nullptr;
SystemDispatcher *m_systemInterface = nullptr;
SystemDbusProxy *m_qSystemDbus = nullptr;
QString desktop;
bool m_existBattery;

View File

@ -28,10 +28,6 @@
//#include "cameramanager.h"
#include "../component/threadpool.h"
#include "dataworker.h"
#include "../qdbusservice/systemdbus/data/systemdbusproxy.h"
#include "../qdbusservice/systemdbus/customdata.h"
#include "../qdbusservice/systemdbus/customdatalist.h"
//QDBusPendingCallWatcher *m_getAllPendingCallWatcher;
// QDBusError m_lastExtendedError;
@ -254,11 +250,6 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
this->initAnimation();
this->hide();
m_qSystemDbus = new SystemDbusProxy;
connect(m_qSystemDbus, &SystemDbusProxy::reportAlert, this, [ = ](int ret, const QString &description) {
qDebug() <<"ret="<<ret<<",description="<<description;
});
this->startDbusDaemon();
// 添加阴影
@ -271,7 +262,7 @@ MainWindow::MainWindow(QString cur_arch, int d_count, QWidget* parent, Qt::Windo
MainWindow::~MainWindow()
{
delete m_qSystemDbus;
// delete m_qSystemDbus;
if (m_dataWorker) {
m_dataWorker->deleteLater();
@ -374,9 +365,6 @@ void MainWindow::onInitDataFinished()
this->displayMainWindow();
qDebug() << "m_qSystemDbus->demoInfo()===="<<m_qSystemDbus->demoInfo();
qDebug() << m_qSystemDbus->getCustomData().hash;
//bind setting notify signal
// connect(m_dataWorker, SIGNAL(string_value_notify(QString,QString)), setting_widget, SIGNAL(string_value_notify(QString,QString)));
// connect(m_dataWorker, SIGNAL(bool_value_notify(QString,bool)), setting_widget, SIGNAL(bool_value_notify(QString,bool)));
@ -960,7 +948,7 @@ void MainWindow::startDbusDaemon()
// systeminterface = new SystemDispatcher;
m_dataWorker = new DataWorker(this->desktop);
QThread *w_thread = ThreadPool::Instance()->newThread();
QThread *w_thread = ThreadPool::Instance()->createNewThread();
m_dataWorker->moveToThread(w_thread);
connect(w_thread, SIGNAL(started()), m_dataWorker, SLOT(doWork()));
connect(m_dataWorker, SIGNAL(dataLoadFinished()), this, SLOT(onInitDataFinished()));

View File

@ -173,11 +173,7 @@ private:
// QStringList skinlist;
ShadowWidget *shadow_widget;
int display_count;
DataWorker *m_dataWorker = nullptr;
SystemDbusProxy *m_qSystemDbus = nullptr;
};
class GlobalData // define by hebing,just for transmit var