summaryrefslogtreecommitdiff
path: root/libresourceqt
diff options
context:
space:
mode:
Diffstat (limited to 'libresourceqt')
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h10
-rw-r--r--libresourceqt/src/resource-engine.cpp38
-rw-r--r--libresourceqt/src/resource-engine.h2
-rw-r--r--libresourceqt/src/resource-set.cpp2
4 files changed, 48 insertions, 4 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index fbf8bd8..a36254d 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -104,6 +104,10 @@ USA.
* So it is important that you connect to it.
*
* To modify the properties of the resources you can use the ResourcePolicy::ResourceSet::resource() method.
+ *
+ * \section see_devel_doc See Also
+ * For a more detailed guide see the
+ * <a href="https://projects.maemo.org/mediawiki/index.php/Maemo_Developer_Guide/Developing_Harmattan_applications/Application_policy_guidelines">Application policy guidelines</a>.
*/
/**
@@ -287,6 +291,12 @@ signals:
*/
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.
* It is very important to connect to this signal as it is signaling when
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<ResourceEngine *>(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 086401c..190df5e 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()) {