Skip to content

Commit

Permalink
suppress driver chatter when YARP_QUIET is set
Browse files Browse the repository at this point in the history
svn path=/trunk/yarp2/; revision=8385
  • Loading branch information
paulfitz committed Nov 26, 2010
1 parent 3022850 commit b2d4ff7
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 35 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2010-11-26 Paul Fitzpatrick <paulfitz@alum.mit.edu>

* src/libYARP_dev/src/ServerControlBoard.cpp: when YARP_QUIET
is set, suppress driver chatter [thanks Gianluca Massera]

2010-11-25 Ugo Pattacini <ugo.pattacini@iit.it>

* GazeControl.h and CartesianControl.h: added methods to save/restore
Expand Down
5 changes: 5 additions & 0 deletions src/libYARP_OS/include/yarp/os/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions src/libYARP_OS/include/yarp/os/impl/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 18 additions & 0 deletions src/libYARP_OS/src/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

8 changes: 5 additions & 3 deletions src/libYARP_OS/src/RateThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions src/libYARP_dev/include/yarp/dev/TestFrameGrabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <yarp/os/Searchable.h>
#include <yarp/os/Time.h>
#include <yarp/os/Vocab.h>
#include <yarp/os/Log.h>

#define VOCAB_LINE VOCAB4('l','i','n','e')

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/libYARP_dev/include/yarp/dev/TestMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <yarp/dev/PolyDriver.h>

#include <yarp/os/Time.h>
#include <yarp/os/Log.h>

namespace yarp {
namespace dev {
Expand Down Expand Up @@ -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;
}

Expand Down
30 changes: 20 additions & 10 deletions src/libYARP_dev/src/Drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -366,25 +372,29 @@ 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
// give the device its chance
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);
}
}

delete terminee;
dd.close();

printf("yarpdev is finished.\n");
if (yarp_show_info()) {
printf("yarpdev is finished.\n");
}

return 0;
}
Expand Down
10 changes: 7 additions & 3 deletions src/libYARP_dev/src/PolyDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 13 additions & 4 deletions src/libYARP_dev/src/ServerControlBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 */
Expand Down
16 changes: 12 additions & 4 deletions src/libYARP_dev/src/ServerFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::ImageOf<yarp::sig::PixelRgb>, 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<ImageRgbSound>(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<yarp::sig::ImageOf<yarp::sig::PixelRgb> >(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<yarp::sig::Sound>(p,*this,canDrop));
} else {
printf("subdevice <%s> doesn't look like a framegrabber\n",
Expand Down

0 comments on commit b2d4ff7

Please sign in to comment.