summaryrefslogtreecommitdiff
path: root/libresourceqt
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
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')
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h (renamed from libresourceqt/include/resource-set.h)17
-rw-r--r--libresourceqt/include/qt4/policy/resource.h (renamed from libresourceqt/include/resource.h)0
-rw-r--r--libresourceqt/include/qt4/policy/resources.h (renamed from libresourceqt/include/resources.h)2
-rw-r--r--libresourceqt/libresourceqt.pro20
-rw-r--r--libresourceqt/src/resource-engine.cpp180
-rw-r--r--libresourceqt/src/resource-engine.h14
-rw-r--r--libresourceqt/src/resource-factory.cpp31
-rw-r--r--libresourceqt/src/resource-set.cpp10
-rw-r--r--libresourceqt/src/resource.cpp2
-rw-r--r--libresourceqt/src/resources.cpp2
10 files changed, 154 insertions, 124 deletions
diff --git a/libresourceqt/include/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index 1f515ee..632ed71 100644
--- a/libresourceqt/include/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -1,7 +1,7 @@
#ifndef RESOURCE_SET_H
#define RESOURCE_SET_H
-#include "resources.h"
+#include <policy/resources.h>
#include <QString>
#include <QObject>
#include <QVector>
@@ -18,12 +18,12 @@
*
* \section library_use_section Library Usage
*
- * To use the Resource Policy Library, you first need to create a set of
+ * To use the Resource Policy Library, you first need to create a number of
* \ref Resource objects like this (given as an example of what a media player
* might want/need):
* \code
* ResourcePolicy::AudioResource *audioResource = new ResourcePolicy::AudioResource();
- * ResourcePolicy::VideoResource *audioResource = new ResourcePolicy::AudioResource();
+ * ResourcePolicy::VideoResource *audioResource = new ResourcePolicy::VideoResource();
* videoResource->setOptional();
* \endcode
* Then you need to create a \ref ResourcePolicy::ResourceSet like this:
@@ -106,7 +106,7 @@ namespace ResourcePolicy
* This method returns a list of all resource in the set.
* \return a QList of all resources in the set.
*/
- QList<Resource *> resources();
+ QList<Resource *> resources() const;
/**
* This method returns a const pointer to a resource of a specific type.
* \type The type of resource we are interested in.
@@ -128,6 +128,7 @@ namespace ResourcePolicy
bool contains(const QList<ResourceType> &types) const;
quint32 id() const;
+ QString applicationClass();
/**
* Connects to the Resource Policy Manager. The connected() signal is sent
@@ -168,12 +169,12 @@ namespace ResourcePolicy
* the given resources have become available.
* \param availableResources A list of available resources.
*/
- void resourcesBecameAvailable(QList<Resource *> availableResources);
+ void resourcesBecameAvailable(QList<ResourceType> availableResources);
/**
* This signal is emited as a response to the acquire() request.
- * \param grantedResources The list of granted optional resources.
+ * \param grantedOptionalResources The list of granted optional resources.
*/
- void resourcesGranted(QList<Resource *> grantedOptionalResources);
+ void resourcesGranted(QList<ResourceType> grantedOptionalResources);
/**
* This signal is emited as a response to the acquire() request, in the
* case where we are not granted any requests.
@@ -197,7 +198,7 @@ namespace ResourcePolicy
private:
quint32 identifier;
- const QString applicationClass;
+ const QString resourceClass;
Resource* resourceSet[NumberOfTypes];
};
}
diff --git a/libresourceqt/include/resource.h b/libresourceqt/include/qt4/policy/resource.h
index 13265d5..13265d5 100644
--- a/libresourceqt/include/resource.h
+++ b/libresourceqt/include/qt4/policy/resource.h
diff --git a/libresourceqt/include/resources.h b/libresourceqt/include/qt4/policy/resources.h
index 8e3da70..47002d7 100644
--- a/libresourceqt/include/resources.h
+++ b/libresourceqt/include/qt4/policy/resources.h
@@ -1,7 +1,7 @@
#ifndef RESOURCES_H
#define RESOURCES_H
-#include "resource.h"
+#include <policy/resource.h>
#include <QObject>
#include <QString>
diff --git a/libresourceqt/libresourceqt.pro b/libresourceqt/libresourceqt.pro
index b9e5cd5..a80eac8 100644
--- a/libresourceqt/libresourceqt.pro
+++ b/libresourceqt/libresourceqt.pro
@@ -1,17 +1,18 @@
+include(../common.pri)
TEMPLATE = lib
-VERSION = 1.0.0
TARGET = resourceqt
DESTDIR = build
-DEPENDPATH += include src
-INCLUDEPATH += src include ../libresource/src
+DEPENDPATH += $${POLICY} src
+INCLUDEPATH += $${LIBRESOURCEINC} src
# Input
-PUBLIC_HEADERS = include/resource.h include/resource-set.h include/resources.h
+PUBLIC_HEADERS = $${POLICY}/resource.h $${POLICY}/resource-set.h $${POLICY}/resources.h
-HEADERS += $$PUBLIC_HEADERS
+HEADERS += $${PUBLIC_HEADERS} src/resource-engine.h
SOURCES += src/resource.cpp \
src/resource-set.cpp \
+ src/resource-engine.cpp \
src/resources.cpp
OBJECTS_DIR = build
@@ -19,12 +20,13 @@ MOC_DIR = build
CONFIG += qt link_pkgconfig dll
QT = core
-PKGCONFIG += dbus-1
+PKGCONFIG += dbus-1 libresource0
# Install directives
-headers.files = $$PUBLIC_HEADERS
+headers.files = $${PUBLIC_HEADERS}
INSTALLBASE = /usr
-target.path = $$INSTALLBASE/lib
-headers.path = $$INSTALLBASE/include/resource/qt4
+target.path = $${INSTALLBASE}/lib
+headers.path = $${INSTALLBASE}/include/resource/qt4/policy
INSTALLS = target headers
+
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();
}
+
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 9dd5fe5..863a23b 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -5,18 +5,16 @@
#include <QMap>
#include <dbus/dbus.h>
#include <res-conn.h>
-#include "resource-set.h"
+#include <policy/resource-set.h>
namespace ResourcePolicy {
-class ResourceEngineData;
-
class ResourceEngine: public QObject
{
Q_OBJECT
Q_DISABLE_COPY( ResourceEngine )
public:
- ResourceEngine(ResourceSet *resourceSet=NULL);
+ ResourceEngine(ResourceSet *resourceSet);
~ResourceEngine();
bool initialize();
@@ -33,9 +31,13 @@ public:
void handleConnectionIsUp();
+ void disconnected();
+ void receivedGrant(resmsg_notify_t *notifyMessage);
+ void receivedAdvice(resmsg_notify_t *notifyMessage);
+
signals:
- void resourcesBecameAvailable(QList<Resource> availableResources);
- void resourcesAcquired(QList<Resource> grantedResources);
+ void resourcesBecameAvailable(QList<Resource *> availableResources);
+ void resourcesAcquired(QList<Resource *> grantedResources);
void resourcesDenied();
void lostResources();
void connectedToManager();
diff --git a/libresourceqt/src/resource-factory.cpp b/libresourceqt/src/resource-factory.cpp
deleted file mode 100644
index f500792..0000000
--- a/libresourceqt/src/resource-factory.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-#include "resource-factory.h"
-#include "libplayback-wrapper.h"
-
-using namespace ResourceTypes;
-
-ResourceFactory::ResourceFactory(QObject *parent)
- : QObject(parent), sessionBusConnection(QDBusConnection::sessionBus())
-{
-}
-
-ResourceFactory::~ResourceFactory()
-{
-}
-
-Resource * ResourceFactory::createResource(enum ResourceClass applicationClass,
- quint16 requestedResources)
-{
- qDebug("We %s connected to DBus",sessionBusConnection.isConnected()?"are":"are not");
- Resource *resource = new Resource(applicationClass, requestedResources, this);
- ResourceLibrary *libPlayback = new LibPlaybackWrapper(resource);
-
- bool resourceProperlyInitialized = resource->initialize(libPlayback);
- if(resourceProperlyInitialized) {
- return resource;
- }
- else {
- qDebug("Failed to initialize Resource. Returning NULL!");
- delete resource;
- return NULL;
- }
-}
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index c7862ef..6ff8d9a 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -1,9 +1,9 @@
-#include "resource-set.h"
+#include <policy/resource-set.h>
using namespace ResourcePolicy;
ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent)
- : QObject(parent), applicationClass(applicationClass)
+ : QObject(parent), resourceClass(applicationClass)
{
identifier = (quint32)this;
memset(resourceSet, 0, sizeof(QPointer<Resource>)*NumberOfTypes);
@@ -60,7 +60,7 @@ quint32 ResourceSet::id() const
return identifier;
}
-QList<Resource *> ResourceSet::resources()
+QList<Resource *> ResourceSet::resources() const
{
QList<Resource *> listOfResources;
for(int i=0; i < NumberOfTypes; i++) {
@@ -109,3 +109,7 @@ bool ResourceSet::update()
return false;
}
+QString ResourceSet::applicationClass()
+{
+ return this->resourceClass;
+}
diff --git a/libresourceqt/src/resource.cpp b/libresourceqt/src/resource.cpp
index 8207b66..fe1153e 100644
--- a/libresourceqt/src/resource.cpp
+++ b/libresourceqt/src/resource.cpp
@@ -1,4 +1,4 @@
-#include "resource.h"
+#include <policy/resource.h>
using namespace ResourcePolicy;
diff --git a/libresourceqt/src/resources.cpp b/libresourceqt/src/resources.cpp
index 9858bd3..c763ebc 100644
--- a/libresourceqt/src/resources.cpp
+++ b/libresourceqt/src/resources.cpp
@@ -1,4 +1,4 @@
-#include "resources.h"
+#include <policy/resources.h>
using namespace ResourcePolicy;