summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-04-27 09:42:03 +0300
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-04-27 09:42:03 +0300
commitee5ed8f33d6060c9eb041cacb54f31c2cb1da067 (patch)
treebf06a93541eed2751d34c3616e2432b88933df43
parent3a5be2e8aff1c1bdd6406904307a7b3b7a062d38 (diff)
downloadlibresourceqt-ee5ed8f33d6060c9eb041cacb54f31c2cb1da067.tar.gz
Added mutexes to make all libresourceqt usage atomic
-rw-r--r--libresourceqt/libresourceqt.pro4
-rw-r--r--libresourceqt/src/resource-engine.cpp149
-rw-r--r--libresourceqt/src/resource-engine.h5
-rw-r--r--libresourceqt/src/resource-set.cpp26
-rw-r--r--tests/test-resource-engine/test-resource-engine.cpp41
-rw-r--r--tests/test-resource-engine/test-resource-engine.h3
6 files changed, 178 insertions, 50 deletions
diff --git a/libresourceqt/libresourceqt.pro b/libresourceqt/libresourceqt.pro
index 01cbca5..bf27d09 100644
--- a/libresourceqt/libresourceqt.pro
+++ b/libresourceqt/libresourceqt.pro
@@ -28,7 +28,9 @@ MOC_DIR = moc
CONFIG += qt link_pkgconfig dll
QT = core
PKGCONFIG += dbus-1 libresource0
-DEFINES += QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT QT_NO_DEBUG_STREAM
+CONFIG(release, release|debug) {
+ 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 93df853..6489a53 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -6,6 +6,8 @@ using namespace ResourcePolicy;
resconn_t *ResourceEngine::libresourceConnection = NULL;
quint32 ResourceEngine::libresourceUsers = 0;
+static QMutex mutex(QMutex::Recursive);
+
static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet);
static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet);
@@ -16,8 +18,9 @@ static void handleGrantMessage(resmsg_t *msg, resset_t *rs, void *data);
static void handleAdviceMessage(resmsg_t *msg, resset_t *rs, void *data);
ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
- : QObject(resourceSet), connected(false), resourceSet(resourceSet),
- libresourceSet(NULL), requestId(0), messageMap(), connectionMode(0)
+ : QObject(), connected(false), resourceSet(resourceSet),
+ libresourceSet(NULL), requestId(0), messageMap(), connectionMode(0),
+ identifier(resourceSet->id()), aboutToBeDeleted(false)
{
if (resourceSet->alwaysGetReply()) {
connectionMode += RESMSG_MODE_ALWAYS_REPLY;
@@ -25,20 +28,30 @@ ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
if (resourceSet->willAutoRelease()) {
connectionMode += RESOURCE_AUTO_RELEASE;
}
- qDebug("connectionMode = %04x", connectionMode);
+ qDebug("ResourceEngine::ResourceEngine(%d) - connectionMode = %04x", identifier, connectionMode);
}
ResourceEngine::~ResourceEngine()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
+ qDebug("ResourceEngine::~ResourceEngine(%d) - starting destruction", identifier);
libresourceUsers--;
- if (libresourceUsers == 0) {
+ if (libresourceSet != NULL) {
libresourceSet->userdata = NULL;
+ qDebug("ResourceEngine::~ResourceEngine(%d) - unset userdata", identifier);
+ }
+ if (libresourceUsers==0) {
+ qDebug("ResourceEngine::~ResourceEngine(%d) - last libresourceUser!", identifier);
+ ResourceEngine::libresourceConnection = NULL;
}
- //need to destroy all libresource structures, but how?
+ qDebug("ResourceEngine::~ResourceEngine(%d) is no more!", identifier);
}
bool ResourceEngine::initialize()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
DBusError dbusError;
DBusConnection *dbusConnection;
@@ -57,7 +70,8 @@ bool ResourceEngine::initialize()
ResourceEngine::libresourceConnection = resproto_init(RESPROTO_ROLE_CLIENT, RESPROTO_TRANSPORT_DBUS,
connectionIsUp, dbusConnection);
if (ResourceEngine::libresourceConnection == NULL) {
- return NULL;
+ qDebug("resproto_init failed!");
+ return false;
}
ResourceEngine::libresourceUsers = 1;
resproto_set_handler(ResourceEngine::libresourceConnection, RESMSG_UNREGISTER, handleUnregisterMessage);
@@ -68,12 +82,16 @@ bool ResourceEngine::initialize()
ResourceEngine::libresourceUsers += 1;
}
- qDebug("ResourceEngine (%p) is now initialized.", this);
+ qDebug("ResourceEngine (%u, %p) is now initialized. %d users",
+ identifier, ResourceEngine::libresourceConnection,
+ ResourceEngine::libresourceUsers);
return true;
}
static void handleUnregisterMessage(resmsg_t *message, resset_t *libresourceSet, void *)
{
+ qDebug("**************** %s() - locking....", __FUNCTION__);
+ QMutexLocker locker(&mutex);
if (NULL == libresourceSet->userdata) {
qDebug("IGNORING unregister, no context");
return;
@@ -91,13 +109,15 @@ static void handleUnregisterMessage(resmsg_t *message, resset_t *libresourceSet,
void ResourceEngine::disconnected()
{
- qDebug("disconnected");
+ qDebug("ResourceEngine(%d) - disconnected", identifier);
connected = false;
emit disconnectedFromManager();
}
static void handleGrantMessage(resmsg_t *message, resset_t *libresourceSet, void *)
{
+ qDebug("**************** %s() - locking....", __FUNCTION__);
+ QMutexLocker locker(&mutex);
if (NULL == libresourceSet->userdata) {
qDebug("IGNORING grant, no context: type=0x%04x, id=0x%04x, reqno=0x%04x, resc=0x%04x",
message->notify.type, message->notify.id, message->notify.reqno, message->notify.resrc);
@@ -117,37 +137,41 @@ static void handleGrantMessage(resmsg_t *message, resset_t *libresourceSet, void
void ResourceEngine::receivedGrant(resmsg_notify_t *notifyMessage)
{
- qDebug("receivedGrant: type=0x%04x, id=0x%04x, reqno=0x%04x, resc=0x%04x",
- notifyMessage->type, notifyMessage->id, notifyMessage->reqno, notifyMessage->resrc);
+ qDebug("ResourceEngine(%d) - receivedGrant: type=0x%04x, id=0x%04x, reqno=0x%04x, resc=0x%04x",
+ identifier, notifyMessage->type, notifyMessage->id, notifyMessage->reqno, notifyMessage->resrc);
if (notifyMessage->resrc == 0) {
bool unkownRequest = !messageMap.contains(notifyMessage->reqno);
resmsg_type_t originaloriginalMessageType = messageMap.take(notifyMessage->reqno);
- qDebug("lost resources, originaloriginalMessageType=%u", originaloriginalMessageType);
+ qDebug("ResourceEngine(%d) - lost resources, originaloriginalMessageType=%u",
+ identifier, originaloriginalMessageType);
if (unkownRequest) {
//we don't know this req number => it must be a server override.
- qDebug("emiting signal resourcesLost()");
+ qDebug("ResourceEngine(%d) - emiting signal resourcesLost()", identifier);
emit resourcesLost(allResourcesToBitmask(resourceSet));
}
else if (originaloriginalMessageType == RESMSG_ACQUIRE) {
- qDebug("request DENIED!");
+ qDebug("ResourceEngine(%d) - request DENIED!", identifier);
emit resourcesDenied();
}
else if (originaloriginalMessageType == RESMSG_RELEASE) {
- qDebug("confirmnation to release");
+ qDebug("ResourceEngine(%d) - confirmation to release", identifier);
emit resourcesReleased();
}
else {
- qDebug("Ignoring the receivedGrant");
+ qDebug("ResourceEngine(%d) - Ignoring the receivedGrant", identifier);
}
}
else {
- qDebug("emiting signal resourcesGranted(%02x)", notifyMessage->resrc);
+ qDebug("ResourceEngine(%d) - emiting signal resourcesGranted(%02x)",
+ identifier, notifyMessage->resrc);
emit resourcesGranted(notifyMessage->resrc);
}
}
static void handleAdviceMessage(resmsg_t *message, resset_t *libresourceSet, void *)
{
+ qDebug("**************** %s() - locking....", __FUNCTION__);
+ QMutexLocker locker(&mutex);
if (NULL == libresourceSet->userdata) {
qDebug("IGNORING advice, no context");
return;
@@ -167,7 +191,7 @@ static void handleAdviceMessage(resmsg_t *message, resset_t *libresourceSet, voi
void ResourceEngine::receivedAdvice(resmsg_notify_t *message)
{
- qDebug("%s: %04x", __FUNCTION__, message->resrc);
+ qDebug("ResourceEngine(%d) - %s: %04x", identifier, __FUNCTION__, message->resrc);
uint32_t allResources = allResourcesToBitmask(resourceSet);
if(message->resrc < allResources) {
emit resourcesLost(allResources-message->resrc);
@@ -179,6 +203,8 @@ void ResourceEngine::receivedAdvice(resmsg_notify_t *message)
bool ResourceEngine::connectToManager()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t resourceMessage;
memset(&resourceMessage, 0, sizeof(resmsg_t));
resourceMessage.record.type = RESMSG_REGISTER;
@@ -201,38 +227,50 @@ bool ResourceEngine::connectToManager()
resourceMessage.record.mode = connectionMode;
- qDebug("ResourceEngine is now connecting...");
+ qDebug("ResourceEngine(%d) - ResourceEngine is now connecting(%d, %d, %d)",
+ identifier, resourceMessage.record.id, resourceMessage.record.reqno,
+ resourceMessage.record.rset.all);
libresourceSet = resconn_connect(ResourceEngine::libresourceConnection, &resourceMessage,
- statusCallbackHandler);
+ statusCallbackHandler);
if (libresourceSet == NULL)
return false;
-
libresourceSet->userdata = this; //save our context
+ //locker.unlock();
+ qDebug("ResourceEngine(%d)::%s() - **************** unlocked! returning true", identifier, __FUNCTION__);
return true;
}
bool ResourceEngine::disconnectFromManager()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t resourceMessage;
memset(&resourceMessage, 0, sizeof(resmsg_t));
- qDebug("disconnecting from manager");
+ qDebug("ResourceEngine(%d)::%s() - disconnecting from manager - %p",
+ identifier, __FUNCTION__, ResourceEngine::libresourceConnection);
+ connected = false;
+ aboutToBeDeleted = true;
resourceMessage.record.type = RESMSG_UNREGISTER;
resourceMessage.record.id = resourceSet->id();
resourceMessage.record.reqno = ++requestId;
- messageMap.insert(requestId, RESMSG_UNREGISTER);
+// messageMap.insert(requestId, RESMSG_UNREGISTER);
int r = resconn_disconnect(libresourceSet, &resourceMessage,
statusCallbackHandler);
- connected = false;
if (r)
return true;
else
return false;
}
+bool ResourceEngine::toBeDeleted()
+{
+ return aboutToBeDeleted;
+}
+
static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet)
{
QList<Resource *> resourceList = resourceSet->resources();
@@ -289,13 +327,20 @@ static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet)
static void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message)
{
+ qDebug("**************** %s().... %d", __FUNCTION__, __LINE__);
+ //qDebug("**************** %s() - locking....", __FUNCTION__);
+ QMutexLocker locker(&mutex);
if (NULL == libresourceSet->userdata) {
qDebug("IGNORING status message, no context: type=0x%04x, id=0x%04x, reqno=0x%04x, errcod=%d",
message->status.type, message->status.id, message->status.reqno, message->status.errcod);
return;
}
+ qDebug("**************** %s().... %d", __FUNCTION__, __LINE__);
ResourceEngine *resourceEngine = reinterpret_cast<ResourceEngine *>(libresourceSet->userdata);
+ qDebug("**************** %s().... %d", __FUNCTION__, __LINE__);
+ qDebug("**************** %s().... %d", __FUNCTION__, __LINE__);
qDebug("recv: status: id=%d, engine->id() = %d", message->any.id, resourceEngine->id());
+ qDebug("**************** %s().... %d", __FUNCTION__, __LINE__);
if(resourceEngine->id() != libresourceSet->id) {
qDebug("Received a status notification, but it is not for us. Ignoring (%d != %d)",
resourceEngine->id(), libresourceSet->id);
@@ -311,7 +356,13 @@ static void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message)
}
else {
qDebug("Received a status message with id %02x and #:%u", message->status.id, message->status.reqno);
- resourceEngine->handleStatusMessage(message->status.reqno);
+ if(!resourceEngine->isConnectedToManager() && resourceEngine->toBeDeleted()) {
+ qDebug("%s(%d) - delete resourceEngine %p", __FUNCTION__, __LINE__, resourceEngine);
+ delete resourceEngine;
+ }
+ else {
+ resourceEngine->handleStatusMessage(message->status.reqno);
+ }
}
}
@@ -320,32 +371,33 @@ void ResourceEngine::handleStatusMessage(quint32 requestNo)
resmsg_type_t originalMessageType = messageMap.value(requestNo);
qDebug("Received a status message: %u(0x%02x)", requestNo, originalMessageType);
if (originalMessageType == RESMSG_REGISTER) {
- qDebug("connected!");
+ qDebug("ResourceEngine(%d) - connected!", identifier);
connected = true;
emit connectedToManager();
messageMap.remove(requestNo);
}
else if (originalMessageType == RESMSG_UNREGISTER) {
- qDebug("disconnected!");
+ qDebug("ResourceEngine(%d) - disconnected!", identifier);
connected = false;
emit disconnectedFromManager();
messageMap.remove(requestNo);
}
else if(originalMessageType == RESMSG_UPDATE) {
- qDebug("Update status");
+ qDebug("ResourceEngine(%d) - Update status", identifier);
}
else if(originalMessageType == RESMSG_ACQUIRE) {
- qDebug("Acquire status");
+ qDebug("ResourceEngine(%d) - Acquire status", identifier);
}
else if(originalMessageType == RESMSG_RELEASE) {
- qDebug("Release status");
+ qDebug("ResourceEngine(%d) - Release status", identifier);
}
}
void ResourceEngine::handleError(quint32 requestNo, qint32 code, const char *message)
{
resmsg_type_t originalMessageType = messageMap.take(requestNo);
- qDebug("Error on request %u(0x%02x): %d - %s", requestNo, originalMessageType, code, message);
+ qDebug("ResourceEngine(%d) - Error on request %u(0x%02x): %d - %s",
+ identifier, requestNo, originalMessageType, code, message);
}
bool ResourceEngine::isConnectedToManager()
@@ -355,6 +407,8 @@ bool ResourceEngine::isConnectedToManager()
bool ResourceEngine::acquireResources()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t message;
memset(&message, 0, sizeof(resmsg_t));
@@ -364,7 +418,7 @@ bool ResourceEngine::acquireResources()
messageMap.insert(requestId, RESMSG_ACQUIRE);
- qDebug("acquire %u:%u", resourceSet->id(), requestId);
+ qDebug("ResourceEngine(%d) - acquire %u:%u", identifier, resourceSet->id(), requestId);
int success = resproto_send_message(libresourceSet, &message, statusCallbackHandler);
if(!success)
@@ -375,6 +429,8 @@ bool ResourceEngine::acquireResources()
bool ResourceEngine::releaseResources()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t message;
memset(&message, 0, sizeof(resmsg_t));
@@ -383,7 +439,7 @@ bool ResourceEngine::releaseResources()
message.possess.reqno = ++requestId;
messageMap.insert(requestId, RESMSG_RELEASE);
- qDebug("release %u:%u", resourceSet->id(), requestId);
+ qDebug("ResourceEngine(%d) - release %u:%u", identifier, resourceSet->id(), requestId);
int success = resproto_send_message(libresourceSet, &message, statusCallbackHandler);
if(!success)
@@ -394,6 +450,8 @@ bool ResourceEngine::releaseResources()
bool ResourceEngine::updateResources()
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t message;
memset(&message, 0, sizeof(resmsg_t));
message.record.type = RESMSG_UPDATE;
@@ -414,7 +472,7 @@ bool ResourceEngine::updateResources()
messageMap.insert(requestId, RESMSG_UPDATE);
- qDebug("update %u:%u", resourceSet->id(), requestId);
+ qDebug("ResourceEngine(%d) - update %u:%u", identifier, resourceSet->id(), requestId);
int success = resproto_send_message(libresourceSet, &message, statusCallbackHandler);
if(!success)
@@ -426,19 +484,21 @@ bool ResourceEngine::updateResources()
bool ResourceEngine::registerAudioProperties(const QString &audioGroup, quint32 pid,
const QString &name, const QString &value)
{
+ qDebug("ResourceEngine(%d)::%s() - **************** locking....", identifier, __FUNCTION__);
+ QMutexLocker locker(&mutex);
resmsg_t message;
memset(&message, 0, sizeof(resmsg_t));
QByteArray groupBa, nameBa, valueBa;
if (pid != 0) {
message.audio.pid = pid;
- qDebug("audio pid %u", pid);
+ qDebug("ResourceEngine(%d) - audio pid %u", identifier, pid);
}
if (!audioGroup.isEmpty() && !audioGroup.isNull()) {
resmsg_audio_t *audio;
groupBa = audioGroup.toLatin1();
message.audio.group = groupBa.data();
- qDebug("audio group: %s", message.audio.group);
+ qDebug("ResourceEngine(%d) - audio group: %s", identifier, message.audio.group);
audio = &message.audio;
}
if (!name.isEmpty() && !name.isNull() && !value.isEmpty() && !value.isNull()) {
@@ -447,7 +507,8 @@ bool ResourceEngine::registerAudioProperties(const QString &audioGroup, quint32
message.audio.property.name = nameBa.data();
message.audio.property.match.method = resmsg_method_equals;
message.audio.property.match.pattern = valueBa.data();
- qDebug("audio stream tag is %s:%s", message.audio.property.name, message.audio.property.match.pattern);
+ qDebug("ResourceEngine(%d) - audio stream tag is %s:%s",
+ identifier, message.audio.property.name, message.audio.property.match.pattern);
}
message.audio.type = RESMSG_AUDIO;
@@ -458,7 +519,7 @@ bool ResourceEngine::registerAudioProperties(const QString &audioGroup, quint32
messageMap.insert(requestId, RESMSG_AUDIO);
- qDebug("audio %u:%u", resourceSet->id(), requestId);
+ qDebug("ResourceEngine(%d) - audio %u:%u", identifier, resourceSet->id(), requestId);
int success = resproto_send_message(libresourceSet, &message, statusCallbackHandler);
if(!success)
@@ -469,6 +530,8 @@ bool ResourceEngine::registerAudioProperties(const QString &audioGroup, quint32
static void connectionIsUp(resconn_t *connection)
{
+ qDebug("**************** %s() - locking....", __FUNCTION__);
+ QMutexLocker locker(&mutex);
if (NULL == connection->dbus.rsets->userdata) {
qDebug("IGNORING connectionIsUp");
return;
@@ -482,15 +545,19 @@ static void connectionIsUp(resconn_t *connection)
void ResourceEngine::handleConnectionIsUp(resconn_t *connection)
{
- if(ResourceEngine::libresourceConnection == connection)
+
+ if(ResourceEngine::libresourceConnection == connection) {
+ qDebug("ResourceEngine(%d) - connected to manager, connection=%p", identifier, connection);
emit connectedToManager();
+ }
else {
- qDebug("ignoring Connection is up, it is not for us (%p != %p)",
- ResourceEngine::libresourceConnection, connection);
+ qDebug("ResourceEngine(%d) - ignoring Connection is up, it is not for us (%p != %p)",
+ identifier, ResourceEngine::libresourceConnection, connection);
}
}
quint32 ResourceEngine::id()
{
- return resourceSet->id();
+ return identifier;
}
+
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index c7c9090..fe3260a 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -48,6 +48,7 @@ public:
void handleError(quint32 requestNo, qint32 code, const char *message);
quint32 id();
+ bool toBeDeleted();
signals:
void resourcesBecameAvailable(quint32 bitmaskOfAvailableResources);
@@ -59,7 +60,6 @@ signals:
void disconnectedFromManager();
private:
-
bool connected;
ResourceSet *resourceSet;
DBusConnection *dbusConnection;
@@ -69,7 +69,8 @@ private:
quint32 connectionMode;
static quint32 libresourceUsers;
static resconn_t *libresourceConnection;
-
+ quint32 identifier;
+ bool aboutToBeDeleted;
};
}
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index d28eb79..b15e556 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -2,6 +2,7 @@
#include "resource-engine.h"
using namespace ResourcePolicy;
+static quint32 resourceSetId=1;
ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent)
: QObject(parent), resourceClass(applicationClass), resourceEngine(NULL),
@@ -9,20 +10,22 @@ ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent)
initialized(false), pendingAcquire(false), pendingUpdate(false),
pendingAudioProperties(false)
{
- identifier = (quint32)this;
+ identifier = resourceSetId++;
memset(resourceSet, 0, sizeof(QPointer<Resource *>)*NumberOfTypes);
}
ResourceSet::~ResourceSet()
{
+ qDebug("ResourceSet::%s(%d)", __FUNCTION__, identifier);
for (int i = 0;i < NumberOfTypes;i++) {
delete resourceSet[i];
}
if(resourceEngine != NULL) {
+ qDebug("ResourceSet::%s(%d) - resourceEngine->disconnectFromManager()", __FUNCTION__, identifier);
resourceEngine->disconnect(this);
resourceEngine->disconnectFromManager();
- delete resourceEngine;
}
+ qDebug("ResourceSet::%s(%d) - deleted!", __FUNCTION__, identifier);
}
bool ResourceSet::initialize()
@@ -43,24 +46,30 @@ bool ResourceSet::initialize()
this, SLOT(handleResourcesLost(quint32)));
QObject::connect(resourceEngine, SIGNAL(resourcesBecameAvailable(quint32)),
this, SLOT(handleResourcesBecameAvailable(quint32)));
+ qDebug("initializing resource engine...");
if (!resourceEngine->initialize()) {
return false;
}
+ qDebug("resourceEngine->initialize() returned true");
if (!resourceEngine->connectToManager()) {
return false;
}
qDebug("ResourceSet is initialized engine=%p", resourceEngine);
initialized = true;
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
return true;
}
void ResourceSet::addResourceObject(Resource *resource)
{
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
if(resource == NULL)
return;
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
delete resourceSet[resource->type()];
resourceSet[resource->type()] = resource;
- if (resource->type() == AudioPlaybackType) {
+ if ((resource->type() == AudioPlaybackType)) {
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
audioResource = static_cast<AudioResource *>(resource);
QObject::connect(audioResource,
SIGNAL(audioPropertiesChanged(const QString &, quint32,
@@ -68,12 +77,15 @@ void ResourceSet::addResourceObject(Resource *resource)
this,
SLOT(handleAudioPropertiesChanged(const QString &, quint32,
const QString &, const QString &)));
- if(audioResource->streamTagIsSet() || audioResource->audioGroupIsSet() ||
- (audioResource->processID() > 0))
+ if(audioResource->streamTagIsSet() && (audioResource->processID() > 0))
{
qDebug("registering audio properties");
registerAudioProperties();
}
+ else if (audioResource->audioGroupIsSet()) {
+ qDebug("ResourceSet::%s().... %d registering audio proprerties later", __FUNCTION__, __LINE__);
+ pendingAudioProperties = true;
+ }
}
}
@@ -181,16 +193,19 @@ Resource * ResourceSet::resource(ResourceType type) const
bool ResourceSet::acquire()
{
if (!initialized) {
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
pendingAcquire = true;
return initialize();
}
if (!resourceEngine->isConnectedToManager()) {
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
pendingAcquire = true;
resourceEngine->connectToManager();
return true;
}
else {
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
return resourceEngine->acquireResources();
}
}
@@ -250,6 +265,7 @@ bool ResourceSet::alwaysGetReply()
void ResourceSet::connectedHandler()
{
+ qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
qDebug("Connected to manager!");
if (pendingAudioProperties) {
registerAudioProperties();
diff --git a/tests/test-resource-engine/test-resource-engine.cpp b/tests/test-resource-engine/test-resource-engine.cpp
index 42f1a0e..f74de51 100644
--- a/tests/test-resource-engine/test-resource-engine.cpp
+++ b/tests/test-resource-engine/test-resource-engine.cpp
@@ -4,6 +4,7 @@
using namespace ResourcePolicy;
quint32 theID = 0;
+quint32 resproto_init_calls = 0;
void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message);
static bool strverify(const char *a, const char *b);
@@ -47,11 +48,22 @@ TestResourceEngine::~TestResourceEngine()
void TestResourceEngine::init()
{
+ resproto_init_calls=0;
resourceEngine = new ResourceEngine(resourceSet);
bool initializeSucceeded = resourceEngine->initialize();
acquireOrDenyWasCalled = false;
QVERIFY(!resourceEngine->isConnectedToManager());
QVERIFY(initializeSucceeded);
+ QVERIFY(resourceSet->id() == theID);
+}
+
+void TestResourceEngine::cleanup()
+{
+ delete(resourceEngine);
+
+ QVERIFY(ResourceEngine::libresourceConnection == NULL);
+ QVERIFY(ResourceEngine::libresourceUsers == 0);
+ resproto_init_calls=0;
}
void TestResourceEngine::testConnect()
@@ -258,6 +270,27 @@ void TestResourceEngine::testRegisterAudioProperties()
QVERIFY(audioPropertiesSetSucceeded);
}
+void TestResourceEngine::testMultipleInstences()
+{
+ ResourceSet *resSet;
+ ResourceEngine *resEngine;
+ resconn_t * resConn = ResourceEngine::libresourceConnection;
+ resSet = new ResourceSet("background", this);
+ resEngine = new ResourceEngine(resSet);
+ bool initializeSucceeded = resEngine->initialize();
+ acquireOrDenyWasCalled = false;
+
+ QVERIFY(!resEngine->isConnectedToManager());
+ QVERIFY(initializeSucceeded);
+ QVERIFY(resEngine->id() != theID);
+ QVERIFY(ResourceEngine::libresourceConnection == resConn);
+ QVERIFY(ResourceEngine::libresourceUsers == 2);
+
+ delete(resEngine);
+ QVERIFY(ResourceEngine::libresourceConnection == resConn);
+ delete(resSet);
+}
+
QTEST_MAIN(TestResourceEngine)
////////////////////////////////////////////////////////////////
@@ -272,6 +305,8 @@ resconn_t* resproto_init(resproto_role_t role, resproto_transport_t transport, .
DBusConnection *dbusConnection;
va_list args;
+ resproto_init_calls += 1;
+
va_start(args, transport);
callbackFunction = va_arg(args, resconn_linkup_t);
dbusConnection = va_arg(args, DBusConnection *);
@@ -296,6 +331,8 @@ static void verify_resproto_init(resproto_role_t role,
QVERIFY(dbusConnection == sessionBus);
QVERIFY(role == RESPROTO_ROLE_CLIENT);
QVERIFY(transport == RESPROTO_TRANSPORT_DBUS);
+ qDebug("resproto_init_calls==%u", resproto_init_calls);
+ QVERIFY(resproto_init_calls==1);
}
resset_t *resconn_connect(resconn_t *connection, resmsg_t *message,
@@ -477,4 +514,6 @@ char *resmsg_dump_message(resmsg_t *resmsg,
int len)
{
char * ret = strdup("message");
-} \ No newline at end of file
+ return ret;
+}
+
diff --git a/tests/test-resource-engine/test-resource-engine.h b/tests/test-resource-engine/test-resource-engine.h
index 5398a72..ddefbea 100644
--- a/tests/test-resource-engine/test-resource-engine.h
+++ b/tests/test-resource-engine/test-resource-engine.h
@@ -34,6 +34,7 @@ public slots:
private slots:
void init();
+ void cleanup();
void testConnect();
void testDisconnect();
@@ -48,6 +49,8 @@ private slots:
void testRegisterAudioProperties_data();
void testRegisterAudioProperties();
+
+ void testMultipleInstences();
};
#endif