From cec5145e9a523a58edeae4cb041cff944edb1826 Mon Sep 17 00:00:00 2001 From: ahlstrom Date: Thu, 7 Nov 2024 07:29:22 -0500 Subject: [PATCH] Cleanup for issue #131. --- Seq66qt5/seq66qt5.cpp | 8 -- libseq66/include/seq66_features.hpp | 9 -- libseq66/src/os/daemonize.cpp | 13 ++- libseq66/src/sessions/clinsmanager.cpp | 6 -- libseq66/src/sessions/smanager.cpp | 66 ++++--------- libsessions/src/nsm/nsmbase.cpp | 123 ++++--------------------- 6 files changed, 48 insertions(+), 177 deletions(-) diff --git a/Seq66qt5/seq66qt5.cpp b/Seq66qt5/seq66qt5.cpp index 2cb02204..e3bd9d05 100644 --- a/Seq66qt5/seq66qt5.cpp +++ b/Seq66qt5/seq66qt5.cpp @@ -149,11 +149,6 @@ main (int argc, char * argv []) #endif int exit_status = EXIT_SUCCESS; /* versus EXIT_FAILURE */ - -#if defined SEQ66_IMMEDIATE_LOG_FILE - (void) seq66::reroute_stdio("session.log"); -#endif - for (;;) { seq66::qt5nsmanager sm(app); @@ -187,9 +182,6 @@ main (int argc, char * argv []) break; } } -#if defined SEQ66_IMMEDIATE_LOG_FILE - (void) seq66::close_stdio(); -#endif return exit_status; } diff --git a/libseq66/include/seq66_features.hpp b/libseq66/include/seq66_features.hpp index cde59a68..05572c48 100644 --- a/libseq66/include/seq66_features.hpp +++ b/libseq66/include/seq66_features.hpp @@ -45,15 +45,6 @@ #include "seq66_features.h" /* the C-compatible definitions */ -/* - * Define this to produce an immediate log file in the current directory. - * Useful in debugging NSM support. The 'usr'-specified log-file will not - * be opened. It happens too late anyway. Normally this macro should be - * *undefined*. - */ - -#undef SEQ66_IMMEDIATE_LOG_FILE - /* * This is the main namespace of Seq66. Do not attempt to * Doxygenate the documentation here; it breaks Doxygen. diff --git a/libseq66/src/os/daemonize.cpp b/libseq66/src/os/daemonize.cpp index ad7cb67d..2fffc95b 100644 --- a/libseq66/src/os/daemonize.cpp +++ b/libseq66/src/os/daemonize.cpp @@ -21,7 +21,7 @@ * \library seq66 application (from PSXC library) * \author Chris Ahlstrom * \date 2005-07-03 to 2007-08-21 (pre-Sequencer24/64) - * \updates 2024-11-05 + * \updates 2024-11-07 * \license GNU GPLv2 or above * * Daemonization module of the POSIX C Wrapper (PSXC) library @@ -457,6 +457,17 @@ close_stdio () return result; } +/** + * Reroute stdout and stderr to the same log file. This is allowed + * only once. + * + * \param logfile + * Provides the full path to the log file. + * + * \return + * Returns true if the rerouting worked or was already done. + */ + bool reroute_stdio (const std::string & logfile) { diff --git a/libseq66/src/sessions/clinsmanager.cpp b/libseq66/src/sessions/clinsmanager.cpp index 5eadbff0..7434670d 100644 --- a/libseq66/src/sessions/clinsmanager.cpp +++ b/libseq66/src/sessions/clinsmanager.cpp @@ -129,7 +129,6 @@ clinsmanager::detect_session (std::string & url) url.clear(); #if defined SEQ66_NSM_SUPPORT - std::string tenturl = nsm::get_url(); /* a tentative URL */ session_message("Checking for NSM_URL"); if (! tenturl.empty()) @@ -185,11 +184,6 @@ bool clinsmanager::create_session (int argc, char * argv []) { #if defined SEQ66_NSM_SUPPORT - -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("create_session"); -#endif - std::string url; bool ok = detect_session(url); /* side-effect */ if (! ok) diff --git a/libseq66/src/sessions/smanager.cpp b/libseq66/src/sessions/smanager.cpp index 206d8f34..0af5515f 100644 --- a/libseq66/src/sessions/smanager.cpp +++ b/libseq66/src/sessions/smanager.cpp @@ -25,7 +25,7 @@ * \library seq66 application * \author Chris Ahlstrom * \date 2020-03-22 - * \updates 2023-12-13 + * \updates 2024-11-07 * \license GNU GPLv2 or above * * Note that this module is part of the libseq66 library, not the libsessions @@ -215,10 +215,6 @@ smanager::main_settings (int argc, char * argv []) std::string parentname = get_parent_process_name(); bool in_nsm = contains(parentname, s_nsm_name); /* this is tentative! */ -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("main_settings"); -#endif - /* * Call app_info() above in main() instead of this. * @@ -285,26 +281,13 @@ smanager::main_settings (int argc, char * argv []) { int optionindex = (-1); bool sessionmodified = false; - if (rc().alt_session()) // issue #131 - { - - /* - * Check for a session, either defined by the environment variable - * "SEQ66_SESSION_TAG" or by the "--session-tag tag" option. The - * latter can override the first. - */ - -#if 0 // commented out for issue #131 - if (! rc().alt_session()) - { - std::string sesstag = cmdlineopts::env_session_tag(); - if (! sesstag.empty()) - rc().session_tag(sesstag); - } - if (rc().alt_session()) + if (rc().alt_session()) /* issue #131 */ { -#endif /* + * Check for a session, either defined by the environment + * variable "SEQ66_SESSION_TAG" or by the "--session-tag tag" + * option. The latter can override the first. + * * The name 'sessions.rc' is a bit more accurate. */ @@ -333,9 +316,12 @@ smanager::main_settings (int argc, char * argv []) return false; } } -#if 0 // comment out for issue #131 } -#endif + else + { + std::string sesstag = cmdlineopts::env_session_tag(); + if (! sesstag.empty()) + rc().session_tag(sesstag); } /* @@ -377,13 +363,15 @@ smanager::main_settings (int argc, char * argv []) { /* * The 'usr' file might not specify a log-file. Check again - * here. + * here. But do we really want to not do this for a verbose + * CLI run? + * + * bool uselog = ! (seq_app_cli() && rc().verbose()) && + * usr().option_use_logfile(); */ (void) cmdlineopts::parse_o_options(argc, argv); - bool uselog = ! (seq_app_cli() && rc().verbose()) && - usr().option_use_logfile(); - + bool uselog = usr().option_use_logfile(); /* * The user migh specify -o options that are also set up in @@ -492,11 +480,6 @@ smanager::create_performer () int cols = usr().mainwnd_cols(); pointer p(new (std::nothrow) performer(ppqn, rows, cols)); result = bool(p); - -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("main_settings"); -#endif - if (result) { m_perf_pointer = std::move(p); /* change the ownership */ @@ -653,11 +636,6 @@ smanager::open_midi_file (const std::string & fname) bool smanager::create_session (int /*argc*/, char * /*argv*/ []) { - -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("create_session"); -#endif - session_setup(); /* daemonize: set basic signal handlers */ return true; } @@ -684,11 +662,6 @@ smanager::create_session (int /*argc*/, char * /*argv*/ []) bool smanager::close_session (std::string & msg, bool ok) { - -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("close_session"); -#endif - bool result = not_nullptr(perf()); if (result) { @@ -1137,11 +1110,6 @@ smanager::create_configuration const std::string & midifilepath ) { - -#if defined SEQ66_IMMEDIATE_LOG_FILE - session_message("create_configuration"); -#endif - bool result = ! cfgfilepath.empty(); if (result) { diff --git a/libsessions/src/nsm/nsmbase.cpp b/libsessions/src/nsm/nsmbase.cpp index 5c7f003e..523349db 100644 --- a/libsessions/src/nsm/nsmbase.cpp +++ b/libsessions/src/nsm/nsmbase.cpp @@ -25,7 +25,7 @@ * \library seq66 application * \author Chris Ahlstrom * \date 2020-03-07 - * \updates 2024-11-06 + * \updates 2024-11-07 * \license GNU GPLv2 or above * * nsmbase is an Non Session Manager (NSM) OSC client helper. The NSM API @@ -121,8 +121,7 @@ static lo_timetag s_lo_timetag = { 0, 1 }; #include /* provides the pid_t typedef */ #include /* C getpid() */ -#include "seq66_features.hpp" /* seq66::set_app_path() */ -#include "cfg/settings.hpp" /* opt: SEQ66_IMMEDIATE_LOG_FILE */ +#include "cfg/settings.hpp" /* rc() and usr() functions */ #include "util/basic_macros.hpp" /* not_nullptr(), warnprint(), etc. */ #include "nsm/nsmbase.hpp" /* seq66::nsmbase class */ #include "nsm/nsmmessagesex.hpp" /* seq66::nsm new message functions */ @@ -137,29 +136,6 @@ static lo_timetag s_lo_timetag = { 0, 1 }; namespace seq66 { -/* - * Define in seq66_features.hpp only for trouble-shooting, especially under a - * session manager. - */ - -#if defined SEQ66_IMMEDIATE_LOG_FILE - -bool -verbose_send () -{ - return true; -} - -#else - -bool -verbose_send () -{ - return rc().verbose(); -} - -#endif - /** * A handler for the /reply message. */ @@ -277,10 +253,7 @@ nsmbase::start_thread () { int rcode = lo_server_thread_start(m_lo_server_thread); if (rcode == 0) /* successful? */ - { - if (rc().verbose()) - session_message("OSC server thread started"); - } + session_message("OSC server thread started"); else error_message("OSC server thread start failed"); } @@ -319,18 +292,15 @@ nsmbase::initialize () if (result) { const int proto = lo_address_get_protocol(m_lo_address); - if (rc().verbose()) + std::string ps = "Unknown"; + switch (proto) { - std::string ps = "Unknown"; - switch (proto) - { - case LO_UDP: ps = "UDP"; break; - case LO_TCP: ps = "TCP"; break; - case LO_UNIX: ps = "UNIX"; break; - } - ps += " OSC protocol"; - session_message(ps); + case LO_UDP: ps = "UDP"; break; + case LO_TCP: ps = "TCP"; break; + case LO_UNIX: ps = "UNIX"; break; } + ps += " OSC protocol"; + session_message(ps); m_lo_server_thread = lo_server_thread_new_with_proto(NULL, proto, NULL); result = not_nullptr(m_lo_server_thread); if (result) @@ -413,9 +383,7 @@ nsmbase::msg_check (int timeoutms) if (lo_server_wait(m_lo_server, timeoutms)) { result = true; - if (rc().verbose()) - session_message("NSM waiting for reply..."); - + session_message("NSM waiting for reply..."); while (lo_server_recv_noblock(m_lo_server, 0)) { /* do nothing, handle the message(s) */ @@ -526,11 +494,6 @@ nsmbase::is_dirty () { int rcode = send_from(message, pattern); ok = rcode == 0; -// lo_send_from /* "/nsm/client/is_dirty" "" */ -// ( -// m_lo_address, m_lo_server, LO_TT_IMMEDIATE_2, -// message.c_str(), pattern.c_str() -// ); } } return result; @@ -644,16 +607,8 @@ nsmbase::send_nsm_reply if (errorcode == nsm::error::ok) { if (client_msg(nsm::tag::reply, message, pattern)) - { rc = send_from(message, pattern, path, replymsg); -// rc = lo_send_from -// ( -// m_lo_address, m_lo_server, LO_TT_IMMEDIATE_2, -// message.c_str(), pattern.c_str(), -// path.c_str(), replymsg.c_str() -// ); - } replytype = "reply"; } else @@ -974,40 +929,6 @@ nsmbase::send_from_client { int rcode = send_from(message, pattern, s1, s2, s3); result = rcode != (-1); -#if 0 - if (s3.empty()) - { - rcode = lo_send_from /* e.g. "/nsm/client/is_clean" "" */ - ( - m_lo_address, m_lo_server, LO_TT_IMMEDIATE_2, - message.c_str(), pattern.c_str(), - s1.c_str(), s2.c_str() - ); - } - else - { - rcode = lo_send_from - ( - m_lo_address, m_lo_server, LO_TT_IMMEDIATE_2, - message.c_str(), pattern.c_str(), - s1.c_str(), s2.c_str(), s3.c_str() - ); - } - result = rcode != (-1); - if (result) - { - if (rc().verbose()) - { - std::string msg = "OSC message sent" + message; - session_message(msg); - } - } - else - { - std::string msg = "OSC message send FAILURE" + message; - error_message(msg); - } -#endif } return result; } @@ -1070,11 +991,8 @@ nsmbase::send_from } if (result != (-1)) { - if (verbose_send()) - { - std::string msg = "OSC message sent " + message + pattern; - session_message(msg); - } + std::string msg = "OSC message sent " + message + pattern; + session_message(msg); } else { @@ -1276,15 +1194,12 @@ outgoing_msg const std::string & data ) { - if (verbose_send()) - { - std::string text = msgsnprintf - ( - "%s-->[%s] %s", - message.c_str(), pattern.c_str(), data.c_str() - ); - session_message(text); - } + std::string text = msgsnprintf + ( + "%s-->[%s] %s", + message.c_str(), pattern.c_str(), data.c_str() + ); + session_message(text); } tokenization