00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TGButton.h"
00013 #include "TRootEmbeddedCanvas.h"
00014 #include "TGLayout.h"
00015 #include "TH2.h"
00016 #include "TCanvas.h"
00017 #include "TSocket.h"
00018 #include "TMessage.h"
00019 #include "RQ_OBJECT.h"
00020
00021
00022 class Spy {
00023
00024 RQ_OBJECT("Spy")
00025
00026 private:
00027 TGMainFrame *fMain;
00028 TRootEmbeddedCanvas *fCanvas;
00029 TGHorizontalFrame *fHorz;
00030 TGHorizontalFrame *fHorz2;
00031 TGLayoutHints *fLbut;
00032 TGLayoutHints *fLhorz;
00033 TGLayoutHints *fLcan;
00034 TGButton *fHpx;
00035 TGButton *fHpxpy;
00036 TGButton *fHprof;
00037 TGButton *fConnect;
00038 TGButton *fQuit;
00039 TSocket *fSock;
00040 TH1 *fHist;
00041
00042 public:
00043 Spy();
00044 ~Spy();
00045
00046 void Connect();
00047 void DoButton();
00048 };
00049
00050 void Spy::DoButton()
00051 {
00052
00053
00054 if (!fSock->IsValid())
00055 return;
00056
00057 TGButton *btn = (TGButton *) gTQSender;
00058 switch (btn->WidgetId()) {
00059 case 1:
00060 fSock->Send("get hpx");
00061 break;
00062 case 2:
00063 fSock->Send("get hpxpy");
00064 break;
00065 case 3:
00066 fSock->Send("get hprof");
00067 break;
00068 }
00069 TMessage *mess;
00070 if (fSock->Recv(mess) <= 0) {
00071 Error("Spy::DoButton", "error receiving message");
00072 return;
00073 }
00074
00075 if (fHist) delete fHist;
00076 if (mess->GetClass()->InheritsFrom(TH1::Class())) {
00077 fHist = (TH1*) mess->ReadObject(mess->GetClass());
00078 if (mess->GetClass()->InheritsFrom(TH2::Class()))
00079 fHist->Draw("cont");
00080 else
00081 fHist->Draw();
00082 fCanvas->GetCanvas()->Modified();
00083 fCanvas->GetCanvas()->Update();
00084 }
00085
00086 delete mess;
00087 }
00088
00089 void Spy::Connect()
00090 {
00091
00092 fSock = new TSocket("localhost", 9090);
00093 fConnect->SetState(kButtonDisabled);
00094 fHpx->SetState(kButtonUp);
00095 fHpxpy->SetState(kButtonUp);
00096 fHprof->SetState(kButtonUp);
00097 }
00098
00099 Spy::Spy()
00100 {
00101
00102 fMain = new TGMainFrame(0, 100, 100);
00103 fMain->SetCleanup(kDeepCleanup);
00104
00105
00106
00107 fCanvas = new TRootEmbeddedCanvas("Canvas", fMain, 600, 400);
00108 fLcan = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY,30,30,30,30);
00109 fMain->AddFrame(fCanvas, fLcan);
00110
00111
00112 fLhorz = new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 30);
00113 fHorz = new TGHorizontalFrame(fMain, 100, 100);
00114 fMain->AddFrame(fHorz, fLhorz);
00115
00116
00117
00118 fLbut = new TGLayoutHints(kLHintsCenterX, 10, 10, 0, 0);
00119 fHpx = new TGTextButton(fHorz, "Get hpx", 1);
00120 fHpx->SetState(kButtonDisabled);
00121 fHpx->Connect("Clicked()", "Spy", this, "DoButton()");
00122 fHorz->AddFrame(fHpx, fLbut);
00123 fHpxpy = new TGTextButton(fHorz, "Get hpxpy", 2);
00124 fHpxpy->SetState(kButtonDisabled);
00125 fHpxpy->Connect("Clicked()", "Spy", this, "DoButton()");
00126 fHorz->AddFrame(fHpxpy, fLbut);
00127 fHprof = new TGTextButton(fHorz, "Get hprof", 3);
00128 fHprof->SetState(kButtonDisabled);
00129 fHprof->Connect("Clicked()", "Spy", this, "DoButton()");
00130 fHorz->AddFrame(fHprof, fLbut);
00131
00132
00133 fHorz2 = new TGHorizontalFrame(fMain, 100, 100);
00134 fMain->AddFrame(fHorz2, fLhorz);
00135
00136
00137
00138 fConnect = new TGTextButton(fHorz2, "Connect");
00139 fConnect->Connect("Clicked()", "Spy", this, "Connect()");
00140 fHorz2->AddFrame(fConnect, fLbut);
00141 fQuit = new TGTextButton(fHorz2, "Quit");
00142 fQuit->SetCommand("gApplication->Terminate()");
00143 fHorz2->AddFrame(fQuit, fLbut);
00144
00145
00146
00147 fMain->SetWindowName("Spy on SpyServ");
00148 fMain->MapSubwindows();
00149 fMain->Resize(fMain->GetDefaultSize());
00150 fMain->MapWindow();
00151
00152 fHist = 0;
00153 }
00154
00155 Spy::~Spy()
00156 {
00157
00158
00159 delete fHist;
00160 delete fSock;
00161 delete fLbut;
00162 delete fLhorz;
00163 delete fLcan;
00164 delete fHpx;
00165 delete fHpxpy;
00166 delete fHprof;
00167 delete fConnect;
00168 delete fQuit;
00169 delete fHorz;
00170 delete fHorz2;
00171 delete fCanvas;
00172 delete fMain;
00173 }
00174
00175 void spy()
00176 {
00177 new Spy;
00178 }