From 816cb8805608a2a8f3ce0e104da4aae72e3486f7 Mon Sep 17 00:00:00 2001
From: "P.-A. Loizeau" <p.-a.loizeau@gsi.de>
Date: Tue, 30 Apr 2024 13:53:28 +0200
Subject: [PATCH] Add option to disable GUI commands to NoFairMQ histo server
 binary

---
 services/histserv/app/Application.cxx    | 26 +++++++++++++-----------
 services/histserv/app/ProgramOptions.cxx |  2 ++
 services/histserv/app/ProgramOptions.h   |  4 ++++
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/services/histserv/app/Application.cxx b/services/histserv/app/Application.cxx
index a32af9d323..1668612b1a 100644
--- a/services/histserv/app/Application.cxx
+++ b/services/histserv/app/Application.cxx
@@ -69,18 +69,20 @@ Application::Application(ProgramOptions const& opt) : fOpt(opt)
   fServer->Register("/", fUiCmdActor.get());
   fServer->Hide("/UiCmdActor");
 
-  fServer->RegisterCommand("/Reset_Hist", "/UiCmdActor/->SetResetHistos()");
-  fServer->RegisterCommand("/Save_Hist", "/UiCmdActor/->SetSaveHistos()");
-  fServer->RegisterCommand("/Stop_Server", "/UiCmdActor/->SetServerStop()");
-
-  /*
-  fServer->RegisterCommand("/Reset_Hist", "this->ResetHistograms()");
-  fServer->RegisterCommand("/Save_Hist", "this->SaveHistograms()");
-  */
-
-  fServer->Restrict("/Reset_Hist", "allow=admin");
-  fServer->Restrict("/Save_Hist", "allow=admin");
-  fServer->Restrict("/Stop_Server", "allow=admin");
+  if (!fOpt.HideGuiCommands()) {
+    fServer->RegisterCommand("/Reset_Hist", "/UiCmdActor/->SetResetHistos()");
+    fServer->RegisterCommand("/Save_Hist", "/UiCmdActor/->SetSaveHistos()");
+    fServer->RegisterCommand("/Stop_Server", "/UiCmdActor/->SetServerStop()");
+
+    /*
+    fServer->RegisterCommand("/Reset_Hist", "this->ResetHistograms()");
+    fServer->RegisterCommand("/Save_Hist", "this->SaveHistograms()");
+    */
+
+    fServer->Restrict("/Reset_Hist", "allow=admin");
+    fServer->Restrict("/Save_Hist", "allow=admin");
+    fServer->Restrict("/Stop_Server", "allow=admin");
+  }
 
   // Provide signal handling for external interruptions
   // NOTE: SZh 02.04.2024:
diff --git a/services/histserv/app/ProgramOptions.cxx b/services/histserv/app/ProgramOptions.cxx
index 54522eaf28..94058260e6 100644
--- a/services/histserv/app/ProgramOptions.cxx
+++ b/services/histserv/app/ProgramOptions.cxx
@@ -44,6 +44,8 @@ namespace cbm::services::histserv
                "name of the output ROOT file with histograms backup");
     config_add("overwrite,w", po::bool_switch(&fOverwrite)->default_value(false),
                "allow to overwite an existing output file");
+    config_add("hideguicmds", po::bool_switch(&fHideGuiCommands)->default_value(false),
+               "allow to hides (disable) the GUI commands for Reset/Save/Close");
 
     // --- Allowed options
     po::options_description cmdline_options("Allowed options");
diff --git a/services/histserv/app/ProgramOptions.h b/services/histserv/app/ProgramOptions.h
index 47a913878b..7f8f1372d8 100644
--- a/services/histserv/app/ProgramOptions.h
+++ b/services/histserv/app/ProgramOptions.h
@@ -45,6 +45,9 @@ namespace cbm::services::histserv
     /** @brief Get overwrite option **/
     [[nodiscard]] bool Overwrite() const { return fOverwrite; }
 
+    /** @brief Get overwrite option **/
+    [[nodiscard]] bool HideGuiCommands() const { return fHideGuiCommands; }
+
     // /** @brief Get configuration file name (YAML format) **/
     // [[nodiscard]] const std::string& ConfigFile() const { return fConfig; }
 
@@ -59,6 +62,7 @@ namespace cbm::services::histserv
     uint32_t fuHttpServerPort    = 8080;                ///< HTTP port of the ROOT web server
     std::string fsHistoFileName  = "histos_dump.root";  ///< Output file name (ROOT format)
     bool fOverwrite              = false;               ///< Enable overwriting of existing output file
+    bool fHideGuiCommands        = false;               ///< Hides (disables) the GUI commands for Reset/Save/Close
     //std::string fConfig        = "";         ///< Configuration file name (YAML format)
   };
 
-- 
GitLab