summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:27:21 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-12-01 16:27:21 +0200
commit78db2c0b916d68a0c4056d4be7228a606b2f9dac (patch)
treefb5c624c88b413d82c790c7f488d3e3efd862742
parentc8917f1cbbf96a1c5c655d9adbd45a46833e70db (diff)
parentef6d735381083c0e90b122f6a22771c13337b8c1 (diff)
downloadlibresourceqt-78db2c0b916d68a0c4056d4be7228a606b2f9dac.tar.gz
Merge remote branch 'origin/master'
-rw-r--r--libresourceqt/include/qt4/policy/resource-set.h12
-rw-r--r--libresourceqt/src/resource-set.cpp26
-rw-r--r--resourceqt-client/client.cpp152
-rw-r--r--resourceqt-client/client.h2
4 files changed, 130 insertions, 62 deletions
diff --git a/libresourceqt/include/qt4/policy/resource-set.h b/libresourceqt/include/qt4/policy/resource-set.h
index 25a8309..a36254d 100644
--- a/libresourceqt/include/qt4/policy/resource-set.h
+++ b/libresourceqt/include/qt4/policy/resource-set.h
@@ -213,6 +213,13 @@ public:
QString applicationClass();
/**
+ * Initialize and connect the ResourceEngine of this ResourceSet.
+ * Use this method after adding resources to the ResourceSet initially.
+ * \return true if the method succeeds without encountering errors.
+ */
+ bool initAndConnect();
+
+ /**
* 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.
@@ -303,6 +310,11 @@ signals:
*/
void errorCallback(quint32, const char*);
+ /**
+ * This signals that we have connected to the Resource Manager.
+ */
+ void connectedToManager();
+
private:
bool initialize();
diff --git a/libresourceqt/src/resource-set.cpp b/libresourceqt/src/resource-set.cpp
index e96c7a0..190df5e 100644
--- a/libresourceqt/src/resource-set.cpp
+++ b/libresourceqt/src/resource-set.cpp
@@ -230,21 +230,32 @@ Resource * ResourceSet::resource(ResourceType type) const
return resourceSet[type];
}
-bool ResourceSet::acquire()
+bool ResourceSet::initAndConnect()
{
- if (!initialized) {
+ if ( !initialized ) {
qDebug("ResourceSet::%s().... initializing...", __FUNCTION__);
- pendingAcquire = true;
return initialize();
}
- if (!resourceEngine->isConnectedToManager()) {
+ if ( !resourceEngine->isConnectedToManager() ) {
qDebug("ResourceSet::%s().... connecting...", __FUNCTION__);
+ return resourceEngine->connectToManager();
+ }
+ else
+ qDebug("ResourceSet::%s(): already connected", __FUNCTION__);
+
+ return true;
+}
+
+bool ResourceSet::acquire()
+{
+ if ( !initialized || !resourceEngine->isConnectedToManager() )
+ {
pendingAcquire = true;
- resourceEngine->connectToManager();
- return true;
+ return initAndConnect();
}
- else {
+ else
+ {
qDebug("ResourceSet::%s().... acquiring", __FUNCTION__);
return resourceEngine->acquireResources();
}
@@ -311,6 +322,7 @@ void ResourceSet::connectedHandler()
qDebug("**************** ResourceSet::%s().... %d", __FUNCTION__, __LINE__);
if (resourceEngine->isConnectedToManager()) {
qDebug("ResourceSet::%s() Connected to manager!", __FUNCTION__);
+ emit connectedToManager();
if (pendingAudioProperties) {
registerAudioProperties();
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 4cd372a..fcfe36c 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -60,9 +60,8 @@ Client::Client()
commandList["free"] = CommandListArgs("", "destroy and free the resources");
commandList["acquire"] = CommandListArgs("", "acquire required resources");
commandList["release"] = CommandListArgs("", "release resources");
- commandList["update"] = CommandListArgs("", "update modified resource set after add or remove command");
- commandList["add"] = CommandListArgs("reslist [-o]", "add resource list, if -o provided, set as optional");
- commandList["remove"] = CommandListArgs("reslist [-o]", "remove resource list, if -o provided, removed only optional flag");
+ commandList["update"] = CommandListArgs("update <all>[:opt] where 'all' and 'opt' are comma separated resources",
+ "update the resource set by specifying the new set");
commandList["audio"] = CommandListArgs("pid <pid> | group <audio group> | tag <name> <value>", "set audio properties");
commandList["addaudio"] = CommandListArgs("<audio group> <pid> <tag name> <tag value>", "Add an audio resource and set the properties");
commandList["show"] = CommandListArgs("", "show resources");
@@ -137,13 +136,18 @@ bool Client::initialize(const CommandLineParser &parser)
if (!connect(&stdInNotifier, SIGNAL(activated(int)), this, SLOT(readLine(int)))) {
return false;
}
+ if (!connect(resourceSet , SIGNAL(connectedToManager()), this, SLOT(stopConnectTimerHandler()))) {
+ return false;
+ }
if (!connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()),
this, SLOT(doExit()))) {
return false;
}
+
+ startTimer();
+ resourceSet->initAndConnect();
OUTPUT << "accepting input" << endl;
showPrompt();
-
return true;
}
@@ -153,6 +157,73 @@ void Client::doExit()
resourceSet->release();
}
+
+void Client::modifyResources(const QString &resString)
+{
+ //resString example: [mand_resources:opt_resources] res1,res2,res3:res1,res3
+ if ( resString.isEmpty() || resString.isNull()){
+ qDebug("Client::modifyResources(): no resources in string.");
+ return;
+ }
+ QStringList newAllAndOpt = resString.split(":");
+
+ if (newAllAndOpt.size()==1)
+ qDebug("There are only mandatory resources.");
+
+ //Every optional res. is also in allSet
+ QSet<ResourcePolicy::ResourceType> newAllSet;
+ QSet<ResourcePolicy::ResourceType> newOptSet;
+
+ if ( !CommandLineParser::parseResourceList(newAllAndOpt.at(0), newAllSet) ) {
+ qDebug("Client::modifyResources(): could not parse all resources.");
+ return;
+ }
+
+ if (newAllAndOpt.size()>1) {
+ if ( !CommandLineParser::parseResourceList(newAllAndOpt.at(1), newOptSet) ){
+ qDebug("Client::modifyResources(): could not parse optional resources.");
+ return;
+ }
+ bool optNotInAll = false;
+ //If the user forgot to add resource to all when specifying optional -> add to all.
+ foreach(ResourceType newOptRes, newOptSet){
+ if ( !newAllSet.contains(newOptRes) ){
+ optNotInAll = true;
+ newAllSet.insert(newOptRes);
+ }
+ }
+ if (optNotInAll)
+ qDebug("Client::modifyResources(): optional resources should be added to all as well.");
+ }
+
+ //Check if new resources are in current resource set.
+ foreach ( ResourceType newRes, newAllSet) {
+ if ( resourceSet->contains(newRes) ){
+ if ( resourceSet->resource(newRes)->isOptional() && !newOptSet.contains(newRes) ) {
+ //New mandatory is in set, but is not optional in the new set.
+ resourceSet->resource(newRes)->setOptional(false);
+ }
+ else if ( !resourceSet->resource(newRes)->isOptional() && newOptSet.contains(newRes) ){
+ //New mandatory is in set, but is optional.
+ resourceSet->resource(newRes)->setOptional(true);
+ }
+ }
+ else { //Add new resource.
+ resourceSet->addResource(newRes);
+
+ if ( newOptSet.contains(newRes) )
+ resourceSet->resource(newRes)->setOptional(true);
+ }
+ }
+ QList<Resource*> resList = resourceSet->resources();
+ //Check if there are current resources not in the new set (i.e. removed).
+ foreach(Resource* resource, resList)
+ if ( !newAllSet.contains(resource->type()) )
+ resourceSet->deleteResource(resource->type());
+
+}
+
+
const char * resourceTypeToString(ResourceType type)
{
switch (type) {
@@ -208,6 +279,11 @@ void Client::showResources(const QList<Resource*> &resList)
}
}
+void Client::stopConnectTimerHandler()
+{
+ stopTimer();
+}
+
void Client::resourceAcquiredHandler(const QList<ResourceType>&)
{
stopTimer();
@@ -333,60 +409,26 @@ void Client::readLine(int)
qCritical("%s failed!", qPrintable(command));
}
}
- else if (command == "add") {
- QString resourceList, flag;
- input >> resourceList >> flag;
- if (!resourceSet) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
- }
- else if (resourceList.isEmpty() || resourceList.isNull()) {
- OUTPUT << "List of desired resources is missing. Use help.";
- }
- else {
- bool optional = false;
- QSet<ResourcePolicy::ResourceType> resToAdd;
- CommandLineParser::parseResourceList(resourceList, resToAdd);
- if (flag == "-o") {
- optional = true;
- }
- foreach(ResourcePolicy::ResourceType resource, resToAdd) {
- if (!resourceSet->contains(resource)) {
- resourceSet->addResource(resource);
- }
- if (optional) {
- resourceSet->resource(resource)->setOptional();
- }
- }
- }
- }
- else if (command == "remove") {
- QString resourceList, flag;
- input >> resourceList >> flag;
- if (!resourceSet) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
- }
- else if (resourceList.isEmpty() || resourceList.isNull()) {
- OUTPUT << "List of desired resources is missing. Use help.";
+ else if (command == "update") {
+
+ QString resourceList;
+ input >> resourceList;
+
+ if (!resourceSet)
+ qCritical("%s failed!", qPrintable(command));
+
+ if (resourceList.isEmpty() || resourceList.isNull()) {
+ qCritical("%s failed! List of desired resources is missing. Use help.",
+ qPrintable(command));
}
else {
- QSet<ResourcePolicy::ResourceType> resToRemove;
- CommandLineParser::parseResourceList(resourceList, resToRemove);
- if (flag == "-o") {
- foreach(ResourcePolicy::ResourceType resource, resToRemove) {
- resourceSet->resource(resource)->setOptional(false);
- }
- }
- else {
- foreach(ResourcePolicy::ResourceType resource, resToRemove) {
- resourceSet->deleteResource(resource);
- }
- }
- }
- }
- else if (command == "update") {
- if (!resourceSet || !resourceSet->update()) {
- qCritical("%s%s failed!", qPrintable(prefix), qPrintable(command));
+ startTimer();
+ modifyResources(resourceList);
+
+ if (!resourceSet->update())
+ qCritical("%s failed!", qPrintable(command));
}
+
}
else if (command == "audio") {
QString what, group, tagName, tagValue;
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index e73c50c..6d92a30 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -63,6 +63,7 @@ private slots:
void resourcesBecameAvailableHandler(const QList<ResourcePolicy::ResourceType> &availableResources);
void readLine(int);
void doExit();
+ void stopConnectTimerHandler();
private:
QTextStream standardInput;
@@ -82,6 +83,7 @@ private:
void showPrompt();
void showResources(const QList<ResourcePolicy::ResourceType> &resList);
void showResources(const QList<ResourcePolicy::Resource*> &resList);
+ void modifyResources(const QString &resString);
inline void startTimer();
inline void stopTimer();
};