29120557f4619eb83c8da29326ca179f5eba693f
[u/mrichter/AliRoot.git] / STORAGE / AliStorageAdministratorPanelMarkEvent.cxx
1 #include "AliStorageAdministratorPanelMarkEvent.h"
2 #include "AliStorageTypes.h"
3
4 #include <iostream>
5 #include "zmq.hpp"
6
7 #include <TGFrame.h>
8 #include <TGButton.h>
9
10 using namespace std;
11 using namespace zmq;
12
13 AliStorageAdministratorPanelMarkEvent *AliStorageAdministratorPanelMarkEvent::fInstance=0;
14
15 ClassImp(AliStorageAdministratorPanelMarkEvent);
16
17 #define WINDOWS_WIDTH 200
18 #define WINDOWS_HEIGHT 200
19
20 enum BUTTON{
21         BUTTON_CLOSE=1,
22         BUTTON_MARK     
23 };
24
25 enum TEXTENTRY{
26         TEXTENTRY_RUN=1,
27         TEXTENTRY_EVENT
28 };
29
30 AliStorageAdministratorPanelMarkEvent::AliStorageAdministratorPanelMarkEvent() :
31         TGMainFrame(gClient->GetRoot(), 400, 400),
32         fStatusLabel(0),
33         fRunNumberEntry(0),
34         fEventNumberEntry(0),
35         fServerSocket(0),
36         fEventManager(0)
37 {
38         fEventManager = new AliStorageEventManager();
39         InitWindow();
40 }
41
42 AliStorageAdministratorPanelMarkEvent::~AliStorageAdministratorPanelMarkEvent()
43 {
44         cout<<"ADMIN PANEL -- Mark Window descructor called";
45 //      if(fStatusLabel)delete fStatusLabel;
46 //      if(fRunNumberEntry)delete fRunNumberEntry;
47 //      if(fEventNumberEntry)delete fEventNumberEntry;
48         //if(fServerSocket)delete fServerSocket;
49 //      DestroyWindow();
50         cout<<" --- OK"<<endl;
51 }
52
53 AliStorageAdministratorPanelMarkEvent* AliStorageAdministratorPanelMarkEvent::GetInstance()
54 {
55         if(!fInstance){fInstance = new AliStorageAdministratorPanelMarkEvent();}
56         return fInstance;
57 }
58
59 void AliStorageAdministratorPanelMarkEvent::SetSocket(socket_t *socket)
60 {
61         fServerSocket = socket;
62 }
63
64 void AliStorageAdministratorPanelMarkEvent::InitWindow()
65 {
66         SetCleanup(kDeepCleanup);
67         
68         AddFrame(new TGLabel(this,"Run number:"),new TGLayoutHints(kLHintsLeft));
69
70         fRunNumberEntry = new TGNumberEntry(this,
71                                             0,
72                                             6,
73                                             TEXTENTRY_RUN,
74                                             TGNumberFormat::kNESInteger,
75                                             TGNumberFormat::kNEAPositive,
76                                             TGNumberFormat::kNELNoLimits);
77         AddFrame(fRunNumberEntry,new TGLayoutHints(kLHintsLeft));
78
79         AddFrame(new TGLabel(this,"Event number:"),new TGLayoutHints(kLHintsLeft));
80
81         fEventNumberEntry = new TGNumberEntry(this,
82                                               0,
83                                               6,
84                                               TEXTENTRY_EVENT,
85                                               TGNumberFormat::kNESInteger,
86                                               TGNumberFormat::kNEAPositive,
87                                               TGNumberFormat::kNELNoLimits);
88         AddFrame(fEventNumberEntry,new TGLayoutHints(kLHintsLeft));     
89
90         fStatusLabel = new TGLabel(this,"");
91         AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
92
93         AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
94                  new TGLayoutHints(kLHintsLeft));
95
96         AddFrame(new TGTextButton(this,"Mark event",BUTTON_MARK),
97                  new TGLayoutHints(kLHintsRight));
98
99         
100         SetWindowName("Mark Event");
101         MapSubwindows();
102         Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
103         MapWindow();
104 }
105
106
107
108
109 void AliStorageAdministratorPanelMarkEvent::onMarkButton()
110 {
111         int runNumber;
112         int eventNumber;
113
114         //get run and event number from TGNumberEntries
115         runNumber=fRunNumberEntry->GetIntNumber();
116         eventNumber=fEventNumberEntry->GetIntNumber();
117         
118         struct serverRequestStruct *requestMessage = new struct serverRequestStruct;
119         struct eventStruct mark;
120         mark.runNumber = runNumber;
121         mark.eventNumber = eventNumber;
122         requestMessage->messageType = REQUEST_MARK_EVENT;
123         requestMessage->event = mark;
124
125         fEventManager->Send(requestMessage,fServerSocket);
126
127         message_t *response = new message_t();
128         fServerSocket->recv(response);
129         char *result = (char*)response->data();
130         
131         if(!strcmp("true",result))
132         {
133                 fStatusLabel->SetText("Event marked");
134                 cout<<"ADMIN PANEL -- Event marked succesfully"<<endl;
135         }
136         else
137         {
138                 fStatusLabel->SetText("Couldn't mark this event");
139                 cout<<"ADMIN PANEL -- Could not matk event"<<endl;
140         }
141 }
142
143 void AliStorageAdministratorPanelMarkEvent::onCloseButton(){onExit();}
144 void AliStorageAdministratorPanelMarkEvent::CloseWindow(){onExit();}
145
146 void AliStorageAdministratorPanelMarkEvent::onExit()
147 {
148         cout<<"Quiting mark event";
149         if(fInstance){delete fInstance;fInstance=0;}
150         cout<<" -- OK"<<endl;
151 }
152
153 Bool_t AliStorageAdministratorPanelMarkEvent::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
154 {
155         switch (GET_MSG(msg))
156         {
157         case kC_COMMAND:
158                 switch (GET_SUBMSG(msg))
159                 {
160                 case kCM_BUTTON:
161                         switch(parm1)
162                         {
163                         case BUTTON_CLOSE:onCloseButton();break;
164                         case BUTTON_MARK:onMarkButton();break;
165                         default:break;
166                         }
167                         break;
168                 default:break;
169                 }
170                 break;
171         default:break;
172         }
173
174         return false;
175 }