Skip to content
Snippets Groups Projects
Commit 91c0f025 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

deactive command buttons in solver UI while solver is running

parent 002c38f3
No related branches found
No related tags found
No related merge requests found
......@@ -2199,7 +2199,7 @@ static void view_applybgmesh_cb(Fl_Widget *w, void *data)
}
}
#define TEST_SERVER
//#define TEST_SERVER
// The static menus (we cannot use the 'g', 'm' 's' and 'p' mnemonics
// since they are already defined as global shortcuts)
......@@ -2484,7 +2484,7 @@ contextItem menu_mesh[] = {
{"3D", (Fl_Callback *)mesh_3d_cb} ,
{"First order", (Fl_Callback *)mesh_degree_cb, (void*)1 } ,
{"Second order", (Fl_Callback *)mesh_degree_cb, (void*)2 } ,
{"Refine", (Fl_Callback *)mesh_refine_cb} ,
{"Refine by splitting", (Fl_Callback *)mesh_refine_cb} ,
{"Optimize", (Fl_Callback *)mesh_optimize_cb} ,
#if defined(HAVE_NETGEN)
{"Optimize (Netgen)", (Fl_Callback *)mesh_optimize_netgen_cb} ,
......
......@@ -91,6 +91,21 @@ void GmshRemote::run(std::string args)
return;
}
// find solver num
int solverNum = 0;
for(std::map<int, GmshRemote*>::iterator it = _all.begin();
it != _all.end(); it++){
if(this == it->second) break;
solverNum++;
}
// make command buttons inactive while running
if(solverNum >= 0 && solverNum < NB_SOLVER_MAX){
for(unsigned int i = 0; i < buttonName.size(); i++)
if(buttonName[i].size())
FlGui::instance()->solver[solverNum]->command[i]->deactivate();
}
_pid = 0;
_server = 0;
FlGmshServer *server = new FlGmshServer(this);
......@@ -118,6 +133,10 @@ void GmshRemote::run(std::string args)
if(sock < 0){
server->Shutdown();
delete server;
// reactivate buttons
for(unsigned int i = 0; i < buttonName.size(); i++)
if(buttonName[i].size())
FlGui::instance()->solver[solverNum]->command[i]->activate();
return;
}
......@@ -214,24 +233,22 @@ void GmshRemote::run(std::string args)
}
}
if(solverNum >= 0 && solverNum < NB_SOLVER_MAX){
// some options have been changed: refill the menus
if(!initOption[0] || !initOption[1] || !initOption[2] || !initOption[3] ||
!initOption[4]){ // some options have been changed
// find solver num
int num = 0;
for(std::map<int, GmshRemote*>::iterator it = _all.begin();
it != _all.end(); it++){
if(this == it->second) break;
num++;
}
if(num >= 0 && num < NB_SOLVER_MAX){
!initOption[4]){
for(unsigned int i = 0; i < optionName.size(); i++) {
if(optionName[i].empty()) break;
FlGui::instance()->solver[num]->choice[i]->clear();
FlGui::instance()->solver[solverNum]->choice[i]->clear();
for(unsigned int j = 0; j < optionValue[i].size(); j++)
FlGui::instance()->solver[num]->choice[i]->add(optionValue[i][j].c_str());
FlGui::instance()->solver[num]->choice[i]->value(0);
FlGui::instance()->solver[solverNum]->choice[i]->add(optionValue[i][j].c_str());
FlGui::instance()->solver[solverNum]->choice[i]->value(0);
}
}
// reactivate buttons
for(unsigned int i = 0; i < buttonName.size(); i++)
if(buttonName[i].size())
FlGui::instance()->solver[solverNum]->command[i]->activate();
}
_server = 0;
......
This diff is collapsed.
......@@ -81,87 +81,88 @@
tToday = 297,
tSyncModel = 298,
tCreateTopology = 299,
tPoint = 300,
tCircle = 301,
tEllipse = 302,
tLine = 303,
tSphere = 304,
tPolarSphere = 305,
tSurface = 306,
tSpline = 307,
tVolume = 308,
tCharacteristic = 309,
tLength = 310,
tParametric = 311,
tElliptic = 312,
tPlane = 313,
tRuled = 314,
tTransfinite = 315,
tComplex = 316,
tPhysical = 317,
tCompound = 318,
tUsing = 319,
tPlugin = 320,
tDegenerated = 321,
tOCCShape = 322,
tRotate = 323,
tTranslate = 324,
tSymmetry = 325,
tDilate = 326,
tExtrude = 327,
tLevelset = 328,
tLoop = 329,
tRecombine = 330,
tSmoother = 331,
tSplit = 332,
tDelete = 333,
tCoherence = 334,
tIntersect = 335,
tLayers = 336,
tHole = 337,
tAlias = 338,
tAliasWithOptions = 339,
tText2D = 340,
tText3D = 341,
tInterpolationScheme = 342,
tTime = 343,
tCombine = 344,
tBSpline = 345,
tBezier = 346,
tNurbs = 347,
tNurbsOrder = 348,
tNurbsKnots = 349,
tColor = 350,
tColorTable = 351,
tFor = 352,
tIn = 353,
tEndFor = 354,
tIf = 355,
tEndIf = 356,
tExit = 357,
tField = 358,
tReturn = 359,
tCall = 360,
tFunction = 361,
tShow = 362,
tHide = 363,
tGetValue = 364,
tGMSH_MAJOR_VERSION = 365,
tGMSH_MINOR_VERSION = 366,
tGMSH_PATCH_VERSION = 367,
tAFFECTDIVIDE = 368,
tAFFECTTIMES = 369,
tAFFECTMINUS = 370,
tAFFECTPLUS = 371,
tOR = 372,
tAND = 373,
tNOTEQUAL = 374,
tEQUAL = 375,
tGREATEROREQUAL = 376,
tLESSOREQUAL = 377,
UNARYPREC = 378,
tMINUSMINUS = 379,
tPLUSPLUS = 380
tDistanceFunction = 300,
tPoint = 301,
tCircle = 302,
tEllipse = 303,
tLine = 304,
tSphere = 305,
tPolarSphere = 306,
tSurface = 307,
tSpline = 308,
tVolume = 309,
tCharacteristic = 310,
tLength = 311,
tParametric = 312,
tElliptic = 313,
tPlane = 314,
tRuled = 315,
tTransfinite = 316,
tComplex = 317,
tPhysical = 318,
tCompound = 319,
tUsing = 320,
tPlugin = 321,
tDegenerated = 322,
tOCCShape = 323,
tRotate = 324,
tTranslate = 325,
tSymmetry = 326,
tDilate = 327,
tExtrude = 328,
tLevelset = 329,
tLoop = 330,
tRecombine = 331,
tSmoother = 332,
tSplit = 333,
tDelete = 334,
tCoherence = 335,
tIntersect = 336,
tLayers = 337,
tHole = 338,
tAlias = 339,
tAliasWithOptions = 340,
tText2D = 341,
tText3D = 342,
tInterpolationScheme = 343,
tTime = 344,
tCombine = 345,
tBSpline = 346,
tBezier = 347,
tNurbs = 348,
tNurbsOrder = 349,
tNurbsKnots = 350,
tColor = 351,
tColorTable = 352,
tFor = 353,
tIn = 354,
tEndFor = 355,
tIf = 356,
tEndIf = 357,
tExit = 358,
tField = 359,
tReturn = 360,
tCall = 361,
tFunction = 362,
tShow = 363,
tHide = 364,
tGetValue = 365,
tGMSH_MAJOR_VERSION = 366,
tGMSH_MINOR_VERSION = 367,
tGMSH_PATCH_VERSION = 368,
tAFFECTDIVIDE = 369,
tAFFECTTIMES = 370,
tAFFECTMINUS = 371,
tAFFECTPLUS = 372,
tOR = 373,
tAND = 374,
tNOTEQUAL = 375,
tEQUAL = 376,
tGREATEROREQUAL = 377,
tLESSOREQUAL = 378,
UNARYPREC = 379,
tMINUSMINUS = 380,
tPLUSPLUS = 381
};
#endif
/* Tokens. */
......@@ -207,87 +208,88 @@
#define tToday 297
#define tSyncModel 298
#define tCreateTopology 299
#define tPoint 300
#define tCircle 301
#define tEllipse 302
#define tLine 303
#define tSphere 304
#define tPolarSphere 305
#define tSurface 306
#define tSpline 307
#define tVolume 308
#define tCharacteristic 309
#define tLength 310
#define tParametric 311
#define tElliptic 312
#define tPlane 313
#define tRuled 314
#define tTransfinite 315
#define tComplex 316
#define tPhysical 317
#define tCompound 318
#define tUsing 319
#define tPlugin 320
#define tDegenerated 321
#define tOCCShape 322
#define tRotate 323
#define tTranslate 324
#define tSymmetry 325
#define tDilate 326
#define tExtrude 327
#define tLevelset 328
#define tLoop 329
#define tRecombine 330
#define tSmoother 331
#define tSplit 332
#define tDelete 333
#define tCoherence 334
#define tIntersect 335
#define tLayers 336
#define tHole 337
#define tAlias 338
#define tAliasWithOptions 339
#define tText2D 340
#define tText3D 341
#define tInterpolationScheme 342
#define tTime 343
#define tCombine 344
#define tBSpline 345
#define tBezier 346
#define tNurbs 347
#define tNurbsOrder 348
#define tNurbsKnots 349
#define tColor 350
#define tColorTable 351
#define tFor 352
#define tIn 353
#define tEndFor 354
#define tIf 355
#define tEndIf 356
#define tExit 357
#define tField 358
#define tReturn 359
#define tCall 360
#define tFunction 361
#define tShow 362
#define tHide 363
#define tGetValue 364
#define tGMSH_MAJOR_VERSION 365
#define tGMSH_MINOR_VERSION 366
#define tGMSH_PATCH_VERSION 367
#define tAFFECTDIVIDE 368
#define tAFFECTTIMES 369
#define tAFFECTMINUS 370
#define tAFFECTPLUS 371
#define tOR 372
#define tAND 373
#define tNOTEQUAL 374
#define tEQUAL 375
#define tGREATEROREQUAL 376
#define tLESSOREQUAL 377
#define UNARYPREC 378
#define tMINUSMINUS 379
#define tPLUSPLUS 380
#define tDistanceFunction 300
#define tPoint 301
#define tCircle 302
#define tEllipse 303
#define tLine 304
#define tSphere 305
#define tPolarSphere 306
#define tSurface 307
#define tSpline 308
#define tVolume 309
#define tCharacteristic 310
#define tLength 311
#define tParametric 312
#define tElliptic 313
#define tPlane 314
#define tRuled 315
#define tTransfinite 316
#define tComplex 317
#define tPhysical 318
#define tCompound 319
#define tUsing 320
#define tPlugin 321
#define tDegenerated 322
#define tOCCShape 323
#define tRotate 324
#define tTranslate 325
#define tSymmetry 326
#define tDilate 327
#define tExtrude 328
#define tLevelset 329
#define tLoop 330
#define tRecombine 331
#define tSmoother 332
#define tSplit 333
#define tDelete 334
#define tCoherence 335
#define tIntersect 336
#define tLayers 337
#define tHole 338
#define tAlias 339
#define tAliasWithOptions 340
#define tText2D 341
#define tText3D 342
#define tInterpolationScheme 343
#define tTime 344
#define tCombine 345
#define tBSpline 346
#define tBezier 347
#define tNurbs 348
#define tNurbsOrder 349
#define tNurbsKnots 350
#define tColor 351
#define tColorTable 352
#define tFor 353
#define tIn 354
#define tEndFor 355
#define tIf 356
#define tEndIf 357
#define tExit 358
#define tField 359
#define tReturn 360
#define tCall 361
#define tFunction 362
#define tShow 363
#define tHide 364
#define tGetValue 365
#define tGMSH_MAJOR_VERSION 366
#define tGMSH_MINOR_VERSION 367
#define tGMSH_PATCH_VERSION 368
#define tAFFECTDIVIDE 369
#define tAFFECTTIMES 370
#define tAFFECTMINUS 371
#define tAFFECTPLUS 372
#define tOR 373
#define tAND 374
#define tNOTEQUAL 375
#define tEQUAL 376
#define tGREATEROREQUAL 377
#define tLESSOREQUAL 378
#define UNARYPREC 379
#define tMINUSMINUS 380
#define tPLUSPLUS 381
......@@ -305,7 +307,7 @@ typedef union YYSTYPE
List_T *l;
}
/* Line 1529 of yacc.c. */
#line 309 "Gmsh.tab.hpp"
#line 311 "Gmsh.tab.hpp"
YYSTYPE;
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
......
......@@ -6,10 +6,29 @@
/* A lexical scanner generated by flex */
#define yy_create_buffer gmsh_yy_create_buffer
#define yy_delete_buffer gmsh_yy_delete_buffer
#define yy_flex_debug gmsh_yy_flex_debug
#define yy_init_buffer gmsh_yy_init_buffer
#define yy_flush_buffer gmsh_yy_flush_buffer
#define yy_load_buffer_state gmsh_yy_load_buffer_state
#define yy_switch_to_buffer gmsh_yy_switch_to_buffer
#define yyin gmsh_yyin
#define yyleng gmsh_yyleng
#define yylex gmsh_yylex
#define yylineno gmsh_yylineno
#define yyout gmsh_yyout
#define yyrestart gmsh_yyrestart
#define yytext gmsh_yytext
#define yywrap gmsh_yywrap
#define yyalloc gmsh_yyalloc
#define yyrealloc gmsh_yyrealloc
#define yyfree gmsh_yyfree
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 33
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
......@@ -31,7 +50,7 @@
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
#if __STDC_VERSION__ >= 199901L
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
* if you want the limit (max/min) macros for int types.
......@@ -94,11 +113,12 @@ typedef unsigned int flex_uint32_t;
#else /* ! __cplusplus */
#if __STDC__
/* C99 requires __STDC__ to be defined as 1. */
#if defined (__STDC__)
#define YY_USE_CONST
#endif /* __STDC__ */
#endif /* defined (__STDC__) */
#endif /* ! __cplusplus */
#ifdef YY_USE_CONST
......@@ -152,7 +172,12 @@ typedef unsigned int flex_uint32_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
extern int gmsh_yyleng;
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
extern yy_size_t gmsh_yyleng;
extern FILE *gmsh_yyin, *gmsh_yyout;
......@@ -178,16 +203,6 @@ extern FILE *gmsh_yyin, *gmsh_yyout;
#define unput(c) yyunput( c, (yytext_ptr) )
/* The following is because we cannot portably get our hands on size_t
* (without autoconf's help, which isn't available because we want
* flex-generated scanners to compile on their own).
*/
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef unsigned int yy_size_t;
#endif
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
......@@ -205,7 +220,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
......@@ -275,8 +290,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
/* yy_hold_char holds the character lost when gmsh_yytext is formed. */
static char yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
int gmsh_yyleng;
static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
yy_size_t gmsh_yyleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
......@@ -304,7 +319,7 @@ static void gmsh_yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
YY_BUFFER_STATE gmsh_yy_scan_buffer (char *base,yy_size_t size );
YY_BUFFER_STATE gmsh_yy_scan_string (yyconst char *yy_str );
YY_BUFFER_STATE gmsh_yy_scan_bytes (yyconst char *bytes,int len );
YY_BUFFER_STATE gmsh_yy_scan_bytes (yyconst char *bytes,yy_size_t len );
void *gmsh_yyalloc (yy_size_t );
void *gmsh_yyrealloc (void *,yy_size_t );
......@@ -883,7 +898,7 @@ void skipline(void);
#define YY_NO_UNISTD_H
#endif
#line 887 "Gmsh.yy.cpp"
#line 902 "Gmsh.yy.cpp"
#define INITIAL 0
......@@ -901,6 +916,35 @@ void skipline(void);
static int yy_init_globals (void );
/* Accessor methods to globals.
These are made visible to non-reentrant scanners for convenience. */
int gmsh_yylex_destroy (void );
int gmsh_yyget_debug (void );
void gmsh_yyset_debug (int debug_flag );
YY_EXTRA_TYPE gmsh_yyget_extra (void );
void gmsh_yyset_extra (YY_EXTRA_TYPE user_defined );
FILE *gmsh_yyget_in (void );
void gmsh_yyset_in (FILE * in_str );
FILE *gmsh_yyget_out (void );
void gmsh_yyset_out (FILE * out_str );
yy_size_t gmsh_yyget_leng (void );
char *gmsh_yyget_text (void );
int gmsh_yyget_lineno (void );
void gmsh_yyset_lineno (int line_number );
/* Macros after this point can all be overridden by user definitions in
* section 1.
*/
......@@ -943,7 +987,7 @@ static int input (void );
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO (void) fwrite( gmsh_yytext, gmsh_yyleng, 1, gmsh_yyout )
#define ECHO fwrite( gmsh_yytext, gmsh_yyleng, 1, gmsh_yyout )
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
......@@ -954,7 +998,7 @@ static int input (void );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
size_t n; \
yy_size_t n; \
for ( n = 0; n < max_size && \
(c = getc( gmsh_yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
......@@ -1039,7 +1083,7 @@ YY_DECL
#line 49 "Gmsh.l"
#line 1043 "Gmsh.yy.cpp"
#line 1087 "Gmsh.yy.cpp"
if ( !(yy_init) )
{
......@@ -1849,7 +1893,7 @@ YY_RULE_SETUP
#line 221 "Gmsh.l"
ECHO;
YY_BREAK
#line 1853 "Gmsh.yy.cpp"
#line 1897 "Gmsh.yy.cpp"
case YY_STATE_EOF(INITIAL):
yyterminate();
......@@ -2035,7 +2079,7 @@ static int yy_get_next_buffer (void)
else
{
int num_to_read =
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
......@@ -2049,7 +2093,7 @@ static int yy_get_next_buffer (void)
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
......@@ -2104,6 +2148,14 @@ static int yy_get_next_buffer (void)
else
ret_val = EOB_ACT_CONTINUE_SCAN;
if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) gmsh_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
}
(yy_n_chars) += number_to_move;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
......@@ -2182,7 +2234,7 @@ static int yy_get_next_buffer (void)
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
register int number_to_move = (yy_n_chars) + 2;
register yy_size_t number_to_move = (yy_n_chars) + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
......@@ -2231,7 +2283,7 @@ static int yy_get_next_buffer (void)
else
{ /* need more input */
int offset = (yy_c_buf_p) - (yytext_ptr);
yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) )
......@@ -2507,7 +2559,7 @@ void gmsh_yypop_buffer_state (void)
*/
static void gmsh_yyensure_buffer_stack (void)
{
int num_to_alloc;
yy_size_t num_to_alloc;
if (!(yy_buffer_stack)) {
......@@ -2519,6 +2571,8 @@ static void gmsh_yyensure_buffer_stack (void)
(yy_buffer_stack) = (struct yy_buffer_state**)gmsh_yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
);
if ( ! (yy_buffer_stack) )
YY_FATAL_ERROR( "out of dynamic memory in gmsh_yyensure_buffer_stack()" );
memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
......@@ -2537,6 +2591,8 @@ static void gmsh_yyensure_buffer_stack (void)
((yy_buffer_stack),
num_to_alloc * sizeof(struct yy_buffer_state*)
);
if ( ! (yy_buffer_stack) )
YY_FATAL_ERROR( "out of dynamic memory in gmsh_yyensure_buffer_stack()" );
/* zero only the new slots.*/
memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
......@@ -2581,7 +2637,7 @@ YY_BUFFER_STATE gmsh_yy_scan_buffer (char * base, yy_size_t size )
/** Setup the input buffer state to scan a string. The next call to gmsh_yylex() will
* scan from a @e copy of @a str.
* @param str a NUL-terminated string to scan
* @param yystr a NUL-terminated string to scan
*
* @return the newly allocated buffer state object.
* @note If you want to scan bytes that may contain NUL values, then use
......@@ -2600,12 +2656,11 @@ YY_BUFFER_STATE gmsh_yy_scan_string (yyconst char * yystr )
*
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE gmsh_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len )
YY_BUFFER_STATE gmsh_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
int i;
yy_size_t n, i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
......@@ -2687,7 +2742,7 @@ FILE *gmsh_yyget_out (void)
/** Get the length of the current token.
*
*/
int gmsh_yyget_leng (void)
yy_size_t gmsh_yyget_leng (void)
{
return gmsh_yyleng;
}
......
......@@ -6,6 +6,7 @@
#ifndef _GMSH_SOCKET_H_
#define _GMSH_SOCKET_H_
//#include "GmshConfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
......@@ -39,20 +40,21 @@ class GmshSocket{
// receive data from a machine with a different byte ordering, and
// we swap the bytes in the payload)
enum MessageType{
CLIENT_START = 1,
CLIENT_STOP = 2,
CLIENT_INFO = 10,
CLIENT_WARNING = 11,
CLIENT_ERROR = 12,
CLIENT_PROGRESS = 13,
CLIENT_MERGE_FILE = 20, // old name: CLIENT_VIEW
CLIENT_PARSE_STRING = 21,
CLIENT_SPEED_TEST = 30,
CLIENT_OPTION_1 = 100,
CLIENT_OPTION_2 = 101,
CLIENT_OPTION_3 = 102,
CLIENT_OPTION_4 = 103,
CLIENT_OPTION_5 = 104};
GMSH_START = 1,
GMSH_STOP = 2,
GMSH_INFO = 10,
GMSH_WARNING = 11,
GMSH_ERROR = 12,
GMSH_PROGRESS = 13,
GMSH_MERGE_FILE = 20,
GMSH_PARSE_STRING = 21,
GMSH_VERTEX_ARRAY = 22,
GMSH_SPEED_TEST = 30,
GMSH_OPTION_1 = 100,
GMSH_OPTION_2 = 101,
GMSH_OPTION_3 = 102,
GMSH_OPTION_4 = 103,
GMSH_OPTION_5 = 104};
protected:
// the socket descriptor
int _sock;
......@@ -78,8 +80,8 @@ class GmshSocket{
int remaining = bytes;
do {
int len = recv(_sock, buf + sofar, remaining, 0);
if(len <= 0)
return 0;
if(len == 0) break; // we're done!
if(len < 0) return -1; // error
sofar += len;
remaining -= len;
} while(remaining > 0);
......@@ -124,26 +126,43 @@ class GmshSocket{
// seconds and microseconds == 0 we check for available data and
// return immediately, i.e., we do polling). Returns 0 when data is
// available.
int Select(int socket, int seconds, int microseconds)
int Select(int seconds, int microseconds, int socket=-1)
{
int s = (socket < 0) ? _sock : socket;
struct timeval tv;
tv.tv_sec = seconds;
tv.tv_usec = microseconds;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(socket, &rfds);
FD_SET(s, &rfds);
// select checks all IO descriptors between 0 and its first arg,
// minus 1... hence the +1 below
return select(socket + 1, &rfds, NULL, NULL, &tv);
return select(s + 1, &rfds, NULL, NULL, &tv);
}
void SendString(int type, const char *str)
void SendMessage(int type, int length, const void *msg)
{
// send header (type + length)
_SendData(&type, sizeof(int));
int len = strlen(str);
_SendData(&len, sizeof(int));
_SendData(&length, sizeof(int));
// send body
_SendData(str, len);
_SendData(msg, length);
}
void SendString(int type, const char *str)
{
SendMessage(type, strlen(str), str);
}
void Info(const char *str){ SendString(GMSH_INFO, str); }
void Warning(const char *str){ SendString(GMSH_WARNING, str); }
void Error(const char *str){ SendString(GMSH_ERROR, str); }
void Progress(const char *str){ SendString(GMSH_PROGRESS, str); }
void MergeFile(const char *str){ SendString(GMSH_MERGE_FILE, str); }
void ParseString(const char *str){ SendString(GMSH_PARSE_STRING, str); }
void SpeedTest(const char *str){ SendString(GMSH_SPEED_TEST, str); }
void Option(int num, const char *str)
{
if(num < 1) num = 1;
if(num > 5) num = 5;
SendString(GMSH_OPTION_1 + num - 1, str);
}
int ReceiveHeader(int *type, int *len)
{
......@@ -178,6 +197,12 @@ class GmshSocket{
close(s);
#else
closesocket(s);
#endif
}
void ShutdownSocket(int s)
{
#if !defined(WIN32) || defined(__CYGWIN__)
shutdown(s, SHUT_RDWR);
#endif
}
};
......@@ -188,16 +213,15 @@ class GmshClient : public GmshSocket {
~GmshClient(){}
int Connect(const char *sockname)
{
// slight delay to be sure that the socket is bound by the
// server before we attempt to connect to it...
// slight delay to make sure that the socket is bound by the
// server before we attempt to connect to it
_Sleep(100);
if(strstr(sockname, "/") || strstr(sockname, "\\") || !strstr(sockname, ":")){
#if !defined(WIN32) || defined(__CYGWIN__)
// UNIX socket (testing ":" is not enough with Windows paths)
_sock = socket(PF_UNIX, SOCK_STREAM, 0);
if(_sock < 0)
return -1; // Error: Couldn't create socket
if(_sock < 0) return -1;
// try to connect socket to given name
struct sockaddr_un addr_un;
memset((char *) &addr_un, 0, sizeof(addr_un));
......@@ -215,8 +239,7 @@ class GmshClient : public GmshSocket {
else{
// TCP/IP socket
_sock = socket(AF_INET, SOCK_STREAM, 0);
if(_sock < 0)
return -1; // Error: Couldn't create socket
if(_sock < 0) return -1;
// try to connect socket to host:port
const char *port = strstr(sockname, ":");
int portno = atoi(port + 1);
......@@ -228,7 +251,7 @@ class GmshClient : public GmshSocket {
struct hostent *server;
if(!(server = gethostbyname(remote))){
CloseSocket(_sock);
return -3; // Error: No such host
return -3; // no such host
}
struct sockaddr_in addr_in;
memset((char *) &addr_in, 0, sizeof(addr_in));
......@@ -242,11 +265,7 @@ class GmshClient : public GmshSocket {
}
}
CloseSocket(_sock);
return -2; // Error: Couldn't connect
}
int Select(int seconds, int microseconds)
{
return GmshSocket::Select(_sock, seconds, microseconds);
return -2; // couldn't connect
}
void Start()
{
......@@ -256,24 +275,9 @@ class GmshClient : public GmshSocket {
#else
sprintf(tmp, "%d", _getpid());
#endif
SendString(CLIENT_START, tmp);
}
void Stop(){ SendString(CLIENT_STOP, "Goodbye!"); }
void Info(const char *str){ SendString(CLIENT_INFO, str); }
void Warning(const char *str){ SendString(CLIENT_WARNING, str); }
void Error(const char *str){ SendString(CLIENT_ERROR, str); }
void Progress(const char *str){ SendString(CLIENT_PROGRESS, str); }
// deprecated: use MergeFile instead
void View(const char *str){ SendString(CLIENT_MERGE_FILE, str); }
void MergeFile(const char *str){ SendString(CLIENT_MERGE_FILE, str); }
void ParseString(const char *str){ SendString(CLIENT_PARSE_STRING, str); }
void SpeedTest(const char *str){ SendString(CLIENT_SPEED_TEST, str); }
void Option(int num, const char *str)
{
if(num < 1) num = 1;
if(num > 5) num = 5;
SendString(CLIENT_OPTION_1 + num - 1, str);
SendString(GMSH_START, tmp);
}
void Stop(){ SendString(GMSH_STOP, "Goodbye!"); }
void Disconnect(){ CloseSocket(_sock); }
};
......@@ -284,18 +288,11 @@ class GmshServer : public GmshSocket{
GmshServer() : GmshSocket(), _portno(-1) {}
virtual ~GmshServer(){}
virtual int SystemCall(const char *str) = 0;
virtual int NonBlockingWait(int socket, int num, double waitint) = 0;
int StartClient(const char *command, const char *sockname=0, int maxdelay=4)
virtual int NonBlockingWait(int socket, double waitint, double timeout) = 0;
int Start(const char *command, const char *sockname, double timeout)
{
bool justwait = (!command || !strlen(command));
if(!sockname) throw "Invalid (null) socket name";
_sockname = sockname;
// no socket? launch the command directly
if(!_sockname) {
SystemCall(command);
return 1;
}
int tmpsock;
if(strstr(_sockname, "/") || strstr(_sockname, "\\") || !strstr(_sockname, ":")){
// UNIX socket (testing ":" is not enough with Windows paths)
......@@ -305,8 +302,7 @@ class GmshServer : public GmshSocket{
unlink(_sockname);
// create a socket
tmpsock = socket(PF_UNIX, SOCK_STREAM, 0);
if(tmpsock < 0)
return -1; // Error: Couldn't create socket
if(tmpsock < 0) throw "Couldn't create socket";
// bind the socket to its name
struct sockaddr_un addr_un;
memset((char *) &addr_un, 0, sizeof(addr_un));
......@@ -314,12 +310,12 @@ class GmshServer : public GmshSocket{
addr_un.sun_family = AF_UNIX;
if(bind(tmpsock, (struct sockaddr *)&addr_un, sizeof(addr_un)) < 0){
CloseSocket(tmpsock);
return -2; // Error: Couldn't bind socket to name
throw "Couldn't bind socket to name";
}
// change permissions on the socket name in case it has to be rm'd later
chmod(_sockname, 0666);
#else
return -7; // Unix sockets not available on Windows
throw "Unix sockets not available on Windows";
#endif
}
else{
......@@ -333,7 +329,7 @@ class GmshServer : public GmshSocket{
#else
if(tmpsock == INVALID_SOCKET)
#endif
return -1; // Error: Couldn't create socket
throw "Couldn't create socket";
// bind the socket to its name
struct sockaddr_in addr_in;
memset((char *) &addr_in, 0, sizeof(addr_in));
......@@ -342,33 +338,33 @@ class GmshServer : public GmshSocket{
addr_in.sin_port = htons(_portno);
if(bind(tmpsock, (struct sockaddr *)&addr_in, sizeof(addr_in)) < 0){
CloseSocket(tmpsock);
return -2; // Error: Couldn't bind socket to name
throw "Couldn't bind socket to name";
}
}
if(!justwait)
if(command && strlen(command)){
SystemCall(command); // Start the solver
}
else{
timeout = 0.; // no command launched: don't set a timeout
}
// listen on socket (queue up to 20 connections before having
// them automatically rejected)
if(listen(tmpsock, 20)){
CloseSocket(tmpsock);
return -3; // Error: Socket listen failed
throw "Socket listen failed";
}
if(justwait){
// wait indefinitely until we get data
if(NonBlockingWait(tmpsock, -1, 0.5)){
// wait until we get data
int ret = NonBlockingWait(tmpsock, 0.5, timeout);
if(ret){
CloseSocket(tmpsock);
return -6; // not an actual error: we just stopped listening
}
if(ret == 2){
throw "Socket listening timeout";
}
else{
// Wait at most maxdelay seconds for data, issue error if no
// connection in that amount of time
if(!Select(tmpsock, maxdelay, 0)){
CloseSocket(tmpsock);
return -4; // Error: Socket listening timeout
return -1; // stopped listening
}
}
......@@ -378,8 +374,6 @@ class GmshServer : public GmshSocket{
struct sockaddr_un from_un;
socklen_t len = sizeof(from_un);
_sock = accept(tmpsock, (struct sockaddr *)&from_un, &len);
#else
_sock = -7; // Unix sockets not available on Windows
#endif
}
else{
......@@ -390,15 +384,16 @@ class GmshServer : public GmshSocket{
CloseSocket(tmpsock);
if(_sock < 0)
return -5; // Error: Socket accept failed
throw "Socket accept failed";
return _sock;
}
int StopClient()
int Shutdown()
{
#if !defined(WIN32) || defined(__CYGWIN__)
if(_portno < 0)
unlink(_sockname);
#endif
ShutdownSocket(_sock);
CloseSocket(_sock);
return 0;
}
......
Solver.Name1 = "My C++ Solver";
Solver.Executable1 = "solver.exe";
Solver.Executable1 = "./solver.exe";
Solver.InputName1 = "dummy";
Solver.OptionCommand1 = "-options";
Solver.FirstOption1 = "My options";
Solver.FirstButton1 = "Run !";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment