summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-11-18 08:11:11 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-11-18 08:13:05 +0200
commit2db176e028c54684e2fe6adf58ab0c5807d298c9 (patch)
tree75e31b55881af44abdfdfcbc0187238e9b1c3565
parent7cf4a74e8a1a548d74f58e7f7f16796fa11a6b61 (diff)
downloadlibresourceqt-2db176e028c54684e2fe6adf58ab0c5807d298c9.tar.gz
Took -i and -v flags into use
-rw-r--r--resourceqt-client/client.cpp54
-rw-r--r--resourceqt-client/client.h3
-rw-r--r--resourceqt-client/resourceqt-client.cpp1
3 files changed, 32 insertions, 26 deletions
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index d190498..7fdb2f6 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -53,7 +53,7 @@ CommandListArgs::~CommandListArgs()
Client::Client()
: QObject(), standardInput(stdin, QIODevice::ReadOnly), stdInNotifier(0, QSocketNotifier::Read), pendingAddAudio(false), applicationClass(),
- resourceSet(NULL), output(stdout), prefix("")
+ resourceSet(NULL), output(stdout), prefix(""), showTimings(false)
{
commandList["help"] = CommandListArgs("", "print this help message");
commandList["quit"] = CommandListArgs("", "exit application");
@@ -93,6 +93,7 @@ bool Client::initialize(const CommandLineParser &parser)
if (parser.shouldAutoRelease()) {
OUTPUT << "client: AutoRelease" << endl;
}
+ showTimings = parser.showTimings();
resourceSet = new ResourceSet(parser.resourceApplicationClass(), this,
parser.shouldAlwaysReply(),
@@ -205,10 +206,7 @@ void Client::showResources(const QList<Resource*> &resList)
void Client::resourceAcquiredHandler(const QList<ResourceType>&)
{
- long int ms = stop_timer();
- if (ms > 0) {
- outputln << "Operation took " << ms << "ms" << endl;
- }
+ stopTimer();
QList<Resource*> list = resourceSet->resources();
if (!list.count()) {
@@ -228,10 +226,7 @@ void Client::resourceAcquiredHandler(const QList<ResourceType>&)
void Client::resourceDeniedHandler()
{
- long int ms = stop_timer();
- if (ms > 0) {
- outputln << "Operation took " << ms << "ms" << endl;
- }
+ stopTimer();
QList<Resource*> allResources = resourceSet->resources();
OUTPUT << "denied:" << allResources << endl;
showPrompt();
@@ -239,10 +234,7 @@ void Client::resourceDeniedHandler()
void Client::resourceLostHandler()
{
- long int ms = stop_timer();
- if (ms > 0) {
- outputln << "Operation took " << ms << "ms" << endl;
- }
+ stopTimer();
QList<Resource*> allResources = resourceSet->resources();
outputln << "lost:" << allResources << endl;
@@ -251,10 +243,7 @@ void Client::resourceLostHandler()
void Client::resourceReleasedHandler()
{
- long int ms = stop_timer();
- if (ms > 0) {
- outputln << "Operation took " << ms << "ms" << endl;
- }
+ stopTimer();
QList<Resource*> allResources = resourceSet->resources();
outputln << "released:"<< allResources << endl;
@@ -265,10 +254,7 @@ void Client::resourcesBecameAvailableHandler(const QList<ResourcePolicy::Resourc
{
if (pendingAddAudio) {
pendingAddAudio = false;
- long int ms = stop_timer();
- if (ms > 0) {
- outputln << "Operation took " << ms << "ms" << endl;
- }
+ stopTimer();
}
outputln << "advice:" << availableResources << endl;
showPrompt();
@@ -321,16 +307,16 @@ void Client::readLine(int)
}
}
else if (command == "acquire") {
- start_timer();
+ startTimer();
if (!resourceSet || !resourceSet->acquire()) {
- stop_timer();
+ stopTimer();
qCritical("%s failed!", qPrintable(command));
}
}
else if (command == "release") {
- start_timer();
+ startTimer();
if (!resourceSet || !resourceSet->release()) {
- stop_timer();
+ stopTimer();
qCritical("%s failed!", qPrintable(command));
}
}
@@ -453,7 +439,7 @@ void Client::readLine(int)
audioResource->setProcessID(pid);
audioResource->setStreamTag(tagName, tagValue);
pendingAddAudio = true;
- start_timer();
+ startTimer();
resourceSet->addResourceObject(audioResource);
}
}
@@ -491,3 +477,19 @@ QTextStream & operator<< (QTextStream &output,
return output;
}
+void Client::startTimer()
+{
+ if (showTimings) {
+ start_timer();
+ }
+}
+
+void Client::stopTimer()
+{
+ if (showTimings) {
+ long int ms = stop_timer();
+ if (ms > 0) {
+ outputln << "Operation took " << ms << " ms" << endl;
+ }
+ }
+}
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index 140c668..3967fee 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -71,6 +71,7 @@ private:
ResourcePolicy::ResourceSet *resourceSet;
QTextStream output;
QString prefix;
+ bool showTimings;
static QMap<QString, CommandListArgs> commandList;
@@ -80,6 +81,8 @@ private:
void showPrompt();
void showResources(const QList<ResourcePolicy::ResourceType> &resList);
void showResources(const QList<ResourcePolicy::Resource*> &resList);
+ inline void startTimer();
+ inline void stopTimer();
};
QTextStream & operator<< (QTextStream &output,
diff --git a/resourceqt-client/resourceqt-client.cpp b/resourceqt-client/resourceqt-client.cpp
index 240b3ce..9bf61d2 100644
--- a/resourceqt-client/resourceqt-client.cpp
+++ b/resourceqt-client/resourceqt-client.cpp
@@ -56,6 +56,7 @@ int main(int argc, char *argv[])
if (!parser.parseArguments()) {
return 1;
}
+ verbose = parser.shouldBeVerbose();
if (!client.initialize(parser)) {
qFatal("Initialization failed");