summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--resourceqt-client/client.cpp29
-rw-r--r--resourceqt-client/client.h4
-rw-r--r--resourceqt-client/resourceqt-client.cpp42
3 files changed, 61 insertions, 14 deletions
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 28d4169..539f5b0 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -159,7 +159,7 @@ void Client::updateSet(uint32_t list, uint32_t optional, bool remove)
}
}
-bool Client::initialize(uint32_t all, uint32_t optional)
+bool Client::initialize(uint32_t all, uint32_t optional, bool alwaysReply, bool autoRelease)
{
resourceSet = new ResourceSet(applicationClass);
if( resourceSet == NULL )
@@ -167,6 +167,16 @@ bool Client::initialize(uint32_t all, uint32_t optional)
return false;
}
+ if( alwaysReply )
+ {
+ resourceSet->setAlwaysReply();
+ }
+
+ if( autoRelease )
+ {
+ resourceSet->setAutoRelease();
+ }
+
updateSet(all, optional, false);
if( !connect(resourceSet, SIGNAL(resourcesGranted(QList<ResourceType>)), this, SLOT(resourceAcquiredHandler(QList<ResourceType>))) )
@@ -309,14 +319,23 @@ void Client::showResources(const QList<Resource*> resList)
Resource* r = resList[i];
printf("\t%s%s%s\n", resTypes[r->type()],
r->isOptional() ? " (optional)" : "",
- r->isGranted() ? "(granted)" : "");
+ r->isGranted() ? " (granted)" : "");
}
}
-void Client::resourceAcquiredHandler(const QList<ResourceType>& resList)
+void Client::resourceAcquiredHandler(const QList<ResourceType>& grantedResList)
{
- printf("\nManager grants access to these resources:\n");
- showResources(resList);
+ QList<Resource*> list = resourceSet->resources();
+ if( !list.count() )
+ {
+ printf("\nGranted resource set is empty. Possible bug?\n");
+ }
+ else
+ {
+ printf("\nManager grants access to these resources:\n");
+ printf("Resource set:\n");
+ showResources(list);
+ }
showPrompt();
}
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index 3399d02..39615ef 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -29,11 +29,11 @@ public:
Client(QString appClass);
~Client();
- bool initialize(uint32_t all, uint32_t optional);
+ bool initialize(uint32_t all, uint32_t optional, bool alwaysReply, bool autoRelease);
static uint32_t parseResourceList(QString resourceListStr);
private slots:
- void resourceAcquiredHandler(const QList<ResourceType>& resList);
+ void resourceAcquiredHandler(const QList<ResourceType>& grantedResList);
void resourceDeniedHandler();
void resourceLostHandler();
diff --git a/resourceqt-client/resourceqt-client.cpp b/resourceqt-client/resourceqt-client.cpp
index f17ebaf..89aef76 100644
--- a/resourceqt-client/resourceqt-client.cpp
+++ b/resourceqt-client/resourceqt-client.cpp
@@ -18,6 +18,8 @@ public:
resourcesAll = 0;
resourcesOptional = 0;
+ autoRelease = false;
+ alwaysReply = false;
parseArguments(argc, argv);
}
@@ -38,6 +40,8 @@ public:
uint32_t resourcesAll;
uint32_t resourcesOptional;
QString applicationClass;
+ bool autoRelease;
+ bool alwaysReply;
void printMessage(const char *fmt, ...)
{
@@ -71,16 +75,15 @@ private:
{
int option;
- while( (option = getopt(argc, argv, "hf:s:")) != -1 )
+ while( (option = getopt(argc, argv, "hm:o:")) != -1 )
{
switch (option)
{
case 'h':
usage(0);
return;
- case 'f':
- printf("-f - not implemented!\n");
- //config.mode = parseModeValues(optarg, 1);
+ case 'm':
+ parseModeValues(optarg);
break;
case 'o':
resourcesOptional = Client::parseResourceList(optarg);
@@ -135,15 +138,40 @@ private:
return str;
}
+ void parseModeValues(QString modeListStr)
+ {
+ if( !modeListStr.isEmpty() && !modeListStr.isNull() )
+ {
+ QStringList modeList = modeListStr.split(",", QString::SkipEmptyParts);
+
+ for( int i = 0; i < modeList.count(); i++ )
+ {
+ if( modeList[i] == "AutoRelease" )
+ {
+ autoRelease = true;
+ }
+ else if( modeList[i] == "AlwaysReply" )
+ {
+ alwaysReply = true;
+ }
+ else
+ {
+ const char* mode = qPrintable(modeList[i]);
+ printMessage("Ignoring unknown mode '%s'!", mode);
+ }
+ }
+ }
+ }
+
void usage(int theExitCode)
{
- printf("usage: %s [-h] [-t] [-v] [-f mode-values]"
+ printf("usage: %s [-h] [-t] [-v] [-m mode-values]"
"[-o optional-resources] [-s shared-resources -m shared-mask] "
"class all-resources\n",
exeName);
printf("\toptions:\n");
printf("\t h\tprint this help message and exit\n");
- printf("\t f\tmode values. See 'modes' below for the "
+ printf("\t m\tmode values. See 'modes' below for the "
"\n\t\tsyntax of <mode-values>\n");
printf("\t o\toptional resources. See 'resources' below for the "
"syntax of\n\t\t<optional-resources>\n");
@@ -193,7 +221,7 @@ int main(int argc, char *argv[])
QCoreApplication app(argc, argv);
Client client(parser.applicationClass);
- if( !client.initialize(parser.resourcesAll, parser.resourcesOptional) )
+ if( !client.initialize(parser.resourcesAll, parser.resourcesOptional, parser.alwaysReply, parser.autoRelease) )
{
parser.printMessage("initialization failed!");
return EINVAL;