From 2db176e028c54684e2fe6adf58ab0c5807d298c9 Mon Sep 17 00:00:00 2001 From: Wolf Bergenheim Date: Thu, 18 Nov 2010 08:11:11 +0200 Subject: Took -i and -v flags into use --- resourceqt-client/client.cpp | 54 +++++++++++++++++---------------- resourceqt-client/client.h | 3 ++ resourceqt-client/resourceqt-client.cpp | 1 + 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 &resList) void Client::resourceAcquiredHandler(const QList&) { - long int ms = stop_timer(); - if (ms > 0) { - outputln << "Operation took " << ms << "ms" << endl; - } + stopTimer(); QList list = resourceSet->resources(); if (!list.count()) { @@ -228,10 +226,7 @@ void Client::resourceAcquiredHandler(const QList&) void Client::resourceDeniedHandler() { - long int ms = stop_timer(); - if (ms > 0) { - outputln << "Operation took " << ms << "ms" << endl; - } + stopTimer(); QList 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 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 allResources = resourceSet->resources(); outputln << "released:"<< allResources << endl; @@ -265,10 +254,7 @@ void Client::resourcesBecameAvailableHandler(const QList 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 commandList; @@ -80,6 +81,8 @@ private: void showPrompt(); void showResources(const QList &resList); void showResources(const QList &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"); -- cgit v1.2.3