summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
committerMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
commit7bfa856f0673b81d4d0dafd6e02e07f10f07a023 (patch)
tree309ac66b5cbfe77df701fc9c7a0c7e5a68d147e7
parenta19a377ae930d54beb98dbe1f6171c6d39ddea80 (diff)
downloadlibresourceqt-7bfa856f0673b81d4d0dafd6e02e07f10f07a023.tar.gz
dbus-qeventloop update
-rw-r--r--debian/changelog6
-rw-r--r--libdbus-qeventloop/dbusconnectioneventloop.cpp71
-rw-r--r--libdbus-qeventloop/dbusconnectioneventloop.h13
-rw-r--r--libdbus-qeventloop/libdbus-qeventloop.pro1
-rw-r--r--libresourceqt/libresourceqt.pro1
-rw-r--r--libresourceqt/src/resource-engine.cpp11
-rw-r--r--libresourceqt/src/resource-engine.h1
-rw-r--r--resourceqt-client/client.cpp26
-rw-r--r--resourceqt-client/client.h61
-rw-r--r--tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp14
10 files changed, 178 insertions, 27 deletions
diff --git a/debian/changelog b/debian/changelog
index 868f17f..0cc8956 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libresourceqt (1.4) unstable; urgency=low
+
+ * libdbus-qeventloop fix
+
+ -- Martin Wolf <ext-martin.2.wolf@nokia.com> Wed, 07 Apr 2010 13:00:00 +0200
+
libresourceqt (1.3) unstable; urgency=low
* Also Fixes: NB#161198 - Unable to hear audio from any other MAFW player process except for the qmafw-dbus-wrapper
diff --git a/libdbus-qeventloop/dbusconnectioneventloop.cpp b/libdbus-qeventloop/dbusconnectioneventloop.cpp
index 0bce26e..e759d36 100644
--- a/libdbus-qeventloop/dbusconnectioneventloop.cpp
+++ b/libdbus-qeventloop/dbusconnectioneventloop.cpp
@@ -5,12 +5,41 @@
#include "dbusconnectioneventloop.h"
+DBUSConnectionEventLoop DBUSConnectionEventLoop::classInstance;
+
+bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn)
+{
+ return classInstance.internalAddConnection(conn);
+}
+
+void DBUSConnectionEventLoop::removeConnection(DBusConnection* conn)
+{
+ classInstance.internalRemoveConnection(conn);
+}
+
DBUSConnectionEventLoop::DBUSConnectionEventLoop() : QObject()
{
+ MYDEBUG();
}
DBUSConnectionEventLoop::~DBUSConnectionEventLoop()
{
+ MYDEBUG();
+ cleanup();
+}
+
+void DBUSConnectionEventLoop::cleanup()
+{
+ MYDEBUG();
+
+ Connections::iterator it;
+ for (it = connections.begin(); it != connections.end(); ++it) {
+ MYDEBUGC("Cleaning connection %p", *it);
+
+ dbus_connection_set_watch_functions(*it, NULL, NULL, NULL, NULL, NULL);
+ dbus_connection_set_timeout_functions(*it, NULL, NULL, NULL, NULL, NULL);
+ dbus_connection_set_wakeup_main_function(*it, NULL, NULL, NULL);
+ }
}
// Handle a socket being ready to read.
@@ -122,11 +151,12 @@ void DBUSConnectionEventLoop::removeWatch(DBusWatch *watch, void *data)
DBUSConnectionEventLoop::Watcher &watcher = it.value();
if (watcher.watch == watch) {
- if (watcher.read)
+ if (watcher.read) {
delete watcher.read;
-
- if (watcher.write)
+ }
+ if (watcher.write) {
delete watcher.write;
+ }
loop->watchers.erase(it);
@@ -229,14 +259,28 @@ void DBUSConnectionEventLoop::wakeupMain(void *data)
}
// The initialization point
-bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn)
+bool DBUSConnectionEventLoop::internalAddConnection(DBusConnection* conn)
{
- bool rc;
+ MYDEBUG();
+
+ bool rc = true;
if (conn == NULL) {
return false;
}
+ MYDEBUGC("Adding connection %p", conn);
+
+ // Check if connection is in list
+ Connections::iterator it;
+ for (it = connections.begin(); it != connections.end(); ++it) {
+ if( *it == conn ) {
+ MYDEBUGC("Connection already in list, skipping");
+ // Skip adding duplicate connection
+ return true;
+ }
+ }
+ // Add new connection
connections.append(conn);
if (
@@ -265,3 +309,20 @@ bool DBUSConnectionEventLoop::addConnection(DBusConnection* conn)
return rc;
}
+
+void DBUSConnectionEventLoop::internalRemoveConnection(DBusConnection* conn)
+{
+ MYDEBUG();
+
+ Connections::iterator it;
+ for (it = connections.begin(); it != connections.end(); ++it) {
+ if( *it == conn ) {
+ dbus_connection_set_watch_functions(*it, NULL, NULL, NULL, NULL, NULL);
+ dbus_connection_set_timeout_functions(*it, NULL, NULL, NULL, NULL, NULL);
+ dbus_connection_set_wakeup_main_function(*it, NULL, NULL, NULL);
+
+ connections.erase(it);
+ return;
+ }
+ }
+}
diff --git a/libdbus-qeventloop/dbusconnectioneventloop.h b/libdbus-qeventloop/dbusconnectioneventloop.h
index 8067e75..d44f667 100644
--- a/libdbus-qeventloop/dbusconnectioneventloop.h
+++ b/libdbus-qeventloop/dbusconnectioneventloop.h
@@ -48,18 +48,24 @@ class DBUSConnectionEventLoop : public QObject
{
Q_OBJECT
private:
+ static DBUSConnectionEventLoop classInstance;
+
Q_DISABLE_COPY(DBUSConnectionEventLoop)
+ DBUSConnectionEventLoop();
public:
- DBUSConnectionEventLoop();
virtual ~DBUSConnectionEventLoop();
-public:
/**
* Add new dbus connection into handler.
* \return true if everything went well.
*/
- bool addConnection(DBusConnection* conn);
+ static bool addConnection(DBusConnection* conn);
+ static void removeConnection(DBusConnection* conn);
+
+private:
+ bool internalAddConnection(DBusConnection* conn);
+ void internalRemoveConnection(DBusConnection* conn);
/**
* Helper class for dbus watcher
@@ -100,6 +106,7 @@ private slots:
protected:
void timerEvent(QTimerEvent *e);
+ void cleanup();
static dbus_bool_t addWatch(DBusWatch *watch, void *data);
static void removeWatch(DBusWatch *watch, void *data);
diff --git a/libdbus-qeventloop/libdbus-qeventloop.pro b/libdbus-qeventloop/libdbus-qeventloop.pro
index 5b0ef18..cbed3cf 100644
--- a/libdbus-qeventloop/libdbus-qeventloop.pro
+++ b/libdbus-qeventloop/libdbus-qeventloop.pro
@@ -14,6 +14,7 @@ HEADERS += dbusconnectioneventloop.h
QT = core
CONFIG += qt link_pkgconfig dll
PKGCONFIG += dbus-1
+DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT QT_NO_DEBUG_STREAM
# Install directives
headers.files = $$HEADERS
diff --git a/libresourceqt/libresourceqt.pro b/libresourceqt/libresourceqt.pro
index f2d642c..f8ef8d8 100644
--- a/libresourceqt/libresourceqt.pro
+++ b/libresourceqt/libresourceqt.pro
@@ -28,6 +28,7 @@ MOC_DIR = build
CONFIG += qt link_pkgconfig dll
QT = core
PKGCONFIG += dbus-1 libresource0
+DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT QT_NO_DEBUG_STREAM
# Install directives
headers.files = $${PUBLIC_HEADERS}
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index 014d2cc..38afb64 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -14,7 +14,7 @@ static void handleAdviceMessage(resmsg_t *msg, resset_t *rs, void *data);
ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
: QObject(resourceSet), connected(false), resourceSet(resourceSet),
- dbusEngine(NULL), libresourceConnection(NULL), libresourceSet(NULL),
+ libresourceConnection(NULL), libresourceSet(NULL),
requestId(0), messageMap(), connectionMode(0)
{
if (resourceSet->alwaysGetReply()) {
@@ -28,7 +28,6 @@ ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
ResourceEngine::~ResourceEngine()
{
- delete dbusEngine;
if (libresourceSet != NULL)
libresourceSet->userdata = NULL;
//need to destroy all libresource structures, but how?
@@ -38,9 +37,6 @@ bool ResourceEngine::initialize()
{
DBusError dbusError;
DBusConnection *dbusConnection;
- dbusEngine = new DBUSConnectionEventLoop;
- if(dbusEngine == NULL)
- return false;
dbus_error_init(&dbusError);
dbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &dbusError);
@@ -50,7 +46,7 @@ bool ResourceEngine::initialize()
return false;
}
dbus_error_free(&dbusError);
- dbusEngine->addConnection(dbusConnection);
+ DBUSConnectionEventLoop::addConnection(dbusConnection);
libresourceConnection = resproto_init(RESPROTO_ROLE_CLIENT, RESPROTO_TRANSPORT_DBUS,
connectionIsUp, dbusConnection);
if (libresourceConnection == NULL) {
@@ -178,6 +174,9 @@ bool ResourceEngine::connectToManager()
libresourceSet = resconn_connect(libresourceConnection, &resourceMessage,
statusCallbackHandler);
+ if (libresourceSet == NULL)
+ return false;
+
libresourceSet->userdata = this; //save our context
return true;
}
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 897c27e..17768a5 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -61,7 +61,6 @@ private:
bool connected;
ResourceSet *resourceSet;
DBusConnection *dbusConnection;
- DBUSConnectionEventLoop *dbusEngine;
resconn_t *libresourceConnection;
resset_t *libresourceSet;
quint32 requestId;
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 078e6e4..e0adbd0 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -297,6 +297,10 @@ void Client::showResources(const QList<Resource*> resList)
void Client::resourceAcquiredHandler(const QList<ResourceType>& /*grantedResList*/)
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
QList<Resource*> list = resourceSet->resources();
if (!list.count()) {
printf("\nGranted resource set is empty. Possible bug?\n");
@@ -311,18 +315,30 @@ void Client::resourceAcquiredHandler(const QList<ResourceType>& /*grantedResList
void Client::resourceDeniedHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nManager denies access to resources!\n");
showPrompt();
}
void Client::resourceLostHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nLost resources from manager!\n");
showPrompt();
}
void Client::resourceReleasedHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nAll resources released\n");
showPrompt();
}
@@ -376,12 +392,22 @@ void Client::timerEvent(QTimerEvent*)
}
}
else if (params[0] == "acquire") {
+ timeStat.markStart();
if (!resourceSet || !resourceSet->acquire()) {
+ if( timeStat.markEnd() ) {
+ timeStat.report("Operation took %.2f ms\n");
+ }
+
printf("Acquire failed!\n");
}
}
else if (params[0] == "release") {
+ timeStat.markStart();
if (!resourceSet || !resourceSet->release()) {
+ if( timeStat.markEnd() ) {
+ timeStat.report("Operation took %.2f ms\n");
+ }
+
printf("Release failed!\n");
}
}
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index ed32538..c61a74c 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -5,6 +5,7 @@
#include <QtCore/QTextStream>
#include <policy/resource-set.h>
+#include <sys/resource.h>
#define RES_AUDIO_PLAYBACK (1<<0)
#define RES_VIDEO_PLAYBACK (1<<1)
@@ -19,6 +20,64 @@
#define RES_SNAP_BUTTON (1<<10)
#define RES_LENS_COVER (1<<11)
+class TimeStat
+{
+public:
+ double totalTime;
+
+ TimeStat()
+ {
+ running = false;
+ totalTime = 0;
+ };
+
+ inline void markStart()
+ {
+ running = true;
+ getrusage(RUSAGE_SELF, &start);
+ }
+
+ inline bool markEnd()
+ {
+ getrusage(RUSAGE_SELF, &end);
+
+ if( !running )
+ return false;
+
+ running = false;
+ timevalSub(&end.ru_utime, &start.ru_utime, &end.ru_utime);
+ timevalSub(&end.ru_stime, &start.ru_stime, &end.ru_stime);
+
+ double sys = end.ru_stime.tv_sec * 1000.0 + end.ru_stime.tv_usec / 1000.0;
+ double usr = end.ru_utime.tv_sec * 1000.0 + end.ru_utime.tv_usec / 1000.0;
+ totalTime = sys + usr;
+
+ return true;
+ }
+
+ void report(const char* format)
+ {
+ printf(format, totalTime);
+ }
+
+private:
+ bool running;
+ struct rusage start;
+ struct rusage end;
+
+ void timevalSub(struct timeval *a, struct timeval *b, struct timeval *diff)
+ {
+ diff->tv_sec = a->tv_sec - b->tv_sec;
+ if( a->tv_usec < b->tv_usec )
+ {
+ diff->tv_sec--;
+ diff->tv_usec = 1000000 - b->tv_usec + a->tv_usec;
+ }
+ else
+ diff->tv_usec = a->tv_usec - b->tv_usec;
+ }
+};
+
class Client : public QObject
{
Q_OBJECT
@@ -47,6 +106,8 @@ private:
uint32_t resourcesOptional;
QString applicationClass;
+ TimeStat timeStat;
+
ResourcePolicy::ResourceSet* resourceSet;
ResourcePolicy::Resource* allocateResource(ResourcePolicy::ResourceType resource, bool optional);
diff --git a/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp b/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
index 3a005c0..746a6ed 100644
--- a/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
+++ b/tests/test-dbus-qeventloop/test-dbus-qeventloop.cpp
@@ -8,7 +8,6 @@ class TestDbusQEventLoop: public QObject
private:
DBusConnection* systemBus;
DBusConnection* sessionBus;
- DBUSConnectionEventLoop* dbusEventLoop;
void resetValues() {
wasInNotifyFnc = 0;
@@ -131,7 +130,6 @@ protected:
private slots:
void initTestCase() {
// First allocate and obtain
- dbusEventLoop = new DBUSConnectionEventLoop();
systemBus = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
sessionBus = dbus_bus_get(DBUS_BUS_SESSION, NULL);;
// Last check, if server is running
@@ -140,9 +138,8 @@ private slots:
// Create event loop ...
- QVERIFY(dbusEventLoop != NULL);
- QVERIFY(dbusEventLoop->addConnection(systemBus) == true);
- QVERIFY(dbusEventLoop->addConnection(sessionBus) == true);
+ QVERIFY(DBUSConnectionEventLoop::addConnection(systemBus) == true);
+ QVERIFY(DBUSConnectionEventLoop::addConnection(sessionBus) == true);
// Then test ... otherwise something don't have to be allocated (i.e. event loop)
QVERIFY(systemBus != NULL);
QVERIFY(sessionBus != NULL);
@@ -183,13 +180,6 @@ private slots:
// Free message, it is not necessary to test, QVERIFY upper will end function
dbus_message_unref(message);
- // Cleanup allocated pointers
- QVERIFY(dbusEventLoop != NULL);
- if (dbusEventLoop) {
- delete dbusEventLoop;
- dbusEventLoop = NULL;
- }
-
// Check if everything went well
QVERIFY(systemTimeout == false);
QVERIFY(systemResponse == 12345);