summaryrefslogtreecommitdiff
path: root/libresourceqt
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-15 11:45:24 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-15 11:45:24 +0200
commit75d34a403884640d9203c6eed3ed3b74964e94e8 (patch)
tree442485a59717b92fc3fbad635114e87d5500f121 /libresourceqt
parentf15d3608dc4d6444fb587f9dfbb93c7a8b02c740 (diff)
downloadlibresourceqt-75d34a403884640d9203c6eed3ed3b74964e94e8.tar.gz
Fixed acquire
Diffstat (limited to 'libresourceqt')
-rw-r--r--libresourceqt/src/resource-engine.cpp31
-rw-r--r--libresourceqt/src/resource-engine.h2
-rw-r--r--libresourceqt/src/resource-set.cpp18
3 files changed, 29 insertions, 22 deletions
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index 4d877e3..2c5c1f8 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -32,9 +32,9 @@ bool ResourceEngine::initialize()
return false;
dbus_error_init(&dbusError);
- dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError);
+ dbusConnection = dbus_bus_get(DBUS_BUS_SESSION, &dbusError);
if (dbus_error_is_set(&dbusError)) {
- qDebug("Error getting the system bus: %s", dbusError.message);
+ qDebug("Error getting the session bus: %s", dbusError.message);
dbus_error_free(&dbusError);
return false;
}
@@ -49,13 +49,13 @@ bool ResourceEngine::initialize()
resproto_set_handler(libresourceConnection, RESMSG_UNREGISTER, handleUnregisterMessage);
resproto_set_handler(libresourceConnection, RESMSG_GRANT, handleGrantMessage);
resproto_set_handler(libresourceConnection, RESMSG_ADVICE, handleAdviceMessage);
-
+ qDebug("ResourceEngine (%p) is now initialized.", this);
return true;
}
-static void handleUnregisterMessage(resmsg_t *, resset_t *, void *data)
+static void handleUnregisterMessage(resmsg_t *, resset_t *resSet, void *)
{
- ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(resSet->userdata);
engine->disconnected();
}
@@ -67,27 +67,29 @@ void ResourceEngine::disconnected()
emit disconnectedFromManager();
}
-static void handleGrantMessage(resmsg_t *msg, resset_t *, void *data)
+static void handleGrantMessage(resmsg_t *msg, resset_t *resSet, void *)
{
- ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(resSet->userdata);
engine->receivedGrant(&(msg->notify));
}
void ResourceEngine::receivedGrant(resmsg_notify_t *notifyMessage)
{
- qDebug("received a grant message");
+ qDebug("received a grant message for request %u", notifyMessage->reqno);
if(notifyMessage->resrc == 0) {
+ qDebug("request DENIED!");
emit resourcesDenied();
}
else {
+ qDebug("emiting signal resourcesAcquired(%02x), this=%p", notifyMessage->resrc, this);
emit resourcesAcquired(notifyMessage->resrc);
}
}
-static void handleAdviceMessage(resmsg_t *msg, resset_t *, void *data)
+static void handleAdviceMessage(resmsg_t *msg, resset_t *resSet, void *)
{
- ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(resSet->userdata);
engine->receivedAdvice(&(msg->notify));
}
@@ -122,6 +124,7 @@ bool ResourceEngine::connect()
resourceMessage.record.mode = mode;
+ qDebug("ResourceEngine is now connecting...");
libresourceSet = resconn_connect(libresourceConnection, &resourceMessage,
statusCallbackHandler);
@@ -227,8 +230,8 @@ static void statusCallbackHandler(resset_t *libresourceSet, resmsg_t *message)
resourceEngine->handleError(message->status.reqno, message->status.errcod, message->status.errmsg);
}
else {
-// resourceEngine->handleStatusMessage(message->status.reqno);
- qDebug("Received a status message of type 0x%02x and #:%u", message->type, message->status.reqno);
+ qDebug("Received a status message with id %02x and #:%u", message->status.id, message->status.reqno);
+ resourceEngine->handleStatusMessage(message->status.reqno);
}
}
@@ -248,10 +251,10 @@ void ResourceEngine::handleStatusMessage(quint32 requestNo)
}
}
-void ResourceEngine::handleError(quint32 requestNo, quint32 code, const char *message)
+void ResourceEngine::handleError(quint32 requestNo, qint32 code, const char *message)
{
resmsg_type_t messageType = messageMap.take(requestNo);
- qDebug("Error on request %u(0x%02x): %u - %s", requestNo, messageType, code, message);
+ qDebug("Error on request %u(0x%02x): %d - %s", requestNo, messageType, code, message);
}
bool ResourceEngine::isConnected()
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index a3693e9..34f416a 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -44,7 +44,7 @@ public:
void receivedAdvice(resmsg_notify_t *notifyMessage);
void handleStatusMessage(quint32 requestNo);
- void handleError(quint32 requestNo, quint32 code, const char *message);
+ void handleError(quint32 requestNo, qint32 code, const char *message);
void setMode(quint32 newMode);
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index 64f7645..7960fad 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -25,19 +25,20 @@ bool ResourceSet::initialize()
if (resourceEngine == NULL) {
return false;
}
- if (!resourceEngine->initialize()) {
- return false;
- }
- if (!resourceEngine->connect()) {
- return false;
- }
QObject::connect(resourceEngine, SIGNAL(connectedToManager()),
this, SLOT(connectedHandler()));
QObject::connect(resourceEngine, SIGNAL(resourcesAcquired(quint32)),
this, SLOT(handleAcquire(quint32)));
QObject::connect(resourceEngine, SIGNAL(resourcesDenied()),
this, SLOT(handleDeny()));
-
+ if (!resourceEngine->initialize()) {
+ return false;
+ }
+ if (!resourceEngine->connect()) {
+ return false;
+ }
+ qDebug("ResourceSet is initialized engine=%p", resourceEngine);
+ initialized = true;
return true;
}
@@ -113,6 +114,7 @@ bool ResourceSet::acquire()
else if (!resourceEngine->isConnected()) {
pendingAcquire = true;
resourceEngine->connect();
+ return true;
}
else {
return resourceEngine->acquireResources();
@@ -153,6 +155,7 @@ void ResourceSet::connectedHandler()
void ResourceSet::handleAcquire(quint32 bitmaskOfGrantedResources)
{
+ qDebug("in %s",__FUNCTION__);
QList<ResourceType> optionalResources;
qDebug("Acquired resources: 0x%04x", bitmaskOfGrantedResources);
for(int i=0;i < NumberOfTypes; i++) {
@@ -164,6 +167,7 @@ void ResourceSet::handleAcquire(quint32 bitmaskOfGrantedResources)
optionalResources << type;
}
resourceSet[i]->setGranted();
+ qDebug("Resource %02x is now granted", i);
}
}
emit resourcesGranted(optionalResources);