2
#include <FL/Fl_Tabs.H>
3
#include <FL/Fl_Check_Button.H>
4
#include <FL/Fl_Button.H>
5
#include <FL/Fl_Input_Choice.H>
6
#include <FL/Fl_Choice.H>
7
#include <FL/Fl_Browser.H>
8
#include <FL/Fl_Scroll.H>
11
#include "OnelabWindow.h"
12
#include "OnelabDatabase.h"
13
#include "OnelabServer.h"
15
#include "paletteWindow.h"
19
void onelab_listen_tcp_cb(Fl_Widget *w, void *data);
20
void onelab_listen_unix_cb(Fl_Widget *w, void *data);
22
void onelab_listen_udt_cb(Fl_Widget *w, void *data);
24
void onelab_connect_remote_server_cb(Fl_Widget *w, void *data);
26
onelabWindow::onelabWindow(int deltaFontSize)
28
FL_NORMAL_SIZE -= deltaFontSize;
30
int width = 34 * FL_NORMAL_SIZE + WB;
31
int height = 12 * BH + 4 * WB;
33
win = new paletteWindow(width, height, CTX::instance()->nonModalWindows ? true : false);
34
win->box(GMSH_WINDOW_BOX);
35
win->label("ONELAB2");
37
Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB);
39
Fl_Group *o = new Fl_Group(
40
WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (server)");
41
_listenOnUNIX = new Fl_Check_Button(2*WB, 2*WB + 1*BH, width-2*WB, BH, "Listen on UNIX socket");
42
_sockUNIX = new Fl_Input(2*WB, 2*WB + 2*BH, width/2-2*WB, BH, "UNIX base socket name");
43
_listenOnUNIX->callback(onelab_listen_unix_cb, _sockUNIX);
44
_sockUNIX->align(FL_ALIGN_RIGHT);
45
_listenOnTCP = new Fl_Check_Button(2*WB, 2*WB + 3*BH, width-2*WB, BH, "Listen on TCP socket");
46
_sockTCP = new Fl_Input(2*WB, 2*WB + 4*BH, width/2-2*WB, BH, "TCP port (0 to let the system choose)");
47
_listenOnTCP->callback(onelab_listen_tcp_cb, _sockTCP);
48
_sockTCP->align(FL_ALIGN_RIGHT);
50
_listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket");
51
_sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)");
52
_listenOnUDT->callback(onelab_listen_udt_cb, _sockUDT);
53
_sockUDT->align(FL_ALIGN_RIGHT);
55
_listenOnUDT = new Fl_Check_Button(2*WB, 2*WB + 5*BH, width-2*WB, BH, "Listen on UDT (UDP) socket");
56
_sockUDT = new Fl_Input(2*WB, 2*WB + 6*BH, width/2-2*WB, BH, "UDP port (0 to let the system choose)");
57
_sockUDT->align(FL_ALIGN_RIGHT);
63
Fl_Group *o = new Fl_Group(
64
0, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Clients (server)");
65
_solvers = new Fl_Choice(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Solver");
66
_solvers->align(FL_ALIGN_RIGHT);
68
_clients = new Fl_Browser(2*WB, 2*WB + 3*BH, width/2-2*WB, 5*BH, "Connected clients");
69
_clients->align(FL_ALIGN_RIGHT);
73
Fl_Group *o = new Fl_Group(
74
WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "Network (client)");
75
_remoteServer = new Fl_Input(2*WB, 2*WB + 1*BH, width/2-2*WB, BH, "Server address (IPv4:port)");
76
_remoteServer->align(FL_ALIGN_RIGHT);
77
_connectRemoteServer = new Fl_Button(2*WB, 3*WB + 2*BH, width/2-2*WB, BH, "Connect");
78
_connectRemoteServer->callback(onelab_connect_remote_server_cb, _remoteServer);
82
void onelabWindow::refresh(){
85
refreshRemoteServer();
88
void onelabWindow::refreshServers()
90
if(OnelabDatabase::instance()->isNetworkClient()) {
91
_listenOnUNIX->deactivate();
92
_listenOnTCP->deactivate();
93
_listenOnUDT->deactivate();
94
_sockUNIX->deactivate();
95
_sockUDT->deactivate();
96
_sockTCP->deactivate();
100
_sockUNIX->value(CTX::instance()->onelab.unixSock.c_str());
101
_sockTCP->value(CTX::instance()->onelab.tcpSock.c_str());
103
_sockUDT->value(CTX::instance()->onelab.udtSock.c_str());
105
_sockUDT->value("Not compiled with UDT library");
107
if(CTX::instance()->onelab.unixConnected) {
108
_listenOnUNIX->value(1);
109
_sockUNIX->deactivate();
112
_listenOnUNIX->value(0);
113
_sockUNIX->activate();
116
if(CTX::instance()->onelab.tcpConnected) {
117
_listenOnTCP->value(1);
118
_sockTCP->deactivate();
121
_listenOnTCP->value(0);
122
_sockTCP->activate();
125
if(CTX::instance()->onelab.udtConnected) {
126
_listenOnUDT->value(1);
127
_sockUDT->deactivate();
130
_listenOnUDT->value(0);
131
_sockUDT->activate();
135
void onelabWindow::rebuildSolverList()
138
for(int i = 0; i < NUM_SOLVERS; i++){
139
if(opt_solver_name(i, GMSH_GET, "").size())
140
_solvers->add(opt_solver_name(i, GMSH_GET, "").c_str());
142
if(CTX::instance()->solverToRun >= 0) _solvers->value(CTX::instance()->solverToRun);
145
void onelabWindow::refreshRemoteServer()
147
if(OnelabDatabase::instance()->isNetworkClient()) {
148
_remoteServer->value();
149
//TODO size_t colon = sockname.find(':');
150
//if(colon != std::string::npos) {
151
// address = ip4_inet_pton(sockname.substr(0,colon).c_str());
152
// port = atoi(sockname.substr(colon+1).c_str());
154
//GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient(address, port, name);
156
// Error("Unable to connect ONELAB server (%s)", sockname.c_str());
162
void onelab_listen_tcp_cb(Fl_Widget *w, void *data)
164
Fl_Check_Button *checkbutton = (Fl_Check_Button *)w;
165
Fl_Input *sockTCP = (Fl_Input *)data;
166
if(checkbutton->value() == 1) {
167
sockTCP->deactivate();
168
CTX::instance()->onelab.tcpSock = sockTCP->value();
169
std::size_t colon = CTX::instance()->onelab.tcpSock.find(":");
170
OnelabServer::instance()->listenOnTcp(
171
ip4_inet_pton(CTX::instance()->onelab.tcpSock.substr(0, colon).c_str()),
172
atoi(CTX::instance()->onelab.tcpSock.substr(colon+1, CTX::instance()->onelab.tcpSock.size()-colon-1).c_str()));
176
OnelabServer::instance()->stopTcp();
180
void onelab_listen_unix_cb(Fl_Widget *w, void *data)
182
Fl_Check_Button *checkbutton = (Fl_Check_Button *)w;
183
Fl_Input *sockUNIX = (Fl_Input *)data;
184
if(checkbutton->value() == 1) {
185
sockUNIX->deactivate();
186
CTX::instance()->onelab.unixSock = sockUNIX->value();
187
std::size_t colon = CTX::instance()->onelab.unixSock.find(":");
188
std::ostringstream tmp;
189
tmp << CTX::instance()->homeDir << CTX::instance()->onelab.unixSock;
190
OnelabServer::instance()->listenOnUnix(tmp.str().c_str());
193
sockUNIX->activate();
194
OnelabServer::instance()->stopUnix();
199
void onelab_listen_udt_cb(Fl_Widget *w, void *data)
201
Fl_Check_Button *checkbutton = (Fl_Check_Button *)w;
202
Fl_Input *sockUDT = (Fl_Input *)data;
203
if(checkbutton->value() == 1) {
204
sockUDT->deactivate();
205
CTX::instance()->onelab.udtSock = sockUDT->value();
206
std::size_t colon = CTX::instance()->onelab.udtSock.find(":");
207
OnelabServer::instance()->listenOnTcp(
208
ip4_inet_pton(CTX::instance()->onelab.udtSock.substr(0, colon).c_str()),
209
atoi(CTX::instance()->onelab.udtSock.substr(colon+1, CTX::instance()->onelab.udtSock.size()-colon-1).c_str()));
213
OnelabServer::instance()->stopUdt();
218
void onelab2_cb(Fl_Widget *w, void *data)
220
FlGui::instance()->onelab2->refresh();
221
FlGui::instance()->onelab2->win->show();
224
void onelab_connect_remote_server_cb(Fl_Widget *w, void *data)
226
Fl_Input *serverAddr = (Fl_Input *)data;
227
std::string address = serverAddr->value();
228
std::size_t colon = address.find(":");
229
GmshNetworkClient *c = OnelabDatabase::instance()->useAsNetworkClient(
230
ip4_inet_pton(address.substr(0, colon).c_str()),
231
atoi(address.substr(colon+1, address.size()-colon-1).c_str()),
234
Msg::Error("Unable to connect ONELAB server (%s)", address.c_str());
237
else if(FlGui::available()) // FIXME
238
c->setCallback(FlGui::instance()->onelab);