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