summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-25 11:12:45 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-01-25 11:12:45 +0200
commitca994fc17c8bdb66c64beaead40bc2727ea89468 (patch)
treef03b032af15c214610d84fe7f1dc99c726eff610 /include
parent9f3e54044fd1e0c26153195f91889342a8425b7f (diff)
Chaged Resource::type to be stored as a number instead of a string. Also
changed ResourceSet to store resources as a QVector instead of a QSet.
Diffstat (limited to 'include')
-rw-r--r--include/resource-set.h62
-rw-r--r--include/resource.h87
2 files changed, 128 insertions, 21 deletions
diff --git a/include/resource-set.h b/include/resource-set.h
index b62e5cd..193dabc 100644
--- a/include/resource-set.h
+++ b/include/resource-set.h
@@ -4,37 +4,83 @@
#include "resource.h"
#include <QString>
#include <QObject>
-#include <QSet>
+#include <QVector>
+#include <QList>
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.
+ *
+ * \b Examples:
+ * This example shows how to create a resourceSet used by a video player
+ * \code
+ * Resource audioResource(AudioPlaybackResource);
+ * Resource videoResource(VideoPlaybackResource);
+ * ResourceSet myResourceSet("player");
+ * myResourceSet.addResource(audioResource);
+ * myResourceSet.addResource(videoResource);
+ * \endcode
+ */
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.
+ */
ResourceSet(const QString &applicationClass);
+ /**
+ * The destructor
+ */
~ResourceSet();
+ /**
+ * 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.
+ */
void addResource(const Resource &resource);
- void addResources(const QSet<Resource> &resources);
- void setResources(const QSet<Resource> &resources);
- QSet<Resource> resources();
+ /**
+ * This method adds (and replaces) the list of resource to the set.
+ * \param resources The list of resources to add to the set.
+ */
+ void addResources(const QList<Resource> &resources);
+ /**
+ * This method clears the old resources and replaces the set with the
+ * resources from the given list.
+ * \param resources The list of resources that the set should contain.
+ */
+ void setResources(const QList<Resource> &resources);
+
+ /**
+ * This method returns a list of all resource in the set.
+ * \return a QList of all resources in the set.
+ */
+ QList<Resource> resources();
bool contains(const Resource &resource) const;
- bool contains(const QSet<Resource> &resources) const;
+ bool contains(const QList<Resource> &resources) const;
quint32 id() const;
signals:
- void resourcesBecameAvailable(QSet<Resource> resources);
- void resourcesAcquired(QSet<Resource> grantedResources);
+ void resourcesBecameAvailable(QList<Resource> availableResources);
+ void resourcesAcquired(QList<Resource> grantedResources);
void resourcesDenied();
void lostResources();
private:
quint32 identifier;
const QString applicationClass;
- QSet<Resource> resourceSet;
+ QVector<Resource> resourceSet;
};
}
diff --git a/include/resource.h b/include/resource.h
index 3d71de6..ef3290c 100644
--- a/include/resource.h
+++ b/include/resource.h
@@ -10,10 +10,11 @@ namespace ResourcePolicy {
*/
enum ResourceType {
InvalidResource = 0,
- AudioPlaybackResource = 0x01,
- VideoPlaybackResource = 0x02,
- AudioRecorderResource = 0x04,
- VideoRecorderResource = 0x08
+ AudioPlaybackResource,
+ VideoPlaybackResource,
+ AudioRecorderResource,
+ VideoRecorderResource,
+ ResourceGuard
};
/**
@@ -21,26 +22,87 @@ namespace ResourcePolicy {
* Resources is to use then in a ResourceSet.
*
* Other Resource types can be added later, these reflect the resources found
- * in the Policy configuration.
+ * in the Policy configuration.
+ *
+ * \b Examples:
+ * This example shows how to make a resource which represents an optional
+ * audio requirement.
+ * \code
+ * Resource audioResource(AudioPlaybackResource);
+ * audioResource->setOptional();
+ * \endcode
+ * This example shows how to create the resources used by a video player
+ * \code
+ * Resource audioResource(AudioPlaybackResource);
+ * Resource videoResource(VideoPlaybackResource);
+ * \endcode
*/
class Resource
{
public:
+ /**
+ * Constructor. Creates a new identifier. The new identifier defaults to
+ * not optional, and not shared. The default type is undefined and
+ * \ref setType() needs to be called to set the type. Optionally a
+ * resource type may be given to the constructor, to avoid having to
+ * call the setType() method.
+ */
+ Resource(enum ResourceType type=InvalidResource);
+ /**
+ * Copy constructor. Copies also the identifier.
+ * \param other The source to copy from.
+ */
Resource(const Resource &other);
- Resource();
+ /**
+ * Assignement operator. Works like the copy constructor.
+ * \param other The source to assign from.
+ */
Resource &operator=(const Resource &other);
-
+ //! Destructor.
~Resource();
+ /**
+ * Returns the type of the resource.
+ * \return the type of the resource.
+ */
ResourceType type() const;
+ /**
+ * Sets the resource type.
+ * \param type The type to set to.
+ * \return true if the type is valid.
+ */
bool setType(enum ResourceType type);
+ /**
+ * 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;
- void setShared(bool shared=true);
- quint32 id() const;
- void setId(quint32 newId);
-
+ /**
+ * 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);
+ /**
+ * Compares two resources and returns true if both are of the same \b type.
+ * \param other The resrouce to compare to.
+ * \return true if the types of both resources are of the same type.
+ */
bool operator==(const Resource &other) const;
private:
ResourceType resourceType;
@@ -48,8 +110,7 @@ namespace ResourcePolicy {
bool shared;
quint32 identifier;
};
-
- uint qHash(const ResourcePolicy::Resource &key);
+
}
#endif