From 992a044efaedc9704fc2d147ce8250de15409b41 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Tue, 22 Dec 2020 22:23:32 +0100 Subject: [PATCH] Introduce command line parameters to handle showing nmsd messages. Default is on. Remove any NDEBUG handling, because that was overidden by distributions default build options. We want the users to report meaningful bugs --- src/Endpoint.cpp | 62 +++++++++++++++++++++--------------------- src/Endpoint.hpp | 2 +- src/debug.cpp | 2 ++ src/debug.h | 21 ++++++-------- src/nsm-legacy-gui.cpp | 6 ++-- src/nsm-proxy.cpp | 20 +++++++------- src/nsmd.cpp | 22 +++++++++------ 7 files changed, 69 insertions(+), 66 deletions(-) diff --git a/src/Endpoint.cpp b/src/Endpoint.cpp index f8085e7..14bc2d7 100644 --- a/src/Endpoint.cpp +++ b/src/Endpoint.cpp @@ -94,7 +94,7 @@ namespace OSC char *new_path; asprintf( &new_path, "%s%s", _endpoint->name() ? _endpoint->name() : "", path ); - DMESSAGE( "Renaming signal %s to %s", this->path(), new_path ); + MESSAGE( "Renaming signal %s to %s", this->path(), new_path ); /* if ( _direction == Signal::Input ) */ /* { */ @@ -138,12 +138,12 @@ namespace OSC } /* else if ( direction() == Input ) */ /* { */ - /* DMESSAGE( "Sending value feedback for signal %s...", path() ); */ + /* MESSAGE( "Sending value feedback for signal %s...", path() ); */ /* for ( std::list::iterator i = _incoming.begin(); */ /* i != _incoming.end(); */ /* ++i ) */ /* { */ - /* DMESSAGE( "Sending value feedback to %s %s %f", lo_address_get_url( (*i)->_peer->addr), (*i)->path() , f); */ + /* MESSAGE( "Sending value feedback to %s %s %f", lo_address_get_url( (*i)->_peer->addr), (*i)->path() , f); */ /* _endpoint->send( (*i)->_peer->addr, */ /* (*i)->path(), */ /* f ); */ @@ -202,7 +202,7 @@ namespace OSC int Endpoint::init ( int proto, const char *port ) { - DMESSAGE( "Creating OSC server" ); + MESSAGE( "Creating OSC server" ); _server = lo_server_new_with_proto( port, proto, error_handler ); @@ -315,7 +315,7 @@ namespace OSC void Endpoint::handle_hello ( const char *peer_name, const char *peer_url ) { - DMESSAGE( "Got hello from %s", peer_name ); + MESSAGE( "Got hello from %s", peer_name ); Peer *p = find_peer_by_name( peer_name ); @@ -344,7 +344,7 @@ namespace OSC /* scan it while we're at it */ p->_scanning = true; - DMESSAGE( "Scanning peer %s", peer_name ); + MESSAGE( "Scanning peer %s", peer_name ); send( p->addr, "/signal/list" ); } @@ -355,7 +355,7 @@ namespace OSC } else { - DMESSAGE( "Not sending hello because we don't have a name yet!" ); + MESSAGE( "Not sending hello because we don't have a name yet!" ); } } @@ -387,7 +387,7 @@ namespace OSC if ( s->_direction == Signal::Input ) { - DMESSAGE( "Peer %s has disconnected from signal %s", our_name, their_name ); + MESSAGE( "Peer %s has disconnected from signal %s", our_name, their_name ); ep->del_translation( their_name ); @@ -422,7 +422,7 @@ namespace OSC return 0; } - DMESSAGE( "Has requested signal connection %s |> %s", src_path, dst_s->path() ); + MESSAGE( "Has requested signal connection %s |> %s", src_path, dst_s->path() ); ep->add_translation( src_path, dst_s->path() ); @@ -455,7 +455,7 @@ namespace OSC return 0; } - DMESSAGE( "Signal %s:%s was removed", o->_peer->name, o->path() ); + MESSAGE( "Signal %s:%s was removed", o->_peer->name, o->path() ); if ( ep->_peer_signal_notification_callback ) @@ -501,7 +501,7 @@ namespace OSC p->_signals.push_back( s ); - DMESSAGE( "Peer %s has created signal %s (%s %f %f %f)", p->name, + MESSAGE( "Peer %s has created signal %s (%s %f %f %f)", p->name, name, direction, min, max, default_value ); if ( ep->_peer_signal_notification_callback ) @@ -513,7 +513,7 @@ namespace OSC int Endpoint::osc_sig_renamed ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) { - DMESSAGE( "Got renamed message." ); + MESSAGE( "Got renamed message." ); const char *old_name = &argv[0]->s; const char *new_name = &argv[1]->s; @@ -536,7 +536,7 @@ namespace OSC return 0; } - DMESSAGE( "Signal %s was renamed to %s", o->_path, new_name ); + MESSAGE( "Signal %s was renamed to %s", o->_path, new_name ); ep->rename_translation_source( o->_path, new_name ); @@ -685,7 +685,7 @@ namespace OSC { ep->add_translation( path, ep->_learning_path ); - DMESSAGE( "Learned translation \"%s\" -> \"%s\"", path, ep->_learning_path ); + MESSAGE( "Learned translation \"%s\" -> \"%s\"", path, ep->_learning_path ); free(ep->_learning_path); ep->_learning_path = NULL; @@ -700,11 +700,11 @@ namespace OSC { const char *dpath = i->second.path.c_str(); -// DMESSAGE( "Translating message \"%s\" to \"%s\"", path, dpath ); +// MESSAGE( "Translating message \"%s\" to \"%s\"", path, dpath ); if ( !strcmp(types, "f" )) { -// DMESSAGE( "recording value %f", argv[0]->f ); +// MESSAGE( "recording value %f", argv[0]->f ); i->second.current_value = argv[0]->f; } @@ -741,7 +741,7 @@ namespace OSC { // OSC_DMSG(); - DMESSAGE( "Listing signals." ); + MESSAGE( "Listing signals." ); const char *prefix = NULL; @@ -906,7 +906,7 @@ namespace OSC if ( argc == 1 ) { p->_scanning = false; - DMESSAGE( "Done scanning %s", p->name ); + MESSAGE( "Done scanning %s", p->name ); if ( ep->_peer_scan_complete_callback ) ep->_peer_scan_complete_callback(ep->_peer_scan_complete_userdata); @@ -918,7 +918,7 @@ namespace OSC if ( s ) return 0; - DMESSAGE( "Peer %s has signal %s (%s)", p->name, &argv[1]->s, &argv[2]->s ); + MESSAGE( "Peer %s has signal %s (%s)", p->name, &argv[1]->s, &argv[2]->s ); int dir = 0; @@ -951,7 +951,7 @@ namespace OSC Method * Endpoint::add_method ( const char *path, const char *typespec, lo_method_handler handler, void *user_data, const char *argument_description ) { -// DMESSAGE( "Added OSC method %s (%s)", path, typespec ); +// MESSAGE( "Added OSC method %s (%s)", path, typespec ); lo_server_add_method( _server, path, typespec, handler, user_data ); @@ -1013,7 +1013,7 @@ namespace OSC void Endpoint::del_method ( const char *path, const char *typespec ) { -// DMESSAGE( "Deleted OSC method %s (%s)", path, typespec ); +// MESSAGE( "Deleted OSC method %s (%s)", path, typespec ); lo_server_del_method( _server, path, typespec ); @@ -1036,7 +1036,7 @@ namespace OSC void Endpoint::del_method ( Method *meth ) { -// DMESSAGE( "Deleted OSC method %s (%s)", path, typespec ); +// MESSAGE( "Deleted OSC method %s (%s)", path, typespec ); lo_server_del_method( _server, meth->path(), meth->typespec() ); @@ -1048,7 +1048,7 @@ namespace OSC void Endpoint::del_signal ( Signal *o ) { -// DMESSAGE( "Deleted OSC method %s (%s)", path, typespec ); +// MESSAGE( "Deleted OSC method %s (%s)", path, typespec ); lo_server_del_method( _server, o->path(), NULL ); @@ -1095,7 +1095,7 @@ namespace OSC { const char *spath = i->first.c_str(); -// DMESSAGE( "Sending feedback to \"%s\": %f", spath, v ); +// MESSAGE( "Sending feedback to \"%s\": %f", spath, v ); /* send to all peers */ for ( std::list::iterator p = _peers.begin(); @@ -1121,7 +1121,7 @@ namespace OSC { Peer *p = new Peer; - DMESSAGE( "Adding peer %s @ %s...", name, url ); + MESSAGE( "Adding peer %s @ %s...", name, url ); p->name = strdup( name ); p->addr = lo_address_new_from_url( url ); @@ -1138,7 +1138,7 @@ namespace OSC p->_scanning = true; - DMESSAGE( "Scanning peer %s", name ); + MESSAGE( "Scanning peer %s", name ); send( p->addr, "/signal/list" ); } @@ -1156,7 +1156,7 @@ namespace OSC { _thread.name( "OSC" ); - DMESSAGE( "OSC Thread running" ); + MESSAGE( "OSC Thread running" ); run(); } @@ -1231,15 +1231,15 @@ namespace OSC switch ( ov->type() ) { case 'f': -// DMESSAGE( "Adding float %f", ((OSC_Float*)ov)->value() ); +// MESSAGE( "Adding float %f", ((OSC_Float*)ov)->value() ); lo_message_add_float( m, ((OSC_Float*)ov)->value() ); break; case 'i': -// DMESSAGE( "Adding int %i", ((OSC_Int*)ov)->value() ); +// MESSAGE( "Adding int %i", ((OSC_Int*)ov)->value() ); lo_message_add_int32( m, ((OSC_Int*)ov)->value() ); break; case 's': -// DMESSAGE( "Adding string %s", ((OSC_String*)ov)->value() ); +// MESSAGE( "Adding string %s", ((OSC_String*)ov)->value() ); lo_message_add_string( m, ((OSC_String*)ov)->value() ); break; default: @@ -1248,7 +1248,7 @@ namespace OSC } } -// DMESSAGE( "Path: %s", path ); +// MESSAGE( "Path: %s", path ); lo_bundle b = lo_bundle_new( LO_TT_IMMEDIATE ); diff --git a/src/Endpoint.hpp b/src/Endpoint.hpp index 62464fc..7354406 100644 --- a/src/Endpoint.hpp +++ b/src/Endpoint.hpp @@ -419,7 +419,7 @@ namespace OSC /* helper macros for defining OSC handlers */ /* #define OSC_NAME( name ) osc_ ## name */ -#define OSC_DMSG() DMESSAGE( "Got OSC message: %s", path ); +#define OSC_DMSG() MESSAGE( "Got OSC message: %s", path ); // #define OSC_HANDLER( name ) static int OSC_NAME( name ) ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) diff --git a/src/debug.cpp b/src/debug.cpp index 8806bd9..68540ce 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -28,6 +28,8 @@ extern char * program_invocation_short_name; +bool quietMessages = false; + void warnf ( warning_t level, const char *module, diff --git a/src/debug.h b/src/debug.h index ab4c4dc..f0964fe 100644 --- a/src/debug.h +++ b/src/debug.h @@ -68,6 +68,8 @@ */ + + #ifndef _DEBUG_H #define _DEBUG_H @@ -83,6 +85,8 @@ #define __FUNCTION__ NULL #endif +extern bool quietMessages; + typedef enum { W_MESSAGE = 0, W_WARNING, @@ -95,20 +99,13 @@ warnf ( warning_t level, const char *file, const char *function, int line, const char *fmt, ... ); +//We do not use NDEBUG anymore. Messages are a command line switch. +//Warnings, asserts and errors are always important. -#ifndef NDEBUG -#define DMESSAGE( fmt, args... ) warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ) -#define DWARNING( fmt, args... ) warnf( W_WARNING, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ) -#define ASSERT( pred, fmt, args... ) do { if ( ! (pred) ) { warnf( W_FATAL, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ); abort(); } } while ( 0 ) -#else -#define DMESSAGE( fmt, args... ) -#define DWARNING( fmt, args... ) -#define ASSERT( pred, fmt, args... ) (void)(pred) -#endif - -/* these are always defined */ -#define MESSAGE( fmt, args... ) warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ) +// #define MESSAGE( fmt, args... ) warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ) +#define MESSAGE( fmt, args... ) do { if ( ! (quietMessages) ) { warnf( W_MESSAGE, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ); } } while ( 0 ) #define WARNING( fmt, args... ) warnf( W_WARNING, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ) #define FATAL( fmt, args... ) ( warnf( W_FATAL, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ), abort() ) +#define ASSERT( pred, fmt, args... ) do { if ( ! (pred) ) { warnf( W_FATAL, __MODULE__, __FILE__, __FUNCTION__, __LINE__, fmt, ## args ); abort(); } } while ( 0 ) #endif diff --git a/src/nsm-legacy-gui.cpp b/src/nsm-legacy-gui.cpp index ee6c095..1fa392e 100644 --- a/src/nsm-legacy-gui.cpp +++ b/src/nsm-legacy-gui.cpp @@ -1071,7 +1071,7 @@ private: /* need at least one argument... */ return 0; - DMESSAGE( "Relaying broadcast" ); + MESSAGE( "Relaying broadcast" ); foreach_daemon( d ) { @@ -1337,7 +1337,7 @@ main (int argc, char **argv ) { case 'n': { - DMESSAGE( "Adding %s to daemon list", optarg ); + MESSAGE( "Adding %s to daemon list", optarg ); Daemon *d = new Daemon; d->url = optarg; @@ -1412,7 +1412,7 @@ main (int argc, char **argv ) for ( ; optind < argc; i++, optind++ ) { - DMESSAGE( "Passing argument: %s", argv[optind] ); + MESSAGE( "Passing argument: %s", argv[optind] ); args[i] = argv[optind]; } diff --git a/src/nsm-proxy.cpp b/src/nsm-proxy.cpp index 812785b..601cabd 100644 --- a/src/nsm-proxy.cpp +++ b/src/nsm-proxy.cpp @@ -202,7 +202,7 @@ public: void save ( void ) { - DMESSAGE( "Sending process save signal" ); + MESSAGE( "Sending process save signal" ); if ( _pid ) ::kill( _pid, _save_signal ); } @@ -261,7 +261,7 @@ public: while ( 2 == fscanf( fp, "%m[^\n]\n\t%m[^\n]\n", &name, &value ) ) { - DMESSAGE( "%s=%s", name, value ); + MESSAGE( "%s=%s", name, value ); if ( !strcmp( name, "executable" ) ) _executable = value; @@ -301,7 +301,7 @@ public: void update ( lo_address to ) { - DMESSAGE( "Sending update" ); + MESSAGE( "Sending update" ); lo_send_from( to, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/save_signal", "i", _save_signal ); lo_send_from( to, losrv, LO_TT_IMMEDIATE, "/nsm/proxy/label", "s", _label ? _label : "" ); @@ -603,12 +603,12 @@ signal_handler ( int x ) void set_traps ( void ) { - signal( SIGHUP, signal_handler ); - signal( SIGINT, signal_handler ); -// signal( SIGQUIT, signal_handler ); -// signal( SIGSEGV, signal_handler ); -// signal( SIGPIPE, signal_handler ); - signal( SIGTERM, signal_handler ); + signal( SIGHUP, signal_handler ); + signal( SIGINT, signal_handler ); +// signal( SIGQUIT, signal_handler ); +// signal( SIGSEGV, signal_handler ); +// signal( SIGPIPE, signal_handler ); + signal( SIGTERM, signal_handler ); } @@ -645,7 +645,7 @@ die ( void ) { if ( gui_pid ) { - DMESSAGE( "Killing GUI" ); + MESSAGE( "Killing GUI" ); kill( gui_pid, SIGTERM ); } diff --git a/src/nsmd.cpp b/src/nsmd.cpp index 63f7c78..37cf35a 100644 --- a/src/nsmd.cpp +++ b/src/nsmd.cpp @@ -282,7 +282,6 @@ static std::list< Client* > client; /* helper macros for defining OSC handlers */ #define OSC_NAME( name ) osc_ ## name -// #define OSCDMSG() DMESSAGE( "Got OSC message: %s", path ); #define OSC_HANDLER( name ) static int OSC_NAME( name ) ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) static char *session_path = NULL; @@ -1467,7 +1466,7 @@ load_session_file ( const char * path ) { //This is not the case when --load-session was used. GUI announce will come later. //Send two parameters to signal that the session was loaded: simple session-name, relative session path below session root - DMESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); + MESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); osc_server->send( gui_addr, "/nsm/gui/session/name", session_name, session_path + strlen( session_root )); } @@ -1663,7 +1662,7 @@ OSC_HANDLER( new ) osc_server->send( gui_addr, "/nsm/gui/session/session", &argv[0]->s ); //Send two parameters to signal that the session was loaded: simple session-name, relative session path below session root - DMESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); + MESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); osc_server->send( gui_addr, "/nsm/gui/session/name", session_name, session_path + strlen( session_root )); } @@ -2306,7 +2305,7 @@ announce_gui( const char *url, bool is_reply ) //No session_path without session_name. We only need to test for session_name. if ( !session_name || session_name[0] == '\0' ) { - DMESSAGE( "Informing GUI that no session is running by sending two empty strings" ); + MESSAGE( "Informing GUI that no session is running by sending two empty strings" ); osc_server->send( gui_addr, "/nsm/gui/session/name", "", "" ); //Empty string = no current session } else @@ -2331,11 +2330,11 @@ announce_gui( const char *url, bool is_reply ) osc_server->send( gui_addr, "/nsm/gui/client/new", c->client_id, c->name ); // upgrade to pretty-name } - DMESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); + MESSAGE( "Informing GUI about running session name: %s with relative path %s", session_name, session_path + strlen( session_root ) ); osc_server->send( gui_addr, "/nsm/gui/session/name", session_name, session_path + strlen( session_root )); } - DMESSAGE( "Registration with GUI complete\n" ); + MESSAGE( "Registration with GUI complete\n" ); } @@ -2410,6 +2409,7 @@ int main(int argc, char *argv[]) { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'v' }, { "load-session", required_argument, 0, 'l'}, + { "quiet", no_argument, 0, 'q'}, //supresses all normal MESSAGE except WARNING and FATAL { 0, 0, 0, 0 } }; @@ -2436,21 +2436,24 @@ int main(int argc, char *argv[]) break; } case 'p': - DMESSAGE( "Using OSC port %s", optarg ); + MESSAGE( "Using OSC port %s", optarg ); osc_port = optarg; break; case 'g': - DMESSAGE( "Going to connect to GUI at: %s", optarg ); + MESSAGE( "Going to connect to GUI at: %s", optarg ); gui_url = optarg; break; case 'l': - DMESSAGE( "Loading existing session file %s", optarg); + MESSAGE( "Loading existing session file %s", optarg); load_session = optarg; break; case 'v': printf( "%s " VERSION_STRING "\n", argv[0] ); exit(0); break; + case 'q': + quietMessages = true; //from debug.h + break; case 'h': //Print usage message according to POSIX.1-2017 const char *usage = @@ -2468,6 +2471,7 @@ int main(int argc, char *argv[]) " --load-session name Load existing session [Example: \"My Song\"].\n" " --gui-url url Connect to running legacy-gui [Example: osc.udp://mycomputer.localdomain:38356/].\n" " --detach Detach from console.\n" + " --quiet Suppress messages except warnings and errors.\n" "\n\n" "nsmd can be run headless with existing sessions. To create new ones it is recommended to use a GUI\n" "such as nsm-legacy-gui (included) or Agordejo (separate package)\n"