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 +++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'resourceqt-client/client.cpp') 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; + } + } +} -- cgit v1.2.3