Skip to content

TGCommandPlugin TTimer #8269

@ferdymercury

Description

@ferdymercury

Explain what you would like to see improved

The TGCommandPlugin has an internal TTimer that I think is redundant. I don't understand why the function CheckRemote needs to be checked every one second, which also calls frame->Layout(). Shouldn't it be better to just check in the beginning with a TTimer::SingleShot? Or if gROOT->GetApplication() changes during lifetime, with a signal/slot ?

fTimer = new TTimer(this, 1000);
fTimer->Reset();
fTimer->TurnOn();
...
////////////////////////////////////////////////////////////////////////////////
/// Handle timer event.

Bool_t TGCommandPlugin::HandleTimer(TTimer *t)
{
   if ((fTimer == 0) || (t != fTimer)) return kTRUE;
   CheckRemote("");
   return kTRUE;
}
void TGCommandPlugin::CheckRemote(const char * /*str*/)
{
   Pixel_t pxl;
   TApplication *app = gROOT->GetApplication();
   if (!app->InheritsFrom("TRint"))
      return;
   TString sPrompt = ((TRint*)app)->GetPrompt();
   Int_t end = sPrompt.Index(":root [", 0);
   if (end > 0 && end != kNPOS) {
      // remote session
      sPrompt.Remove(end);
      gClient->GetColorByName("#ff0000", pxl);
      fLabel->SetTextColor(pxl);
      fLabel->SetText(Form("Command (%s):", sPrompt.Data()));
   }
   else {
      // local session
      gClient->GetColorByName("#000000", pxl);
      fLabel->SetTextColor(pxl);
      fLabel->SetText("Command (local):");
   }
   fHf->Layout();
}

Alternatively, it would be nice to provide a function to stop the timer by the user, when performance is needed and you are sure that TApplication is always the same.

Setup

  1. ROOT from git master
  2. Ubuntu 20
  3. Self-built

Additional context

https://root-forum.cern.ch/t/trentrantrwlock-thread-lock-program-freezes/45116

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions