From b2d4ff7a9342b47b48d180b2ec3032741d28ec3d Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Fri, 26 Nov 2010 16:35:27 +0000 Subject: [PATCH] suppress driver chatter when YARP_QUIET is set svn path=/trunk/yarp2/; revision=8385 --- ChangeLog | 5 ++++ src/libYARP_OS/include/yarp/os/Log.h | 5 ++++ src/libYARP_OS/include/yarp/os/impl/Logger.h | 12 ++++++++ src/libYARP_OS/src/Logger.cpp | 18 +++++++++++ src/libYARP_OS/src/RateThread.cpp | 8 +++-- .../include/yarp/dev/TestFrameGrabber.h | 20 ++++++------- src/libYARP_dev/include/yarp/dev/TestMotor.h | 5 +++- src/libYARP_dev/src/Drivers.cpp | 30 ++++++++++++------- src/libYARP_dev/src/PolyDriver.cpp | 10 +++++-- src/libYARP_dev/src/ServerControlBoard.cpp | 17 ++++++++--- src/libYARP_dev/src/ServerFrameGrabber.cpp | 16 +++++++--- 11 files changed, 111 insertions(+), 35 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c84dfdde42..c083c853c94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-11-26 Paul Fitzpatrick + + * src/libYARP_dev/src/ServerControlBoard.cpp: when YARP_QUIET + is set, suppress driver chatter [thanks Gianluca Massera] + 2010-11-25 Ugo Pattacini * GazeControl.h and CartesianControl.h: added methods to save/restore diff --git a/src/libYARP_OS/include/yarp/os/Log.h b/src/libYARP_OS/include/yarp/os/Log.h index 79bb6d0ecfa..b4446ca8958 100644 --- a/src/libYARP_OS/include/yarp/os/Log.h +++ b/src/libYARP_OS/include/yarp/os/Log.h @@ -33,6 +33,11 @@ YARP_OS_API void __yarp_warn(const char *str); YARP_OS_API void __yarp_info(const char *str); YARP_OS_API void __yarp_debug(const char *str); +YARP_OS_API bool yarp_show_error(); +YARP_OS_API bool yarp_show_warn(); +YARP_OS_API bool yarp_show_info(); +YARP_OS_API bool yarp_show_debug(); + #define YARP_LOG_ERROR(x) __yarp_error(x) #define YARP_LOG_WARN(x) __yarp_warn(x) #define YARP_LOG_INFO(x) __yarp_info(x) diff --git a/src/libYARP_OS/include/yarp/os/impl/Logger.h b/src/libYARP_OS/include/yarp/os/impl/Logger.h index 79c87313a07..255b4ba7046 100644 --- a/src/libYARP_OS/include/yarp/os/impl/Logger.h +++ b/src/libYARP_OS/include/yarp/os/impl/Logger.h @@ -115,6 +115,18 @@ class yarp::os::impl::Logger : public ACE_Log_Msg_Callback { return pid; } + bool shouldShowInfo() { + return (verbose>=0); + } + + bool shouldShowError() { + return true; + } + + bool shouldShowDebug() { + return (verbose>0); + } + private: void show(int level, const String& txt); void exit(int result); diff --git a/src/libYARP_OS/src/Logger.cpp b/src/libYARP_OS/src/Logger.cpp index 337ab9ba3ee..0bc8f725b21 100644 --- a/src/libYARP_OS/src/Logger.cpp +++ b/src/libYARP_OS/src/Logger.cpp @@ -100,3 +100,21 @@ void __yarp_info(const char *str) { void __yarp_debug(const char *str) { YARP_DEBUG(Logger::get(),str); } + + +bool yarp_show_error() { + return Logger::get().shouldShowError(); +} + +bool yarp_show_warn() { + return Logger::get().shouldShowError(); +} + +bool yarp_show_info() { + return Logger::get().shouldShowInfo(); +} + +bool yarp_show_debug() { + return Logger::get().shouldShowDebug(); +} + diff --git a/src/libYARP_OS/src/RateThread.cpp b/src/libYARP_OS/src/RateThread.cpp index fa937716a24..de557365967 100644 --- a/src/libYARP_OS/src/RateThread.cpp +++ b/src/libYARP_OS/src/RateThread.cpp @@ -385,10 +385,12 @@ bool RateThreadWrapper::open(double framerate, bool polling) { int period = 0; if (framerate>0) { period=(int) (0.5+1000.0/framerate); - ACE_OS::printf("Setting framerate to: %.0lf[Hz] (thread period %d[ms])\n", - framerate, period); + YARP_SPRINTF2(Logger::get(),info, + "Setting framerate to: %.0lf[Hz] (thread period %d[ms])\n", + framerate, period); } else { - ACE_OS::printf("No framerate specified, polling the device\n"); + YARP_SPRINTF0(Logger::get(),info, + "No framerate specified, polling the device"); period=0; //continuous } RateThread::setRate(period); diff --git a/src/libYARP_dev/include/yarp/dev/TestFrameGrabber.h b/src/libYARP_dev/include/yarp/dev/TestFrameGrabber.h index 50b890c0273..76e3bff233d 100644 --- a/src/libYARP_dev/include/yarp/dev/TestFrameGrabber.h +++ b/src/libYARP_dev/include/yarp/dev/TestFrameGrabber.h @@ -16,6 +16,7 @@ #include #include #include +#include #define VOCAB_LINE VOCAB4('l','i','n','e') @@ -100,16 +101,15 @@ class YARP_dev_API yarp::dev::TestFrameGrabber : public DeviceDriver, yarp::os::Value(VOCAB_LINE, true), "bouncy [ball], scrolly [line], grid [grid], random [rand]").asVocab(); - if (freq!=-1) - { - printf("Test grabber period %g / freq %g , mode [%s]\n", period, freq, - yarp::os::Vocab::decode(mode).c_str()); - } - else - { - printf("Test grabber period %g / freq [inf], mode [%s]\n", period, - yarp::os::Vocab::decode(mode).c_str()); - } + if (yarp_show_info()) { + if (freq!=-1) { + printf("Test grabber period %g / freq %g , mode [%s]\n", period, freq, + yarp::os::Vocab::decode(mode).c_str()); + } else { + printf("Test grabber period %g / freq [inf], mode [%s]\n", period, + yarp::os::Vocab::decode(mode).c_str()); + } + } bx = w/2; by = h/2; diff --git a/src/libYARP_dev/include/yarp/dev/TestMotor.h b/src/libYARP_dev/include/yarp/dev/TestMotor.h index 5a006284101..6f5c5f32e3e 100644 --- a/src/libYARP_dev/include/yarp/dev/TestMotor.h +++ b/src/libYARP_dev/include/yarp/dev/TestMotor.h @@ -18,6 +18,7 @@ #include #include +#include namespace yarp { namespace dev { @@ -45,7 +46,9 @@ class YARP_dev_API yarp::dev::TestMotor : public DeviceDriver, virtual bool getAxes(int *ax) { *ax = njoints; - printf("TestMotor reporting %d axes present\n", *ax); + if (yarp_show_info()) { + printf("TestMotor reporting %d axes present\n", *ax); + } return true; } diff --git a/src/libYARP_dev/src/Drivers.cpp b/src/libYARP_dev/src/Drivers.cpp index cf1477f8928..97814a019ff 100644 --- a/src/libYARP_dev/src/Drivers.cpp +++ b/src/libYARP_dev/src/Drivers.cpp @@ -202,17 +202,23 @@ static void handler (int) { handleTime = now; ct++; if (ct>3) { - printf("Aborting...\n"); + if (yarp_show_info()) { + printf("Aborting...\n"); + } ACE_OS::exit(1); } if (terminatorKey!="") { - printf("[try %d of 3] Trying to shut down %s\n", - ct, - terminatorKey.c_str()); + if (yarp_show_info()) { + printf("[try %d of 3] Trying to shut down %s\n", + ct, + terminatorKey.c_str()); + } terminated = true; Terminator::terminateByName(terminatorKey.c_str()); } else { - printf("Aborting...\n"); + if (yarp_show_info()) { + printf("Aborting...\n"); + } ACE_OS::exit(1); } } @@ -366,8 +372,9 @@ int Drivers::yarpdev(int argc, char *argv[]) { if (service!=NULL) { double now = Time::now(); if (now-startTime>dnow) { - printf("yarpdev: device active...\n"); - fflush(stdout); + if (yarp_show_info()) { + YARP_LOG_INFO("device active..."); + } startTime += dnow; } // we requested single threading, so need to @@ -375,8 +382,9 @@ int Drivers::yarpdev(int argc, char *argv[]) { service->updateService(); } else { // we don't need to do anything - printf("yarpdev: device active in background...\n"); - fflush(stdout); + if (yarp_show_info()) { + YARP_LOG_INFO("device active in background..."); + } Time::delay(dnow); } } @@ -384,7 +392,9 @@ int Drivers::yarpdev(int argc, char *argv[]) { delete terminee; dd.close(); - printf("yarpdev is finished.\n"); + if (yarp_show_info()) { + printf("yarpdev is finished.\n"); + } return 0; } diff --git a/src/libYARP_dev/src/PolyDriver.cpp b/src/libYARP_dev/src/PolyDriver.cpp index 891827292b5..76a873d4ddd 100644 --- a/src/libYARP_dev/src/PolyDriver.cpp +++ b/src/libYARP_dev/src/PolyDriver.cpp @@ -277,9 +277,13 @@ bool PolyDriver::coreOpen(yarp::os::Searchable& prop) { ConstString name = creator->getName(); ConstString wrapper = creator->getWrapper(); ConstString code = creator->getCode(); - printf("yarpdev: created %s <%s>. See C++ class %s for documentation.\n", - (name==wrapper)?"wrapper":"device", - name.c_str(), code.c_str()); + if (yarp_show_info()) { + ConstString msg = ConstString("created ") + + ((name==wrapper)?"wrapper":"device") + + " <" + name + ">. See C++ class " + + code + " for documentation."; + YARP_LOG_INFO(msg); + } } } dd = driver; diff --git a/src/libYARP_dev/src/ServerControlBoard.cpp b/src/libYARP_dev/src/ServerControlBoard.cpp index 95be826a344..3a1acb85a13 100644 --- a/src/libYARP_dev/src/ServerControlBoard.cpp +++ b/src/libYARP_dev/src/ServerControlBoard.cpp @@ -243,7 +243,9 @@ class yarp::dev::ServerControlBoard : Value *name; if (prop.check("subdevice",name,"name of specific control device to wrap")) { - printf("Subdevice %s\n", name->toString().c_str()); + if (yarp_show_info()) { + printf("ControlBoard subdevice is %s\n", name->toString().c_str()); + } if (name->isString()) { // maybe user isn't doing nested configuration Property p; @@ -355,7 +357,9 @@ class yarp::dev::ServerControlBoard : * The thread main loop deals with writing on ports here. */ virtual void run() { - printf("Server control board starting\n"); + if (yarp_show_info()) { + printf("Server control board starting\n"); + } double before, now; while (!isStopping()) { before = Time::now(); @@ -379,10 +383,15 @@ class yarp::dev::ServerControlBoard : Time::delay(k); } else { - printf("Can't comply with the %d ms period\n", thread_period); + if (yarp_show_warn()) { + printf("Can't comply with the %d ms period\n", + thread_period); + } } } - printf("Server control board stopping\n"); + if (yarp_show_info()) { + printf("Server control board stopping\n"); + } } /* IPidControl */ diff --git a/src/libYARP_dev/src/ServerFrameGrabber.cpp b/src/libYARP_dev/src/ServerFrameGrabber.cpp index 260b1ec2dd1..28f9a4b59af 100644 --- a/src/libYARP_dev/src/ServerFrameGrabber.cpp +++ b/src/libYARP_dev/src/ServerFrameGrabber.cpp @@ -115,19 +115,27 @@ bool ServerFrameGrabber::open(yarp::os::Searchable& config) { if (fgAv!=NULL) { if (separatePorts) { - printf("Grabber for images and sound (in separate ports)\n"); + if (yarp_show_info()) { + printf("Grabber for images and sound (in separate ports)\n"); + } YARP_ASSERT(p2!=NULL); thread.attach(new DataWriter2, yarp::sig::Sound>(p,*p2,*this,canDrop,addStamp)); } else { - printf("Grabber for images and sound (in shared port)\n"); + if (yarp_show_info()) { + printf("Grabber for images and sound (in shared port)\n"); + } thread.attach(new DataWriter(p,*this,canDrop, addStamp)); } } else if (fgImage!=NULL) { - printf("Grabber for images\n"); + if (yarp_show_debug()) { + printf("Grabber for images\n"); + } thread.attach(new DataWriter >(p,*this,canDrop,addStamp,fgTimed)); } else if (fgSound!=NULL) { - printf("Grabber for sound\n"); + if (yarp_show_info()) { + printf("Grabber for sound\n"); + } thread.attach(new DataWriter(p,*this,canDrop)); } else { printf("subdevice <%s> doesn't look like a framegrabber\n",