From c8917f1cbbf96a1c5c655d9adbd45a46833e70db Mon Sep 17 00:00:00 2001 From: Wolf Bergenheim Date: Wed, 1 Dec 2010 16:26:59 +0200 Subject: Added support for RESMSG_RELEASE message from manager --- libresourceqt/include/qt4/policy/resource-set.h | 6 ++++ libresourceqt/src/resource-engine.cpp | 38 ++++++++++++++++++++++--- libresourceqt/src/resource-engine.h | 2 ++ libresourceqt/src/resource-set.cpp | 2 ++ resourceqt-client/client.cpp | 13 +++++++++ resourceqt-client/client.h | 1 + 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h index d37b514..25a8309 100644 --- a/libresourceqt/include/qt4/policy/resource-set.h +++ b/libresourceqt/include/qt4/policy/resource-set.h @@ -283,6 +283,12 @@ signals: * This signal is emitted as a response to the release() request. */ void resourcesReleased(); + /** + * This signal is emited when the manager releases our acquired resources, + * so that we have to acquire them again when the user wishes to interact + * with us. + */ + void resourcesReleasedByManager(); /** * This signal is emitted when some other program with a higher priority * supersedes us, and as a result we loose (some of) our resources. diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp index b9d9ee2..accb3a0 100644 --- a/libresourceqt/src/resource-engine.cpp +++ b/libresourceqt/src/resource-engine.cpp @@ -39,6 +39,7 @@ static void statusCallbackHandler(resset_t *rset, resmsg_t *msg); static void handleUnregisterMessage(resmsg_t *, resset_t *, void *data); static void handleGrantMessage(resmsg_t *msg, resset_t *rs, void *data); static void handleAdviceMessage(resmsg_t *msg, resset_t *rs, void *data); +static void handleReleaseMessage(resmsg_t *message, resset_t *rs, void *data); ResourceEngine::ResourceEngine(ResourceSet *resourceSet) : QObject(), connected(false), resourceSet(resourceSet), @@ -111,6 +112,7 @@ bool ResourceEngine::initialize() resproto_set_handler(ResourceEngine::libresourceConnection, RESMSG_UNREGISTER, handleUnregisterMessage); resproto_set_handler(ResourceEngine::libresourceConnection, RESMSG_GRANT, handleGrantMessage); resproto_set_handler(ResourceEngine::libresourceConnection, RESMSG_ADVICE, handleAdviceMessage); + resproto_set_handler(ResourceEngine::libresourceConnection, RESMSG_RELEASE, handleReleaseMessage); engineMap.insert(ResourceEngine::libresourceConnection, this); } else { @@ -186,12 +188,12 @@ void ResourceEngine::receivedGrant(resmsg_notify_t *notifyMessage) emit resourcesLost(allResourcesToBitmask(resourceSet)); } else if (originaloriginalMessageType == RESMSG_ACQUIRE) { - qDebug("ResourceEngine(%d) - request DENIED!", identifier); - emit resourcesDenied(); + qDebug("ResourceEngine(%d) - request DENIED!", identifier); + emit resourcesDenied(); } else if (originaloriginalMessageType == RESMSG_RELEASE) { - qDebug("ResourceEngine(%d) - confirmation to release", identifier); - emit resourcesReleased(); + qDebug("ResourceEngine(%d) - confirmation to release", identifier); + emit resourcesReleased(); } else { qDebug("ResourceEngine(%d) - Ignoring the receivedGrant", identifier); @@ -205,6 +207,34 @@ void ResourceEngine::receivedGrant(resmsg_notify_t *notifyMessage) messageMap.remove(notifyMessage->reqno); } +static void handleReleaseMessage(resmsg_t *message, resset_t *rs, void *) +{ + qDebug("**************** %s() - locking....", __FUNCTION__); + QMutexLocker locker(&mutex); + if (NULL == rs->userdata) { + qDebug("IGNORING release, no context"); + return; + } + ResourceEngine *engine = reinterpret_cast(rs->userdata); + qDebug("recv: release: type=%d, id=%d, reqno=%d, resc=0x%04x engine->id() = %d", + message->notify.type, message->notify.id, message->notify.reqno, + message->notify.resrc, engine->id()); + if(engine->id() != message->any.id) { + qDebug("Received an advice message, but it is not for us. Ignoring (%d != %d)", + engine->id(), message->any.id); + return; + } + + engine->receivedRelease(&(message->notify)); +} + +void ResourceEngine::receivedRelease(resmsg_notify_t *message) +{ + uint32_t allResources = allResourcesToBitmask(resourceSet); + qDebug("ResourceEngine(%d) - %s: have: %02x got %02x", identifier, __FUNCTION__, allResources, message->resrc); + emit resourcesReleasedByManager(); +} + static void handleAdviceMessage(resmsg_t *message, resset_t *libresourceSet, void *) { qDebug("**************** %s() - locking....", __FUNCTION__); diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h index 66b37bd..e3e29c7 100644 --- a/libresourceqt/src/resource-engine.h +++ b/libresourceqt/src/resource-engine.h @@ -65,6 +65,7 @@ public: void disconnected(); void receivedGrant(resmsg_notify_t *notifyMessage); void receivedAdvice(resmsg_notify_t *notifyMessage); + void receivedRelease(resmsg_notify_t *notifyMessage); void handleStatusMessage(quint32 requestNo); void handleError(quint32 requestNo, qint32 code, const char *message); @@ -81,6 +82,7 @@ signals: void connectedToManager(); void disconnectedFromManager(); void errorCallback(quint32 code, const char* ); + void resourcesReleasedByManager(); private: bool connected; diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp index 8b46664..e96c7a0 100644 --- a/libresourceqt/src/resource-set.cpp +++ b/libresourceqt/src/resource-set.cpp @@ -80,6 +80,8 @@ bool ResourceSet::initialize() this, SLOT(handleResourcesBecameAvailable(quint32))); QObject::connect(resourceEngine, SIGNAL(errorCallback(quint32, const char*)), this, SIGNAL(errorCallback(quint32, const char*))); + QObject::connect(resourceEngine, SIGNAL(resourcesReleasedByManager()), + this, SIGNAL(resourcesReleasedByManager())); qDebug("initializing resource engine..."); if (!resourceEngine->initialize()) { diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp index 7fdb2f6..4cd372a 100644 --- a/resourceqt-client/client.cpp +++ b/resourceqt-client/client.cpp @@ -130,6 +130,10 @@ bool Client::initialize(const CommandLineParser &parser) this, SLOT(resourcesBecameAvailableHandler(const QList &)))) { return false; } + if (!connect(resourceSet, SIGNAL(resourcesReleasedByManager()), + this, SLOT(resourceReleasedByManagerHandler()))) { + return false; + } if (!connect(&stdInNotifier, SIGNAL(activated(int)), this, SLOT(readLine(int)))) { return false; } @@ -250,6 +254,15 @@ void Client::resourceReleasedHandler() showPrompt(); } +void Client::resourceReleasedByManagerHandler() +{ + stopTimer(); + + QList allResources = resourceSet->resources(); + outputln << "mgr-released:"<< allResources << endl; + showPrompt(); +} + void Client::resourcesBecameAvailableHandler(const QList &availableResources) { if (pendingAddAudio) { diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h index 3967fee..e73c50c 100644 --- a/resourceqt-client/client.h +++ b/resourceqt-client/client.h @@ -59,6 +59,7 @@ private slots: void resourceDeniedHandler(); void resourceLostHandler(); void resourceReleasedHandler(); + void resourceReleasedByManagerHandler(); void resourcesBecameAvailableHandler(const QList &availableResources); void readLine(int); void doExit(); -- cgit v1.2.3