summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-10 11:55:19 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-10 13:52:50 +0200
commit80042b6e527238d11dd2c955e47b652941c2ba6e (patch)
tree5f9bcc28129af5235742af32d26817a06ddf1800
parent8fe83d5fd968d7e475600691bd9a72f5f888a8c9 (diff)
downloadlibresourceqt-80042b6e527238d11dd2c955e47b652941c2ba6e.tar.gz
Updated API to hide the whole resource manager and stuff
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h83
-rw-r--r--libresourceqt/include/qt4/policy/resource.h19
-rw-r--r--libresourceqt/src/resource-engine.cpp14
-rw-r--r--libresourceqt/src/resource-engine.h3
-rw-r--r--libresourceqt/src/resource-set.cpp41
-rw-r--r--libresourceqt/src/resource.cpp10
6 files changed, 92 insertions, 78 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index d998807..0e18e5b 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -74,10 +74,11 @@ namespace ResourcePolicy
*/
~ResourceSet();
/**
- * Initializes the underlaying communications library.
- * \return true if initialization is successful.
+ * Finalizes the ResourceSet. This method should be called after all
+ * resources have been added to the set.
+ * \return true if the finalization was successful.
*/
- bool initialize();
+ bool finalize();
/**
* This method adds a resource to the set. A set contains only a single
@@ -127,57 +128,74 @@ namespace ResourcePolicy
*/
bool contains(const QList<ResourceType> &types) const;
+ /**
+ * Returns the unique identifier for this ResourceSet.
+ * @return the unique identifier for this ResourceSet.
+ */
quint32 id() const;
+
+ /**
+ * Returns the registered application class (given in the constructor).
+ */
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.
+ * Try to acquire the \ref ResourceSet. The resourcesGranted() or
+ * resourcesDenied() signal will be emited depending on whether the
+ * requested resources could be acquired or not.
*/
- bool connectToManager(bool reconnectOnDisconnect);
+ bool acquire();
/**
- * Disconnects from the Resource Policy Manager. Further attempts at acquiring
- * the \ref ResourceSet will fail.
+ * Release the acquired resources.
*/
- void disconnectFromManager();
+ bool release();
/**
- * Checks whether the ResourceSet is connected or not.
+ * Commit changes to the \ref ResourceSet. Remember to call update()
+ * after adding and/or removing resources.
*/
- bool isConnectedToManager();
+ bool update();
+
/**
- * Attempt to acquire the ResourceSet. The response is returned as the
- * resourcesAcquired() signal.
+ * Stes the auto-release. When loosing the resources doue to another
+ * application with a higher priority the default is that we automatically
+ * re-gain our resources without having to re-request them. However if
+ * the AutoRelease is set we release the resources and need to re-acquire
+ * them, when the pre-emting application releases it s resources.
+ * This feature is by default disabled.
+ * Remember to call update() when changing this.
*/
- bool acquire();
+ void setAutoRelease();
/**
- * Release the acquired resources.
+ * see \ref setAutoRelease().
*/
- bool release();
+ void unsetAutoRelease();
/**
- * Commit changes to the \ref ResourceSet to the Manager.
+ * Sets that the resourcesGranted() signal is emited even if we already
+ * have the requested resources granted. By default this feature is off.
*/
- bool update();
+ void setAlwaysReply();
+ /**
+ * Unsets the always reply flag (see \ref setAlwaysReply())
+ */
+ void unsetAlwaysReply();
- signals:
+ 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.
+ * \param availableResources A list of available resources. The list of
+ * available resources contains only available resource which we have in the set.
*/
void resourcesBecameAvailable(QList<ResourceType> availableResources);
/**
* This signal is emited as a response to the acquire() request.
* \param grantedOptionalResources The list of granted optional resources.
+ * All the mandatory resources have also been aquired.
*/
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.
+ * case where one or more of the mandatroy resources were not availalble.
*/
void resourcesDenied();
/**
@@ -185,21 +203,14 @@ namespace ResourcePolicy
* 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];
+ bool connected;
+ bool autoRelease;
+ bool alwaysReply;
};
}
diff --git a/libresourceqt/include/qt4/policy/resource.h b/libresourceqt/include/qt4/policy/resource.h
index 13265d5..4b68ab1 100644
--- a/libresourceqt/include/qt4/policy/resource.h
+++ b/libresourceqt/include/qt4/policy/resource.h
@@ -45,21 +45,7 @@ namespace ResourcePolicy {
* 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;
@@ -70,9 +56,12 @@ namespace ResourcePolicy {
ResourceType resourceType;
bool optional;
- bool shared;
quint32 identifier;
+ private:
+ void setGranted();
+ void unsetGranted();
bool granted;
+
};
}
diff --git a/libresourceqt/src/resource-engine.cpp b/libresourceqt/src/resource-engine.cpp
index 9f42a48..1478e33 100644
--- a/libresourceqt/src/resource-engine.cpp
+++ b/libresourceqt/src/resource-engine.cpp
@@ -17,7 +17,7 @@ static void handleAdviceMessage(resmsg_t *msg, resset_t *rs, void *data);
ResourceEngine::ResourceEngine(ResourceSet *resourceSet)
: QObject(resourceSet), connected(false), resourceSet(resourceSet),
libresourceConnection(NULL), libresourceSet(NULL), requestId(0),
- messageMap()
+ messageMap(), mode(0)
{
}
@@ -105,17 +105,16 @@ bool ResourceEngine::connect()
uint32_t allResources, optionalResources, sharedResources;
allResources = allResourcesToBitmask(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.rset.share = 0;
+ resourceMessage.record.rset.mask = 0;
QByteArray ba = resourceSet->applicationClass().toLatin1();
resourceMessage.record.klass = ba.data();
- resourceMessage.record.mode = 0; //No auto release
+ resourceMessage.record.mode = mode;
libresourceSet = resconn_connect(libresourceConnection, &resourceMessage,
statusCallbackHandler);
@@ -299,3 +298,8 @@ void ResourceEngine::handleConnectionIsUp()
emit connectedToManager();
}
+void ResourceEngine::setMode(quint32 newMode)
+{
+ mode = newMode;
+}
+
diff --git a/libresourceqt/src/resource-engine.h b/libresourceqt/src/resource-engine.h
index 6d81d8e..9d26127 100644
--- a/libresourceqt/src/resource-engine.h
+++ b/libresourceqt/src/resource-engine.h
@@ -41,6 +41,8 @@ public:
void handleStatusMessage(quint32 requestNo);
+ void setMode(quint32 newMode);
+
signals:
void resourcesBecameAvailable(QList<Resource *> availableResources);
void resourcesAcquired(QList<Resource *> grantedResources);
@@ -57,6 +59,7 @@ private:
resset_t *libresourceSet;
quint32 requestId;
QMap<quint32, resmsg_type_t> messageMap;
+ quint32 mode;
};
}
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index 64bdf8e..f8f3826 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -3,7 +3,9 @@ using namespace ResourcePolicy;
ResourceSet::ResourceSet(const QString &applicationClass, QObject * parent)
- : QObject(parent), resourceClass(applicationClass)
+ : QObject(parent), resourceClass(applicationClass), autoRelease(false),
+ alwaysReply(false)
+
{
identifier = (quint32)this;
memset(resourceSet, 0, sizeof(QPointer<Resource *>)*NumberOfTypes);
@@ -16,8 +18,16 @@ ResourceSet::~ResourceSet()
}
}
+bool ResourceSet::finalize()
+{
+ return false;
+}
+
void ResourceSet::addResource(const Resource *resource)
{
+ if((resource->type() == AudioPlaybackType) || (resource->type() == AudioRecorderType)) {
+ qDebug("audioResource...");
+ }
resourceSet[resource->type()] = resource->clone();
}
@@ -80,36 +90,43 @@ Resource * ResourceSet::resource(ResourceType type) const
return NULL;
}
-bool ResourceSet::connectToManager(bool reconnectOnDisconnect)
+bool ResourceSet::acquire()
{
return false;
}
-void ResourceSet::disconnectFromManager()
+bool ResourceSet::release()
{
+ return false;
}
-bool ResourceSet::isConnectedToManager()
+bool ResourceSet::update()
{
return false;
}
-bool ResourceSet::acquire()
+QString ResourceSet::applicationClass()
{
- return false;
+ return this->resourceClass;
}
-bool ResourceSet::release()
+void ResourceSet::setAutoRelease()
{
- return false;
+ autoRelease = true;
}
-bool ResourceSet::update()
+void ResourceSet::unsetAutoRelease()
{
- return false;
+ autoRelease = false;
}
-QString ResourceSet::applicationClass()
+void ResourceSet::setAlwaysReply()
{
- return this->resourceClass;
+ alwaysReply = true;
+}
+
+void ResourceSet::unsetAlwaysReply()
+{
+ alwaysReply = false;
}
+
diff --git a/libresourceqt/src/resource.cpp b/libresourceqt/src/resource.cpp
index fe1153e..796a345 100644
--- a/libresourceqt/src/resource.cpp
+++ b/libresourceqt/src/resource.cpp
@@ -29,16 +29,6 @@ void Resource::setOptional(bool resourceIsOptional)
optional = resourceIsOptional;
}
-bool Resource::isShared() const
-{
- return shared;
-}
-
-void Resource::setShared(bool shared)
-{
- this->shared = shared;
-}
-
bool Resource::isGranted() const
{
return granted;