summaryrefslogtreecommitdiff
path: root/libresourceqt/src/resource-engine.cpp
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-09 12:07:31 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-09 12:14:46 +0200
commit381719b9a0adb8553a041633aed943f5ef48a1ff (patch)
tree6c5db8b6a7342dee77b1e1a010a6618fd824714f /libresourceqt/src/resource-engine.cpp
parent6751c585385f017d08540bbe121606d642afb220 (diff)
downloadlibresourceqt-381719b9a0adb8553a041633aed943f5ef48a1ff.tar.gz
Restructured libresourceqt includes, updated debianpackages to soversion=1.
Fixed ResourceEngine to work with the new Resource object.
Diffstat (limited to 'libresourceqt/src/resource-engine.cpp')
-rw-r--r--libresourceqt/src/resource-engine.cpp180
1 files changed, 116 insertions, 64 deletions
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index cd34c08..a25c789 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -1,18 +1,24 @@
#include "resource-engine.h"
#include <dbus/dbus.h>
-#include <Resource>
using namespace ResourcePolicy;
-static void connectionIsUp(resconn_t *connection);
static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet);
static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet);
static inline quint32 sharedResourcesToBitmask(const ResourceSet *resourceSet);
+static inline quint32 resourceTypeToLibresourceType(ResourceType type);
+
+static void connectionIsUp(resconn_t *connection);
+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);
ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
- : QObject(resourceSet), resourceSet(resourceSet), requestId(0)
+ : QObject(resourceSet), connected(false), resourceSet(resourceSet),
+ libresourceConnection(NULL), libresourceSet(NULL), requestId(0),
+ messageMap()
{
- identifier = (quint32)this;
}
ResourceEngine::~ResourceEngine()
@@ -27,104 +33,159 @@ bool ResourceEngine::initialize()
dbus_error_init(&dbusError);
dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusError);
if(dbus_error_is_set(&dbusError)) {
- qDebug("Error while connection to the system bus: %s", dbusError.message);
- dbus_error_free(&dbusError);
- return false;
+ qDebug("Error getting the system bus: %s", dbusError.message);
+ dbus_error_free(&dbusError);
+ return false;
}
dbus_error_free(&dbusError);
libresourceConnection = resproto_init(RESPROTO_ROLE_CLIENT, RESPROTO_TRANSPORT_DBUS,
connectionIsUp, dbusConnection);
if(libresourceConnection == NULL) {
- return NULL;
+ return NULL;
}
-/* resproto_set_handler(libresourceConnection, RESMSG_UNREGISTER, handleUnregisterMessage);
+ resproto_set_handler(libresourceConnection, RESMSG_UNREGISTER, handleUnregisterMessage);
resproto_set_handler(libresourceConnection, RESMSG_GRANT, handleGrantMessage);
- resproto_set_handler(libresourceConnection, RESMSG_ADVICE, handleAdviceMessage);*/
+ resproto_set_handler(libresourceConnection, RESMSG_ADVICE, handleAdviceMessage);
+
return true;
}
+static void handleUnregisterMessage(resmsg_t *, resset_t *, void *data)
+{
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+
+ engine->disconnected();
+}
+
+void ResourceEngine::disconnected()
+{
+ qDebug("disconnected");
+
+ connected = false;
+}
+
+static void handleGrantMessage(resmsg_t *msg, resset_t *, void *data)
+{
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+
+ engine->receivedGrant(&(msg->notify));
+}
+
+void ResourceEngine::receivedGrant(resmsg_notify_t *notifyMessage)
+{
+ char buf[80];
+ resmsg_res_str(notifyMessage->resrc, buf, sizeof(buf));
+ qDebug("%s: %s", __FUNCTION__, buf);
+}
+
+static void handleAdviceMessage(resmsg_t *msg, resset_t *, void *data)
+{
+ ResourceEngine *engine = reinterpret_cast<ResourceEngine *>(data);
+
+ engine->receivedAdvice(&(msg->notify));
+}
+
+void ResourceEngine::receivedAdvice(resmsg_notify_t *notifyMessage)
+{
+ char buf[80];
+ resmsg_res_str(notifyMessage->resrc, buf, sizeof(buf));
+ qDebug("%s: %s", __FUNCTION__, buf);
+}
+
bool ResourceEngine::connect()
{
resmsg_t resourceMessage;
resourceMessage.record.type = RESMSG_REGISTER;
- resourceMessage.record.id = identifier;
- resourceMessage.record.reqno = ++reqestId;
+ resourceMessage.record.id = resourceSet->id();
+ resourceMessage.record.reqno = ++requestId;
- requestMap.insert(requestId, RESMSG_REGISTER);
+ messageMap.insert(requestId, RESMSG_REGISTER);
uint32_t allResources, optionalResources, sharedResources;
allResources = allResourcesToBitmask(resourceSet);
- allResources = optionalResourcesToBitmask(resourceSet);
- allResources = sharedResourcesToBitmask(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
- resourceMessage.record.klass = resourceSet->applicationClass();
+ QByteArray ba = resourceSet->applicationClass().toLatin1();
+ resourceMessage.record.klass = ba.data();
+
resourceMessage.record.mode = 0; //No auto release
- libresourceSet = resconn_connect(libresourceConnection, &resourceMessage, handleConnect);
+ libresourceSet = resconn_connect(libresourceConnection, &resourceMessage,
+ statusCallbackHandler);
libresourceSet->userdata = this; //save our context
- index = REQHASH_INDEX(reqno);
- reqtyp[index] = RESMSG_REGISTER;
return true;
}
static inline quint32 allResourcesToBitmask(const ResourceSet *resourceSet)
{
- QList<Resource> resourceList = resourceSet->resources();
+ QList<Resource *> resourceList = resourceSet->resources();
quint32 bitmask=0;
for(int i=0; i < resourceList.size(); i++) {
- switch(resourceList[i].type()) {
- case AudioPlaybackResource:
+ bitmask += resourceTypeToLibresourceType(resourceList[i]->type());
+ }
+ return bitmask;
+}
+
+static inline quint32 resourceTypeToLibresourceType(ResourceType type)
+{
+ quint32 bitmask=0;
+ switch(type) {
+ case AudioPlaybackType:
bitmask += RESMSG_AUDIO_PLAYBACK;
break;
- case VideoPlaybackResource:
+ case VideoPlaybackType:
bitmask += RESMSG_VIDEO_PLAYBACK;
break;
- case AudioRecorderResource:
+ case AudioRecorderType:
bitmask += RESMSG_AUDIO_RECORDING;
break;
- case VideoRecorderResource:
+ case VideoRecorderType:
bitmask += RESMSG_VIDEO_RECORDING;
break;
- case VibraResource:
+ case VibraType:
bitmask += RESMSG_VIBRA;
break;
- case
+ case LedsType:
+ bitmask += RESMSG_LEDS;
+ break;
+ case BacklightType:
+ bitmask += RESMSG_BACKLIGHT;
+ break;
+ case SystemButtonType:
+ bitmask += RESMSG_SYSTEM_BUTTON;
+ case LockButtonType:
+ bitmask += RESMSG_LOCK_BUTTON;
+ break;
+ case ScaleButtonType:
+ bitmask += RESMSG_SCALE_BUTTON;
+ break;
+ case SnapButtonType:
+ bitmask += RESMSG_SNAP_BUTTON;
+ break;
+ case LensCoverType:
+ bitmask += RESMSG_LENS_COVER;
+ break;
default:
break;
- }
}
return bitmask;
}
static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet)
{
- QList<Resource> resourceList = resourceSet->resources();
+ QList<Resource *> resourceList = resourceSet->resources();
quint32 bitmask=0;
for(int i=0; i < resourceList.size(); i++) {
- if(resourceList[i].isOptional()) {
- switch(resourceList[i].type()) {
- case AudioPlaybackResource:
- bitmask += RESMSG_AUDIO_PLAYBACK;
- break;
- case VideoPlaybackResource:
- bitmask += RESMSG_VIDEO_PLAYBACK;
- break;
- case AudioRecorderResource:
- bitmask += RESMSG_AUDIO_RECORDING;
- break;
- case VideoRecorderResource:
- bitmask += RESMSG_VIDEO_RECORDING;
- break;
- default:
- break;
- }
+ if(resourceList[i]->isOptional()) {
+ bitmask += resourceTypeToLibresourceType(resourceList[i]->type());
}
}
return bitmask;
@@ -132,31 +193,21 @@ static inline quint32 optionalResourcesToBitmask(const ResourceSet *resourceSet)
static inline quint32 sharedResourcesToBitmask(const ResourceSet *resourceSet)
{
- QList<Resource> resourceList = resourceSet->resources();
+ QList<Resource *> resourceList = resourceSet->resources();
quint32 bitmask=0;
for(int i=0; i < resourceList.size(); i++) {
- if(resourceList[i].isShared()) {
- switch(resourceList[i].type()) {
- case AudioPlaybackResource:
- bitmask += RESMSG_AUDIO_PLAYBACK;
- break;
- case VideoPlaybackResource:
- bitmask += RESMSG_VIDEO_PLAYBACK;
- break;
- case AudioRecorderResource:
- bitmask += RESMSG_AUDIO_RECORDING;
- break;
- case VideoRecorderResource:
- bitmask += RESMSG_VIDEO_RECORDING;
- break;
- default:
- break;
- }
+ if(resourceList[i]->isShared()) {
+ bitmask += resourceTypeToLibresourceType(resourceList[i]->type());
}
}
return bitmask;
}
+static void statusCallbackHandler(resset_t *rset, resmsg_t *msg)
+{
+ qDebug("Received a status notification");
+}
+
bool ResourceEngine::isConnected()
{
return false;
@@ -195,3 +246,4 @@ void ResourceEngine::handleConnectionIsUp()
{
emit connectedToManager();
}
+