summaryrefslogtreecommitdiff
path: root/libresourceqt
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:28:01 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:28:01 +0200
commitbece735d920909a83e290a790be0d76224653b07 (patch)
tree2d56daf9f1cc79039a7d9c40722ab566ab9ad424 /libresourceqt
parent6a47ede3a71e22b09a09169818705351c00abf9d (diff)
parent78db2c0b916d68a0c4056d4be7228a606b2f9dac (diff)
Merge branch 'master' into meego
Diffstat (limited to 'libresourceqt')
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h22
-rw-r--r--libresourceqt/src/resource-engine.cpp38
-rw-r--r--libresourceqt/src/resource-engine.h2
-rw-r--r--libresourceqt/src/resource-set.cpp28
4 files changed, 79 insertions, 11 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index dad892e..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>.
*/
/**
@@ -209,6 +213,13 @@ public:
QString applicationClass();
/**
+ * Initialize and connect the ResourceEngine of this ResourceSet.
+ * Use this method after adding resources to the ResourceSet initially.
+ * \return true if the method succeeds without encountering errors.
+ */
+ bool initAndConnect();
+
+ /**
* Try to acquire the \ref ResourceSet. The resourcesGranted() or
* resourcesDenied() signal will be emited depending on whether the
* requested resources could be acquired or not.
@@ -280,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
@@ -293,6 +310,11 @@ signals:
*/
void errorCallback(quint32, const char*);
+ /**
+ * This signals that we have connected to the Resource Manager.
+ */
+ void connectedToManager();
+
private:
bool initialize();
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 8b46664..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()) {
@@ -228,21 +230,32 @@ Resource * ResourceSet::resource(ResourceType type) const
return resourceSet[type];
}
-bool ResourceSet::acquire()
+bool ResourceSet::initAndConnect()
{
- if (!initialized) {
+ if ( !initialized ) {
qDebug("ResourceSet::%s().... initializing...", __FUNCTION__);
- pendingAcquire = true;
return initialize();
}
- if (!resourceEngine->isConnectedToManager()) {
+ if ( !resourceEngine->isConnectedToManager() ) {
qDebug("ResourceSet::%s().... connecting...", __FUNCTION__);
+ return resourceEngine->connectToManager();
+ }
+ else
+ qDebug("ResourceSet::%s(): already connected", __FUNCTION__);
+
+ return true;
+}
+
+bool ResourceSet::acquire()
+{
+ if ( !initialized || !resourceEngine->isConnectedToManager() )
+ {
pendingAcquire = true;
- resourceEngine->connectToManager();
- return true;
+ return initAndConnect();
}
- else {
+ else
+ {
qDebug("ResourceSet::%s().... acquiring", __FUNCTION__);
return resourceEngine->acquireResources();
}
@@ -309,6 +322,7 @@ void ResourceSet::connectedHandler()
qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
if (resourceEngine->isConnectedToManager()) {
qDebug("ResourceSet::%s() Connected to manager!", __FUNCTION__);
+ emit connectedToManager();
if (pendingAudioProperties) {
registerAudioProperties();