From 7457945ab2973c6c93fbb9e92af7d81f15bced9d Mon Sep 17 00:00:00 2001 From: eshe Date: Sat, 5 Jun 2010 10:23:22 +0100 Subject: [PATCH] Daemon's memory usage decreased of about 6 MB. --- Makefile | 2 +- debian/changelog | 6 ++ src/common/connectionmanager.h | 2 +- src/common/settings.cpp | 6 ++ src/common/settings.h | 1 + src/daemon/calllistener.cpp | 121 +++++++++++++++++++++++----------------- src/daemon/calllistener.h | 8 ++- src/daemon/daemon.pro | 2 +- 8 files changed, 92 insertions(+), 56 deletions(-) diff --git a/Makefile b/Makefile index 166a6f3..a5cdae3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: jenirok -# Generated by qmake (2.01a) (Qt 4.6.2) on: Fri Jun 4 18:33:00 2010 +# Generated by qmake (2.01a) (Qt 4.6.2) on: Sat Jun 5 10:22:03 2010 # Project: jenirok.pro # Template: subdirs # Command: /usr/bin/qmake -unix -o Makefile jenirok.pro diff --git a/debian/changelog b/debian/changelog index 139ca56..5fd71f3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +jenirok (0.1-7) unstable; urgency=low + + * Decreased daemon's memory usage. + + -- Jesse Hakanen Sat, 5 Jun 2010 10:20:47 +0100 + jenirok (0.1-6) unstable; urgency=low * Added missing Finnish translations for several error messages. diff --git a/src/common/connectionmanager.h b/src/common/connectionmanager.h index 6c5e2a1..9261eb3 100644 --- a/src/common/connectionmanager.h +++ b/src/common/connectionmanager.h @@ -80,7 +80,7 @@ private: int scannedConnections_; int timer_; QList* connections_; - QDBusInterface *icd2interface_; + QDBusInterface* icd2interface_; }; #endif diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 91b289d..1333c21 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -33,6 +33,12 @@ Settings* Settings::instance() return instance_; } +void Settings::close() +{ + delete instance_; + instance_ = 0; +} + bool Settings::set(QString const& name, QString const& value) { bool connected = DB::connected(); diff --git a/src/common/settings.h b/src/common/settings.h index 2263beb..6649071 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -30,6 +30,7 @@ class Settings public: static Settings* instance(); + static void close(); bool set(QString const& name, QString const& value); QString get(QString const& name); QString getDefaultValue(QString const& name); diff --git a/src/daemon/calllistener.cpp b/src/daemon/calllistener.cpp index 5c640bb..d53da0a 100644 --- a/src/daemon/calllistener.cpp +++ b/src/daemon/calllistener.cpp @@ -23,6 +23,7 @@ #include "calllistener.h" #include "settings.h" #include "cache.h" +#include "contactmanager.h" namespace { @@ -37,9 +38,9 @@ namespace QDBusConnection CallListener::systemBus_ = QDBusConnection::systemBus(); -CallListener::CallListener(): eniro_(0), contactManager_(0), -connectionManager_(0), closeConnection_(false), box_(0), label_(0), -retries_(-1) +CallListener::CallListener(): eniro_(0), connectionManager_(0), +closeConnection_(false), initialized_(false), box_(0), label_(0), +retries_(-1), site_(Eniro::FI) { } @@ -64,23 +65,8 @@ void CallListener::begin() this, SLOT(callTerminate())); - contactManager_ = new ContactManager; - - eniro_ = new Eniro(Eniro::stringToSite(Settings::instance()->get("site"))); - - eniro_->setMaxResults(1); - eniro_->setFindNumber(false); - eniro_->setTimeout(REQUEST_TIMEOUT); - - connect(eniro_, SIGNAL(requestFinished(QVector const&, - Eniro::SearchDetails const&, bool)), - this, SLOT(requestFinished(QVector const&, - Eniro::SearchDetails const&, bool))); - - box_ = new InformationBox(); - label_ = new QLabel("", box_); - label_->setMargin(8); - box_->setWidget(label_); + site_ = Eniro::stringToSite(Settings::instance()->get("site")); + Settings::close(); qDebug() << "Starting..."; @@ -102,27 +88,23 @@ void CallListener::end() this, SLOT(callTerminate())); - delete contactManager_; - contactManager_ = 0; - delete connectionManager_; - connectionManager_ = 0; - delete eniro_; - eniro_ = 0; - delete box_; - box_ = 0; - delete label_; - label_ = 0; + searchClose(); + } void CallListener::search(Eniro::SearchDetails const& details) { qDebug() << "Search called"; + searchInit(); + Eniro::Result result; if(Cache::instance().findItem(details.query, result)) { + qDebug() << "Found from cache"; + showDelayedResult(createResult(result.name, result.street, result.city), BANNER_DELAY); @@ -132,14 +114,6 @@ void CallListener::search(Eniro::SearchDetails const& details) retries_ = 0; currentSearch_ = details.query; - if(connectionManager_) - { - delete connectionManager_; - connectionManager_ = 0; - } - - connectionManager_ = new ConnectionManager; - if(!connectionManager_->isConnected()) { connectionManager_->connect(); @@ -151,6 +125,9 @@ void CallListener::search(Eniro::SearchDetails const& details) } showDelayedResult(tr("Searching..."), BANNER_DELAY); + + qDebug() << "Starting to search..."; + eniro_->search(details); } @@ -161,7 +138,7 @@ void CallListener::requestFinished(QVector const& results, bool error) { // If box is not visible, the call must have been terminated already - if(!box_->isVisible()) + if(!initialized_ || !box_->isVisible()) { return; } @@ -213,10 +190,6 @@ void CallListener::requestFinished(QVector const& results, connectionManager_->disconnect(true); closeConnection_ = false; } - - delete connectionManager_; - connectionManager_ = 0; - } QString CallListener::createResult(QString const& name, QString const& street, QString const& city) @@ -240,6 +213,11 @@ QString CallListener::createResult(QString const& name, QString const& street, Q void CallListener::showResult(QString const& text) { + if(!initialized_) + { + return; + } + label_->setText("" + text + ""); if(box_->isVisible()) @@ -254,7 +232,9 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number) { qDebug() << "Incoming: " << number; - if(!contactManager_->numberExists(number)) + ContactManager cm; + + if(!cm.numberExists(number)) { qDebug() << "Number doesn't exist"; @@ -265,8 +245,6 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number) this, SLOT(callTerminate())); - qDebug() << "Going to search"; - search(Eniro::SearchDetails(number)); } else @@ -277,7 +255,7 @@ void CallListener::incomingCall(QDBusObjectPath path, QString number) void CallListener::callTerminate() { - if(box_->isVisible()) + if(initialized_ && box_ && box_->isVisible()) { box_->hide(); } @@ -288,8 +266,7 @@ void CallListener::callTerminate() closeConnection_ = false; } - delete connectionManager_; - connectionManager_ = 0; + searchClose(); } void CallListener::showDelayedResult(QString const& text, int delay) @@ -300,7 +277,7 @@ void CallListener::showDelayedResult(QString const& text, int delay) void CallListener::showTimedMessage() { - if(timedMessage_.size() == 0) + if(timedMessage_.size() == 0 || !initialized_) { return; } @@ -309,3 +286,47 @@ void CallListener::showTimedMessage() timedMessage_ = ""; } + +void CallListener::searchInit() +{ + qDebug() << "Initializing search..."; + + connectionManager_ = new ConnectionManager; + + eniro_ = new Eniro(site_); + eniro_->setMaxResults(1); + eniro_->setFindNumber(false); + eniro_->setTimeout(REQUEST_TIMEOUT); + + connect(eniro_, SIGNAL(requestFinished(QVector const&, + Eniro::SearchDetails const&, bool)), + this, SLOT(requestFinished(QVector const&, + Eniro::SearchDetails const&, bool))); + box_ = new InformationBox; + label_ = new QLabel("", box_); + label_->setMargin(8); + box_->setWidget(label_); + initialized_ = true; +} + +void CallListener::searchClose() +{ + initialized_ = false; + + qDebug() << "Closing search..."; + + if(eniro_) + { + disconnect(eniro_, SIGNAL(requestFinished(QVector const&, + Eniro::SearchDetails const&, bool)), + this, SLOT(requestFinished(QVector const&, + Eniro::SearchDetails const&, bool))); + } + + delete connectionManager_; + connectionManager_ = 0; + delete eniro_; + eniro_ = 0; + delete box_; + box_ = 0; +} diff --git a/src/daemon/calllistener.h b/src/daemon/calllistener.h index 8d098c8..4fe29b4 100644 --- a/src/daemon/calllistener.h +++ b/src/daemon/calllistener.h @@ -26,7 +26,6 @@ #include #include "informationbox.h" #include "eniro.h" -#include "contactmanager.h" #include "connectionmanager.h" class CallListener: public QObject @@ -39,7 +38,7 @@ public: void begin(); void end(); static const int REQUEST_TIMEOUT = 10000; - static const int BANNER_DELAY = 400; + static const int BANNER_DELAY = 350; static const int NUMBER_OF_RETRIES = 3; private slots: @@ -54,17 +53,20 @@ private: void search(Eniro::SearchDetails const& details); void showResult(QString const& text); void showDelayedResult(QString const& text, int delay); + void searchInit(); + void searchClose(); QString createResult(QString const& name, QString const& street, QString const& city); QString timedMessage_; Eniro* eniro_; - ContactManager* contactManager_; ConnectionManager* connectionManager_; bool closeConnection_; + bool initialized_; InformationBox* box_; QLabel* label_; static QDBusConnection systemBus_; int retries_; QString currentSearch_; + Eniro::Site site_; }; #endif // CALLLISTENER_H diff --git a/src/daemon/daemon.pro b/src/daemon/daemon.pro index c7fb9b2..252661b 100644 --- a/src/daemon/daemon.pro +++ b/src/daemon/daemon.pro @@ -8,7 +8,7 @@ TRANSLATIONS = ../common/translations/fi_FI.ts RESOURCES = ../common/translations.grc INCLUDEPATH += ../common CONFIG += link_pkgconfig -PKGCONFIG += libebook-1.2 glib-2.0 +PKGCONFIG += libebook-1.2 unix { #VARIABLES -- 1.7.9.5