summaryrefslogtreecommitdiff
path: root/libresourceqt
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-09 16:32:16 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-09 16:32:16 +0200
commit30dcb37e647eed8fd68874f7588cd203ef8fc709 (patch)
tree332dd618866da29d196b2e837d12a671a5d18cdb /libresourceqt
parent910493fac3e328cef329ade5e8c1a71e136ca246 (diff)
downloadlibresourceqt-30dcb37e647eed8fd68874f7588cd203ef8fc709.tar.gz
implemented ResourceEngine::disconnect()
Diffstat (limited to 'libresourceqt')
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h2
-rw-r--r--libresourceqt/src/resource-engine.cpp60
-rw-r--r--libresourceqt/src/resource-engine.h6
3 files changed, 63 insertions, 5 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index 632ed71..d998807 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -32,7 +32,7 @@
* resources->addResource(audioResource);
* resources->addResource(videoResource);
* resources->initialize();
- * QObject::connect(resources, SIGNAL(connectedToManager), this, SLOT(connectedHandler()));
+ * QObject::connect(resources, SIGNAL(connectedToManager()), this, SLOT(connectedHandler()));
* resources->connectToManager();
* \endcode
* Then the when you want to acquire the \ref ResourcePolicy::ResourceSet you simply use the
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index a25c789..9f42a48 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -61,8 +61,8 @@ static void handleUnregisterMessage(resmsg_t *, resset_t *, void *data)
void ResourceEngine::disconnected()
{
qDebug("disconnected");
-
connected = false;
+ emit disconnectedFromManager();
}
static void handleGrantMessage(resmsg_t *msg, resset_t *, void *data)
@@ -124,6 +124,39 @@ bool ResourceEngine::connect()
return true;
}
+bool ResourceEngine::disconnect()
+{
+ resmsg_t resourceMessage;
+ resourceMessage.record.type = RESMSG_UNREGISTER;
+ resourceMessage.record.id = resourceSet->id();
+ resourceMessage.record.reqno = ++requestId;
+
+ messageMap.insert(requestId, RESMSG_UNREGISTER);
+
+ uint32_t allResources, optionalResources, sharedResources;
+ allResources = allResourcesToBitmask(resourceSet);
+ optionalResources = optionalResourcesToBitmask(resourceSet);
+ sharedResources = sharedResourcesToBitmask(resourceSet);
+
+ resourceMessage.record.rset.all = allResources;
+ resourceMessage.record.rset.opt = optionalResources;
+ resourceMessage.record.rset.share = sharedResources;
+ resourceMessage.record.rset.mask = 0; //find out what it is
+
+ QByteArray ba = resourceSet->applicationClass().toLatin1();
+ resourceMessage.record.klass = ba.data();
+
+ resourceMessage.record.mode = 0; //No auto release
+
+ int r = resconn_disconnect(libresourceSet, &resourceMessage,
+ statusCallbackHandler);
+ connected = false;
+ if(r)
+ return true;
+ else
+ return false;
+}
+
static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet)
{
QList<Resource *> resourceList = resourceSet->resources();
@@ -161,6 +194,7 @@ static inline quint32 resourceTypeToLibresourceType(ResourceType type)
break;
case SystemButtonType:
bitmask += RESMSG_SYSTEM_BUTTON;
+ break;
case LockButtonType:
bitmask += RESMSG_LOCK_BUTTON;
break;
@@ -203,14 +237,32 @@ static inline quint32 sharedResourcesToBitmask(const ResourceSet *resourceSet)
return bitmask;
}
-static void statusCallbackHandler(resset_t *rset, resmsg_t *msg)
+static void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message)
{
+ ResourceEngine *resourceEngine = reinterpret_cast<ResourceEngine *>(libresourceSet->userdata);
qDebug("Received a status notification");
+ resourceEngine->handleStatusMessage(message->status.reqno);
+}
+
+void ResourceEngine::handleStatusMessage(quint32 requestNo)
+{
+ resmsg_type_t messageType = messageMap.take(requestNo);
+ if(messageType == RESMSG_REGISTER) {
+ qDebug("connected!");
+ connected = true;
+ emit connectedToManager();
+ }
+ else if(messageType == RESMSG_UNREGISTER) {
+ qDebug("disconnected!");
+ connected = false;
+ emit disconnectedFromManager();
+ }
+
}
bool ResourceEngine::isConnected()
{
- return false;
+ return connected;
}
bool ResourceEngine::acquireResources()
@@ -237,7 +289,7 @@ static void connectionIsUp(resconn_t *connection)
{
ResourceEngine *resourceEngine;
- resourceEngine = (ResourceEngine *)(connection->dbus.rsets->userdata);
+ resourceEngine = reinterpret_cast<ResourceEngine *>(connection->dbus.rsets->userdata);
resourceEngine->handleConnectionIsUp();
}
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 863a23b..6d81d8e 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -13,6 +13,10 @@ class ResourceEngine: public QObject
{
Q_OBJECT
Q_DISABLE_COPY( ResourceEngine )
+#ifndef QT_NO_DEBUG
+ friend class TestResourceEngine;
+#endif
+
public:
ResourceEngine(ResourceSet *resourceSet);
~ResourceEngine();
@@ -35,6 +39,8 @@ public:
void receivedGrant(resmsg_notify_t *notifyMessage);
void receivedAdvice(resmsg_notify_t *notifyMessage);
+ void handleStatusMessage(quint32 requestNo);
+
signals:
void resourcesBecameAvailable(QList<Resource *> availableResources);
void resourcesAcquired(QList<Resource *> grantedResources);