59d4e41593a3a971ef9cacb30ed5ba998073c3ce
[u/mrichter/AliRoot.git] / MONITOR / alistoragemanager / AliStorageAdministratorPanelSetStorageParams.cxx
1 #include "AliStorageAdministratorPanelSetStorageParams.h"
2 #include "AliStorageTypes.h"
3
4 #include <iostream>
5
6 #include <TGFrame.h>
7 #include <TGButton.h>
8
9 using namespace std;
10
11 AliStorageAdministratorPanelSetStorageParams *AliStorageAdministratorPanelSetStorageParams::fInstance=0;
12
13 ClassImp(AliStorageAdministratorPanelSetStorageParams);
14
15 #define WINDOWS_WIDTH 200
16 #define WINDOWS_HEIGHT 200
17
18 enum BUTTON{
19         BUTTON_CLOSE=1,
20         BUTTON_SET      
21 };
22
23 enum ENTRY{
24         ENTRY_STORAGE_SIZE=1,
25         ENTRY_OCCUPATION,
26         ENTRY_REMOVE,
27         ENTRY_EVENTS_CHUNK
28 };
29
30 AliStorageAdministratorPanelSetStorageParams::AliStorageAdministratorPanelSetStorageParams() :
31         TGMainFrame(gClient->GetRoot(), 400, 400),
32         fStatusLabel(0),
33         fMaxStorageSizeEntry(0),
34         fMaxOccupationEntry(0),
35         fRemoveEventsEntry(0),
36         fEventsInChunkEntry(0),
37         fClientSocket(CLIENT_COMMUNICATION_REQ),
38         fEventManager(0)
39 {
40         fEventManager = AliStorageEventManager::GetEventManagerInstance();
41         fEventManager->CreateSocket(fClientSocket);
42         InitWindow();
43 }
44
45 AliStorageAdministratorPanelSetStorageParams::~AliStorageAdministratorPanelSetStorageParams(){}
46
47 AliStorageAdministratorPanelSetStorageParams* AliStorageAdministratorPanelSetStorageParams::GetInstance()
48 {
49         if(!fInstance){fInstance = new AliStorageAdministratorPanelSetStorageParams();}
50         return fInstance;
51 }
52
53 void AliStorageAdministratorPanelSetStorageParams::Setup(storageSockets socket, int maxStorageSize, int maxOccupation, int removeEvents, int eventsInChunk)
54 {
55         fClientSocket = socket;
56         fMaxStorageSizeEntry->SetIntNumber(maxStorageSize);
57         fMaxOccupationEntry->SetIntNumber(maxOccupation);
58         fRemoveEventsEntry->SetIntNumber(removeEvents);
59         fEventsInChunkEntry->SetIntNumber(eventsInChunk);
60 }
61
62 void AliStorageAdministratorPanelSetStorageParams::InitWindow()
63 {
64         SetCleanup(kDeepCleanup);
65
66         // max storage size
67         AddFrame(new TGLabel(this,"Max storage size (MB):"),new TGLayoutHints(kLHintsLeft));
68
69         fMaxStorageSizeEntry = new TGNumberEntry(this,
70                                                      0,
71                                                      6,
72                                                      ENTRY_STORAGE_SIZE,
73                                                      TGNumberFormat::kNESInteger,
74                                                      TGNumberFormat::kNEAPositive,
75                                                      TGNumberFormat::kNELNoLimits);
76         AddFrame(fMaxStorageSizeEntry,new TGLayoutHints(kLHintsLeft));
77
78         // max occupation
79         AddFrame(new TGLabel(this,"Max occupation percent (%):"),new TGLayoutHints(kLHintsLeft));
80
81         fMaxOccupationEntry = new TGNumberEntry(this,
82                                                 0,
83                                                 6,
84                                                 ENTRY_OCCUPATION,
85                                                 TGNumberFormat::kNESInteger,
86                                                 TGNumberFormat::kNEAPositive,
87                                                 TGNumberFormat::kNELNoLimits);
88         AddFrame(fMaxOccupationEntry,new TGLayoutHints(kLHintsLeft));   
89
90         // remove events percantage
91         AddFrame(new TGLabel(this,"Remove events percentage (%):"),new TGLayoutHints(kLHintsLeft));
92
93         fRemoveEventsEntry = new TGNumberEntry(this,
94                                                 0,
95                                                 6,
96                                                 ENTRY_OCCUPATION,
97                                                 TGNumberFormat::kNESInteger,
98                                                 TGNumberFormat::kNEAPositive,
99                                                 TGNumberFormat::kNELNoLimits);
100         AddFrame(fRemoveEventsEntry,new TGLayoutHints(kLHintsLeft));
101
102         // events in chunk
103         AddFrame(new TGLabel(this,"Number of events in file:"),new TGLayoutHints(kLHintsLeft));
104
105         fEventsInChunkEntry = new TGNumberEntry(this,
106                                                 0,
107                                                 6,
108                                                 ENTRY_OCCUPATION,
109                                                 TGNumberFormat::kNESInteger,
110                                                 TGNumberFormat::kNEAPositive,
111                                                 TGNumberFormat::kNELNoLimits);
112         AddFrame(fEventsInChunkEntry,new TGLayoutHints(kLHintsLeft));   
113
114         // status label
115         fStatusLabel = new TGLabel(this,"");
116         AddFrame(fStatusLabel,new TGLayoutHints(kLHintsExpandX | kLHintsLeft));
117
118         AddFrame(new TGTextButton(this,"Close",BUTTON_CLOSE),
119                  new TGLayoutHints(kLHintsLeft));
120
121         AddFrame(new TGTextButton(this,"Set parameters",BUTTON_SET),
122                  new TGLayoutHints(kLHintsRight));
123
124         
125         SetWindowName("Set Storage Parameters");
126         MapSubwindows();
127         Resize(WINDOWS_WIDTH,WINDOWS_HEIGHT);
128         MapWindow();
129 }
130
131
132
133
134 void AliStorageAdministratorPanelSetStorageParams::onSetParamsButton()
135 {
136         
137         struct clientRequestStruct *requestMessage = new struct clientRequestStruct;    
138         //get run and event number from TGNumberEntries
139         requestMessage->messageType = REQUEST_SET_PARAMS;
140         requestMessage->maxStorageSize = fMaxStorageSizeEntry->GetIntNumber()*1000000;
141         requestMessage->maxOccupation = fMaxOccupationEntry->GetIntNumber();
142         requestMessage->removeEvents = fRemoveEventsEntry->GetIntNumber();
143         requestMessage->eventsInChunk = fEventsInChunkEntry->GetIntNumber();
144
145         fEventManager->Send(requestMessage,fClientSocket);
146         bool response = fEventManager->GetBool(fClientSocket);
147         
148         if(response)
149         {
150                 fStatusLabel->SetText("Params set");
151                 cout<<"ADMIN PANEL -- Params set succesfully"<<endl;
152         }
153         else
154         {
155                 fStatusLabel->SetText("Couldn't set params");
156                 cout<<"ADMIN PANEL -- Couldn't set params"<<endl;
157         }
158 }
159
160 void AliStorageAdministratorPanelSetStorageParams::onCloseButton(){onExit();}
161 void AliStorageAdministratorPanelSetStorageParams::CloseWindow(){onExit();}
162
163 void AliStorageAdministratorPanelSetStorageParams::onExit()
164 {
165         cout<<"Quiting set storage params";
166         if(fInstance){delete fInstance;fInstance=0;}
167         cout<<" -- OK"<<endl;
168 }
169
170 Bool_t AliStorageAdministratorPanelSetStorageParams::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
171 {
172         switch (GET_MSG(msg))
173         {
174         case kC_COMMAND:
175                 switch (GET_SUBMSG(msg))
176                 {
177                 case kCM_BUTTON:
178                         switch(parm1)
179                         {
180                         case BUTTON_CLOSE:onCloseButton();break;
181                         case BUTTON_SET:onSetParamsButton();break;
182                         default:break;
183                         }
184                         break;
185                 default:break;
186                 }
187                 break;
188         default:break;
189         }
190
191         return false;
192 }