summaryrefslogtreecommitdiff
path: root/libresourceqt/include/qt4/policy
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/include/qt4/policy
parent6751c585385f017d08540bbe121606d642afb220 (diff)
Restructured libresourceqt includes, updated debianpackages to soversion=1.
Fixed ResourceEngine to work with the new Resource object.
Diffstat (limited to 'libresourceqt/include/qt4/policy')
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h207
-rw-r--r--libresourceqt/include/qt4/policy/resource.h80
-rw-r--r--libresourceqt/include/qt4/policy/resources.h169
3 files changed, 456 insertions, 0 deletions
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 <policy/resources.h>
+#include <QString>
+#include <QObject>
+#include <QVector>
+#include <QList>
+
+/**
+ * \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<ResourcePolicy::Resource>)));
+ * 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 QList<Resource *>resources);
+ /**
+ * 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<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.
+ * \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<ResourceType> &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<ResourceType> availableResources);
+ /**
+ * This signal is emited as a response to the acquire() request.
+ * \param grantedOptionalResources The list of granted optional resources.
+ */
+ 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.
+ */
+ 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 <QtCore>
+
+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 <policy/resource.h>
+#include <QObject>
+#include <QString>
+
+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
+