From 381719b9a0adb8553a041633aed943f5ef48a1ff Mon Sep 17 00:00:00 2001 From: Wolf Bergenheim Date: Tue, 9 Feb 2010 12:07:31 +0200 Subject: Restructured libresourceqt includes, updated debianpackages to soversion=1. Fixed ResourceEngine to work with the new Resource object. --- libresourceqt/include/qt4/policy/resource-set.h | 207 ++++++++++++++++++++++++ libresourceqt/include/qt4/policy/resource.h | 80 +++++++++ libresourceqt/include/qt4/policy/resources.h | 169 +++++++++++++++++++ libresourceqt/include/resource-set.h | 206 ----------------------- libresourceqt/include/resource.h | 80 --------- libresourceqt/include/resources.h | 169 ------------------- libresourceqt/libresourceqt.pro | 20 +-- libresourceqt/src/resource-engine.cpp | 180 +++++++++++++-------- libresourceqt/src/resource-engine.h | 14 +- libresourceqt/src/resource-factory.cpp | 31 ---- libresourceqt/src/resource-set.cpp | 10 +- libresourceqt/src/resource.cpp | 2 +- libresourceqt/src/resources.cpp | 2 +- 13 files changed, 600 insertions(+), 570 deletions(-) create mode 100644 libresourceqt/include/qt4/policy/resource-set.h create mode 100644 libresourceqt/include/qt4/policy/resource.h create mode 100644 libresourceqt/include/qt4/policy/resources.h delete mode 100644 libresourceqt/include/resource-set.h delete mode 100644 libresourceqt/include/resource.h delete mode 100644 libresourceqt/include/resources.h delete mode 100644 libresourceqt/src/resource-factory.cpp (limited to 'libresourceqt') diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h new file mode 100644 index 0000000..632ed71 --- /dev/null +++ b/libresourceqt/include/qt4/policy/resource-set.h @@ -0,0 +1,207 @@ +#ifndef RESOURCE_SET_H +#define RESOURCE_SET_H + +#include +#include +#include +#include +#include + +/** + * \mainpage Resource Policy Library + * + * \section intro_section Introduction + * + * This library is used to request resources from the Polict Resource Manager. + * To use this library two classes are provided: \ref ResourcePolicy::Resource and + * \ref ResourcePolicy::ResourceSet. + * + * \section library_use_section Library Usage + * + * 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::VideoResource(); + * videoResource->setOptional(); + * \endcode + * Then you need to create a \ref ResourcePolicy::ResourceSet like this: + * \code + * ResourcePolicy::ResourceSet *resources = new ResourcePolicy::ResourceSet("player"); + * resources->addResource(audioResource); + * resources->addResource(videoResource); + * resources->initialize(); + * 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 + * \ref acquire() method of the \ref ResourceSet object, like this: + * \code + * QObject::connect(resources, SIGNAL(resourcesAcquired), + * this, SLOT(acquireOkHandler(QList))); + * QObject::connect(resources, SIGNAL(resourcesDenied), this, SLOT(acquireDeniedHandler())); + * resources->acquire(); + * \endcode + */ + +/** + * The Namespace for Resource Policy. + */ +namespace ResourcePolicy +{ + /** + * The resourceSet repesents a set of attributes. Each set can only contain + * a single Resource of a given type. That is one AudioPlaybackResource, etc. + * + * Internally the set is stored as a QVector of \ref Resource objects. + */ + class ResourceSet: public QObject + { + Q_OBJECT + Q_DISABLE_COPY( ResourceSet ) + public: + /** + * The constructor. + * \param applicationClass This parameter defines the application class. + * The application class is used to determine the priority order of the + * application. + * \param parent The optional parent of of this class. + */ + ResourceSet(const QString &applicationClass, QObject *parent=NULL); + /** + * The destructor + */ + ~ResourceSet(); + /** + * Initializes the underlaying communications library. + * \return true if initialization is successful. + */ + bool initialize(); + + /** + * This method adds a resource to the set. A set contains only a single + * instance of a given resource. If the ResourceSet already contains a + * resource of the given type it will be overridden. + * \param resource The resource to add to the set. A copy of this object + * is stored in the Set. + */ + void addResource(const Resource *resource); + /** + * This method adds all resources in the list to the set. + * A set contains only a single instance of a given resource. If the + * ResourceSet already contains a resource of the given type it will be + * overridden. + * \param resources The list of resources to add to the set. These will + * be copied. + */ + void addResources(const QListresources); + /** + * This method removes the resource of the given type + * \param type The type of the resource to remove from the set. + */ + void delResource(ResourceType type); + + /** + * This method returns a list of all resource in the set. + * \return a QList of all resources in the set. + */ + QList resources() const; + /** + * This method returns a const pointer to a resource of a specific type. + * \type The type of resource we are interested in. + * \return a pointer to the Resource if it is defined NULL otherwise. + */ + Resource * resource(ResourceType type) const; + /** + * Checks if the \ref ResourceSet contains the given \ref Resource + * \param type The Resource to look for + * \return true if the \ref Resource is defined in this \ref ResourceSet + */ + bool contains(ResourceType type) const; + + /** + * Checks if the \ref ResourceSet contains all given resources. + * \param types A list of resources to check for + * \return true if \b all given resources are defined in the ResourceSet. + */ + bool contains(const QList &types) const; + + quint32 id() const; + QString applicationClass(); + + /** + * Connects to the Resource Policy Manager. The connected() signal is sent + * when the connection has been established. Acquiring the ResourceSet can + * be attempted at any time after this, but not before. + * \return true if the connection request was successfully sent. + * \param reconnectOnDisconnect. Set to true to automatically reconnect on + * lost connection to the Policy Resource Manager. This optional parameter + * defaults to true. + */ + bool connectToManager(bool reconnectOnDisconnect); + /** + * Disconnects from the Resource Policy Manager. Further attempts at acquiring + * the \ref ResourceSet will fail. + */ + void disconnectFromManager(); + /** + * Checks whether the ResourceSet is connected or not. + */ + bool isConnectedToManager(); + /** + * Attempt to acquire the ResourceSet. The response is returned as the + * resourcesAcquired() signal. + */ + bool acquire(); + /** + * Release the acquired resources. + */ + bool release(); + /** + * Commit changes to the \ref ResourceSet to the Manager. + */ + bool update(); + + signals: + /** + * This signal is emited when the Resource Policy Manager notifies that + * the given resources have become available. + * \param availableResources A list of available resources. + */ + void resourcesBecameAvailable(QList availableResources); + /** + * This signal is emited as a response to the acquire() request. + * \param grantedOptionalResources The list of granted optional resources. + */ + void resourcesGranted(QList grantedOptionalResources); + /** + * This signal is emited as a response to the acquire() request, in the + * case where we are not granted any requests. + */ + void resourcesDenied(); + /** + * This signal is emited when some other program with a higher priority + * superseeds us, and as a result we loose our resources. + */ + void lostResources(); + /** + * This signal is emited when we have successfully connected to the manager. + */ + void connectedToManager(); + /** + * This signal is emited when we loose the connection to the manager. + * A reconnect is automatically attempted. + */ + void disconnectedFromManager(); + + + private: + quint32 identifier; + const QString resourceClass; + Resource* resourceSet[NumberOfTypes]; + }; +} + +#endif + diff --git a/libresourceqt/include/qt4/policy/resource.h b/libresourceqt/include/qt4/policy/resource.h new file mode 100644 index 0000000..13265d5 --- /dev/null +++ b/libresourceqt/include/qt4/policy/resource.h @@ -0,0 +1,80 @@ +#ifndef RESOURCE_H +#define RESOURCE_H + +#include + +namespace ResourcePolicy { + enum ResourceType { + AudioPlaybackType = 0, + VideoPlaybackType, + AudioRecorderType, + VideoRecorderType, + VibraType, + LedsType, + BacklightType, + SystemButtonType, + LockButtonType, + ScaleButtonType, + SnapButtonType, + LensCoverType, + NumberOfTypes + }; + + /** + * This class is the super class for all resources. It represents a generic + * \ref Resource. The type specific resource classes should be used. + */ + class Resource + { + public: + /** + * Whether or not this resource is optional, in that it doesn't need to + * be available for the set to be acquired. + * \return true when this resource is optional. + */ + bool isOptional() const; + /** + * Set the resource to be optional or mandatory. + * \param resourceIsOptional This optional parameter defaults to true. + * The default, true, results in the resource becoming optional. When it + * is set to false the resource becomes mandatory. + */ + void setOptional(bool resourceIsOptional=true); + /** + * Whether or not the resource to be shared. If it is shared then other + * programs are allowed to share this resource. + * \return true when this resource is shared. + */ + bool isShared() const; + /** + * Sets the resource to be shared/private. + * \param resourceIsShared This optional parameter defaults to true. + * When it is set to true (de default) the resource is shared with + * other programs. Setting it to false makes this resource exclusive. + */ + void setShared(bool resourceIsShared=true); + /** + * Whether or not this resource has been granted. + * \return true if this resource has been granted. + */ + bool isGranted() const; + void setGranted(); + void unsetGranted(); + + virtual ResourceType type() const = 0; + virtual Resource * clone() const = 0; + virtual ~Resource(); + protected: + Resource(); + Resource(const Resource &other); + + ResourceType resourceType; + bool optional; + bool shared; + quint32 identifier; + bool granted; + }; +} + +#endif + diff --git a/libresourceqt/include/qt4/policy/resources.h b/libresourceqt/include/qt4/policy/resources.h new file mode 100644 index 0000000..47002d7 --- /dev/null +++ b/libresourceqt/include/qt4/policy/resources.h @@ -0,0 +1,169 @@ +#ifndef RESOURCES_H +#define RESOURCES_H + +#include +#include +#include + +namespace ResourcePolicy { + + class AudioResource: public Resource + { + public: + AudioResource(const QString &audioGroup=QString()); + AudioResource(const AudioResource &other); + virtual ~AudioResource(); + + QString audioGroup() const; + void setAudioGroup(const QString & newGroup); + + quint32 processID() const; + void setProcessID(quint32 newPID); + + QString streamTag() const; + void setStreamTag(const QString & newStreamTag); + + virtual ResourceType type() const; + virtual Resource * clone() const; + private: + QString group; + quint32 pid; + QString stream; + }; + + class AudioRecorderResource: public Resource + { + public: + AudioRecorderResource(const QString & audioGroup=QString()); + AudioRecorderResource(const AudioRecorderResource &other); + virtual ~AudioRecorderResource(); + + QString audioGroup() const; + void setAudioGroup(const QString & newGroup); + + quint32 processID() const; + void setProcessID(quint32 newPID); + + QString streamTag() const; + void setStreamTag(const QString & newStreamTag); + + virtual ResourceType type() const; + virtual Resource * clone() const; + private: + QString group; + quint32 pid; + QString stream; + }; + + class BacklightResource: public Resource + { + public: + BacklightResource(); + BacklightResource(const BacklightResource &other); + virtual ~BacklightResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class LedsResource: public Resource + { + public: + LedsResource(); + LedsResource(const LedsResource &other); + virtual ~LedsResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class VibraResource: public Resource + { + public: + VibraResource(); + VibraResource(const VibraResource &other); + virtual ~VibraResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class VideoRecorderResource: public Resource + { + public: + VideoRecorderResource(); + VideoRecorderResource(const VideoRecorderResource &other); + virtual ~VideoRecorderResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class VideoResource: public Resource + { + public: + VideoResource(); + VideoResource(const VideoResource &other); + virtual ~VideoResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class SystemButtonResource: public Resource + { + public: + SystemButtonResource(); + SystemButtonResource(const SystemButtonResource &other); + virtual ~SystemButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class LockButtonResource: public Resource + { + public: + LockButtonResource(); + LockButtonResource(const LockButtonResource &other); + virtual ~LockButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class ScaleButtonResource: public Resource + { + public: + ScaleButtonResource(); + ScaleButtonResource(const ScaleButtonResource &other); + virtual ~ScaleButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class SnapButtonResource: public Resource + { + public: + SnapButtonResource(); + SnapButtonResource(const SnapButtonResource &other); + virtual ~SnapButtonResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; + + class LensCoverResource: public Resource + { + public: + LensCoverResource(); + LensCoverResource(const LensCoverResource &other); + virtual ~LensCoverResource(); + + virtual ResourceType type() const; + virtual Resource * clone() const; + }; +} +#endif + diff --git a/libresourceqt/include/resource-set.h b/libresourceqt/include/resource-set.h deleted file mode 100644 index 1f515ee..0000000 --- a/libresourceqt/include/resource-set.h +++ /dev/null @@ -1,206 +0,0 @@ -#ifndef RESOURCE_SET_H -#define RESOURCE_SET_H - -#include "resources.h" -#include -#include -#include -#include - -/** - * \mainpage Resource Policy Library - * - * \section intro_section Introduction - * - * This library is used to request resources from the Polict Resource Manager. - * To use this library two classes are provided: \ref ResourcePolicy::Resource and - * \ref ResourcePolicy::ResourceSet. - * - * \section library_use_section Library Usage - * - * To use the Resource Policy Library, you first need to create a set 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(); - * videoResource->setOptional(); - * \endcode - * Then you need to create a \ref ResourcePolicy::ResourceSet like this: - * \code - * ResourcePolicy::ResourceSet *resources = new ResourcePolicy::ResourceSet("player"); - * resources->addResource(audioResource); - * resources->addResource(videoResource); - * resources->initialize(); - * 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 - * \ref acquire() method of the \ref ResourceSet object, like this: - * \code - * QObject::connect(resources, SIGNAL(resourcesAcquired), - * this, SLOT(acquireOkHandler(QList))); - * QObject::connect(resources, SIGNAL(resourcesDenied), this, SLOT(acquireDeniedHandler())); - * resources->acquire(); - * \endcode - */ - -/** - * The Namespace for Resource Policy. - */ -namespace ResourcePolicy -{ - /** - * The resourceSet repesents a set of attributes. Each set can only contain - * a single Resource of a given type. That is one AudioPlaybackResource, etc. - * - * Internally the set is stored as a QVector of \ref Resource objects. - */ - class ResourceSet: public QObject - { - Q_OBJECT - Q_DISABLE_COPY( ResourceSet ) - public: - /** - * The constructor. - * \param applicationClass This parameter defines the application class. - * The application class is used to determine the priority order of the - * application. - * \param parent The optional parent of of this class. - */ - ResourceSet(const QString &applicationClass, QObject *parent=NULL); - /** - * The destructor - */ - ~ResourceSet(); - /** - * Initializes the underlaying communications library. - * \return true if initialization is successful. - */ - bool initialize(); - - /** - * This method adds a resource to the set. A set contains only a single - * instance of a given resource. If the ResourceSet already contains a - * resource of the given type it will be overridden. - * \param resource The resource to add to the set. A copy of this object - * is stored in the Set. - */ - void addResource(const Resource *resource); - /** - * This method adds all resources in the list to the set. - * A set contains only a single instance of a given resource. If the - * ResourceSet already contains a resource of the given type it will be - * overridden. - * \param resources The list of resources to add to the set. These will - * be copied. - */ - void addResources(const QListresources); - /** - * This method removes the resource of the given type - * \param type The type of the resource to remove from the set. - */ - void delResource(ResourceType type); - - /** - * This method returns a list of all resource in the set. - * \return a QList of all resources in the set. - */ - QList resources(); - /** - * This method returns a const pointer to a resource of a specific type. - * \type The type of resource we are interested in. - * \return a pointer to the Resource if it is defined NULL otherwise. - */ - Resource * resource(ResourceType type) const; - /** - * Checks if the \ref ResourceSet contains the given \ref Resource - * \param type The Resource to look for - * \return true if the \ref Resource is defined in this \ref ResourceSet - */ - bool contains(ResourceType type) const; - - /** - * Checks if the \ref ResourceSet contains all given resources. - * \param types A list of resources to check for - * \return true if \b all given resources are defined in the ResourceSet. - */ - bool contains(const QList &types) const; - - quint32 id() const; - - /** - * Connects to the Resource Policy Manager. The connected() signal is sent - * when the connection has been established. Acquiring the ResourceSet can - * be attempted at any time after this, but not before. - * \return true if the connection request was successfully sent. - * \param reconnectOnDisconnect. Set to true to automatically reconnect on - * lost connection to the Policy Resource Manager. This optional parameter - * defaults to true. - */ - bool connectToManager(bool reconnectOnDisconnect); - /** - * Disconnects from the Resource Policy Manager. Further attempts at acquiring - * the \ref ResourceSet will fail. - */ - void disconnectFromManager(); - /** - * Checks whether the ResourceSet is connected or not. - */ - bool isConnectedToManager(); - /** - * Attempt to acquire the ResourceSet. The response is returned as the - * resourcesAcquired() signal. - */ - bool acquire(); - /** - * Release the acquired resources. - */ - bool release(); - /** - * Commit changes to the \ref ResourceSet to the Manager. - */ - bool update(); - - signals: - /** - * This signal is emited when the Resource Policy Manager notifies that - * the given resources have become available. - * \param availableResources A list of available resources. - */ - void resourcesBecameAvailable(QList availableResources); - /** - * This signal is emited as a response to the acquire() request. - * \param grantedResources The list of granted optional resources. - */ - void resourcesGranted(QList grantedOptionalResources); - /** - * This signal is emited as a response to the acquire() request, in the - * case where we are not granted any requests. - */ - void resourcesDenied(); - /** - * This signal is emited when some other program with a higher priority - * superseeds us, and as a result we loose our resources. - */ - void lostResources(); - /** - * This signal is emited when we have successfully connected to the manager. - */ - void connectedToManager(); - /** - * This signal is emited when we loose the connection to the manager. - * A reconnect is automatically attempted. - */ - void disconnectedFromManager(); - - - private: - quint32 identifier; - const QString applicationClass; - Resource* resourceSet[NumberOfTypes]; - }; -} - -#endif - diff --git a/libresourceqt/include/resource.h b/libresourceqt/include/resource.h deleted file mode 100644 index 13265d5..0000000 --- a/libresourceqt/include/resource.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef RESOURCE_H -#define RESOURCE_H - -#include - -namespace ResourcePolicy { - enum ResourceType { - AudioPlaybackType = 0, - VideoPlaybackType, - AudioRecorderType, - VideoRecorderType, - VibraType, - LedsType, - BacklightType, - SystemButtonType, - LockButtonType, - ScaleButtonType, - SnapButtonType, - LensCoverType, - NumberOfTypes - }; - - /** - * This class is the super class for all resources. It represents a generic - * \ref Resource. The type specific resource classes should be used. - */ - class Resource - { - public: - /** - * Whether or not this resource is optional, in that it doesn't need to - * be available for the set to be acquired. - * \return true when this resource is optional. - */ - bool isOptional() const; - /** - * Set the resource to be optional or mandatory. - * \param resourceIsOptional This optional parameter defaults to true. - * The default, true, results in the resource becoming optional. When it - * is set to false the resource becomes mandatory. - */ - void setOptional(bool resourceIsOptional=true); - /** - * Whether or not the resource to be shared. If it is shared then other - * programs are allowed to share this resource. - * \return true when this resource is shared. - */ - bool isShared() const; - /** - * Sets the resource to be shared/private. - * \param resourceIsShared This optional parameter defaults to true. - * When it is set to true (de default) the resource is shared with - * other programs. Setting it to false makes this resource exclusive. - */ - void setShared(bool resourceIsShared=true); - /** - * Whether or not this resource has been granted. - * \return true if this resource has been granted. - */ - bool isGranted() const; - void setGranted(); - void unsetGranted(); - - virtual ResourceType type() const = 0; - virtual Resource * clone() const = 0; - virtual ~Resource(); - protected: - Resource(); - Resource(const Resource &other); - - ResourceType resourceType; - bool optional; - bool shared; - quint32 identifier; - bool granted; - }; -} - -#endif - diff --git a/libresourceqt/include/resources.h b/libresourceqt/include/resources.h deleted file mode 100644 index 8e3da70..0000000 --- a/libresourceqt/include/resources.h +++ /dev/null @@ -1,169 +0,0 @@ -#ifndef RESOURCES_H -#define RESOURCES_H - -#include "resource.h" -#include -#include - -namespace ResourcePolicy { - - class AudioResource: public Resource - { - public: - AudioResource(const QString &audioGroup=QString()); - AudioResource(const AudioResource &other); - virtual ~AudioResource(); - - QString audioGroup() const; - void setAudioGroup(const QString & newGroup); - - quint32 processID() const; - void setProcessID(quint32 newPID); - - QString streamTag() const; - void setStreamTag(const QString & newStreamTag); - - virtual ResourceType type() const; - virtual Resource * clone() const; - private: - QString group; - quint32 pid; - QString stream; - }; - - class AudioRecorderResource: public Resource - { - public: - AudioRecorderResource(const QString & audioGroup=QString()); - AudioRecorderResource(const AudioRecorderResource &other); - virtual ~AudioRecorderResource(); - - QString audioGroup() const; - void setAudioGroup(const QString & newGroup); - - quint32 processID() const; - void setProcessID(quint32 newPID); - - QString streamTag() const; - void setStreamTag(const QString & newStreamTag); - - virtual ResourceType type() const; - virtual Resource * clone() const; - private: - QString group; - quint32 pid; - QString stream; - }; - - class BacklightResource: public Resource - { - public: - BacklightResource(); - BacklightResource(const BacklightResource &other); - virtual ~BacklightResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LedsResource: public Resource - { - public: - LedsResource(); - LedsResource(const LedsResource &other); - virtual ~LedsResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VibraResource: public Resource - { - public: - VibraResource(); - VibraResource(const VibraResource &other); - virtual ~VibraResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VideoRecorderResource: public Resource - { - public: - VideoRecorderResource(); - VideoRecorderResource(const VideoRecorderResource &other); - virtual ~VideoRecorderResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class VideoResource: public Resource - { - public: - VideoResource(); - VideoResource(const VideoResource &other); - virtual ~VideoResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class SystemButtonResource: public Resource - { - public: - SystemButtonResource(); - SystemButtonResource(const SystemButtonResource &other); - virtual ~SystemButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LockButtonResource: public Resource - { - public: - LockButtonResource(); - LockButtonResource(const LockButtonResource &other); - virtual ~LockButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class ScaleButtonResource: public Resource - { - public: - ScaleButtonResource(); - ScaleButtonResource(const ScaleButtonResource &other); - virtual ~ScaleButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class SnapButtonResource: public Resource - { - public: - SnapButtonResource(); - SnapButtonResource(const SnapButtonResource &other); - virtual ~SnapButtonResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; - - class LensCoverResource: public Resource - { - public: - LensCoverResource(); - LensCoverResource(const LensCoverResource &other); - virtual ~LensCoverResource(); - - virtual ResourceType type() const; - virtual Resource * clone() const; - }; -} -#endif - 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 -#include 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(data); + + engine->disconnected(); +} + +void ResourceEngine::disconnected() +{ + qDebug("disconnected"); + + connected = false; +} + +static void handleGrantMessage(resmsg_t *msg, resset_t *, void *data) +{ + ResourceEngine *engine = reinterpret_cast(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(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 resourceList = resourceSet->resources(); + QList 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 resourceList = resourceSet->resources(); + QList 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 resourceList = resourceSet->resources(); + QList 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 #include #include -#include "resource-set.h" +#include 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 availableResources); - void resourcesAcquired(QList grantedResources); + void resourcesBecameAvailable(QList availableResources); + void resourcesAcquired(QList 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 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)*NumberOfTypes); @@ -60,7 +60,7 @@ quint32 ResourceSet::id() const return identifier; } -QList ResourceSet::resources() +QList ResourceSet::resources() const { QList 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 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 using namespace ResourcePolicy; -- cgit v1.2.3