diff --git a/Fltk/GmshServer.h b/Fltk/GmshServer.h index 788d08cb918e1c3268bec2d20e4f9b74c68327f0..8cf04c33755250c80259c8f6b533c1d68617c67d 100644 --- a/Fltk/GmshServer.h +++ b/Fltk/GmshServer.h @@ -60,18 +60,19 @@ int WaitForData(int socket, int num, int pollint, double waitint); class GmshServer { public: // This should match what's in GmshClient.h - typedef enum{ CLIENT_START = 1, - CLIENT_STOP = 2, - CLIENT_INFO = 10, - CLIENT_WARNING = 11, - CLIENT_ERROR = 12, - CLIENT_PROGRESS = 13, - CLIENT_VIEW = 20, - CLIENT_OPTION_1 = 100, - CLIENT_OPTION_2 = 101, - CLIENT_OPTION_3 = 102, - CLIENT_OPTION_4 = 103, - CLIENT_OPTION_5 = 104 } MessageType; + typedef enum{ 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_OPTION_1 = 100, + CLIENT_OPTION_2 = 101, + CLIENT_OPTION_3 = 102, + CLIENT_OPTION_4 = 103, + CLIENT_OPTION_5 = 104 } MessageType; // FIXME: this should be removed static int init, s; @@ -226,6 +227,21 @@ class GmshServer { } return 0; } + int ReceiveMessageHeader(int *type, int *len) + { + _ReceiveData(type, sizeof(int)); + if(_ReceiveData(len, sizeof(int))) + return 1; + return 0; + } + int ReceiveMessageBody(int len, char *str) + { + if(_ReceiveData(str, len) == len) { + str[len] = '\0'; + return 1; + } + return 0; + } int StopClient() { if(_portno < 0){ diff --git a/Fltk/Solvers.cpp b/Fltk/Solvers.cpp index 5bbffa75b753f92de213d95103ba2d2761b33bbc..791ae413a3816ddc879eca7e16a6f9ce3c0170ab 100644 --- a/Fltk/Solvers.cpp +++ b/Fltk/Solvers.cpp @@ -1,4 +1,4 @@ -// $Id: Solvers.cpp,v 1.43 2006-02-22 17:25:03 geuzaine Exp $ +// $Id: Solvers.cpp,v 1.44 2006-02-23 21:59:08 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -89,7 +89,7 @@ int WaitForData(int socket, int num, int pollint, double waitint) int Solver(int num, char *args) { - char command[1024], sockname[1024], str[1024], prog[1024], buf[1024]; + char command[1024], sockname[1024], prog[1024], tmp[1024], tmp2[1024]; new_connection: @@ -119,18 +119,18 @@ int Solver(int num, char *args) if(!strstr(CTX.solver.socket_name, ":")){ // file socket if(num >= 0) - sprintf(str, "%s%s-%d", CTX.home_dir, CTX.solver.socket_name, num); + sprintf(tmp, "%s%s-%d", CTX.home_dir, CTX.solver.socket_name, num); else - sprintf(str, "%s%s", CTX.home_dir, CTX.solver.socket_name); - FixWindowsPath(str, sockname); + sprintf(tmp, "%s%s", CTX.home_dir, CTX.solver.socket_name); + FixWindowsPath(tmp, sockname); } else strcpy(sockname, CTX.solver.socket_name); if(num >= 0){ - sprintf(str, "\"%s\"", sockname); - sprintf(buf, SINFO[num].socket_command, str); - sprintf(command, "%s %s %s", prog, args, buf); + sprintf(tmp, "\"%s\"", sockname); + sprintf(tmp2, SINFO[num].socket_command, tmp); + sprintf(command, "%s %s %s", prog, args, tmp2); #if !defined(WIN32) strcat(command, " &"); #endif @@ -182,70 +182,83 @@ int Solver(int num, char *args) if(stop || (num >= 0 && SINFO[num].pid < 0)) break; - int type; - if(server.ReceiveString(&type, str)){ - switch (type) { - case GmshServer::CLIENT_START: - if(num >= 0) - SINFO[num].pid = atoi(str); - break; - case GmshServer::CLIENT_STOP: - stop = 1; - if(num >= 0) - SINFO[num].pid = -1; - break; - case GmshServer::CLIENT_PROGRESS: - if(num >= 0) - Msg(STATUS3N, "%s %s", SINFO[num].name, str); - else - Msg(STATUS3N, "%s", str); - break; - case GmshServer::CLIENT_OPTION_1: - if(num >= 0) - strcpy(SINFO[num].option[0][SINFO[num].nbval[0]++], str); - break; - case GmshServer::CLIENT_OPTION_2: - if(num >= 0) - strcpy(SINFO[num].option[1][SINFO[num].nbval[1]++], str); - break; - case GmshServer::CLIENT_OPTION_3: - if(num >= 0) - strcpy(SINFO[num].option[2][SINFO[num].nbval[2]++], str); - break; - case GmshServer::CLIENT_OPTION_4: - if(num >= 0) - strcpy(SINFO[num].option[3][SINFO[num].nbval[3]++], str); - break; - case GmshServer::CLIENT_OPTION_5: - if(num >= 0) - strcpy(SINFO[num].option[4][SINFO[num].nbval[4]++], str); - break; - case GmshServer::CLIENT_VIEW: - if(num < 0 || (num >= 0 && SINFO[num].merge_views)) { - int n = List_Nbr(CTX.post.list); - MergeProblem(str); + int type, length; + if(server.ReceiveMessageHeader(&type, &length)){ + char *message = new char[length+1]; + if(server.ReceiveMessageBody(length, message)){ + switch (type) { + case GmshServer::CLIENT_START: + if(num >= 0) + SINFO[num].pid = atoi(message); + break; + case GmshServer::CLIENT_STOP: + stop = 1; + if(num >= 0) + SINFO[num].pid = -1; + break; + case GmshServer::CLIENT_PROGRESS: + if(num >= 0) + Msg(STATUS3N, "%s %s", SINFO[num].name, message); + else + Msg(STATUS3N, "%s", message); + break; + case GmshServer::CLIENT_OPTION_1: + if(num >= 0) + strcpy(SINFO[num].option[0][SINFO[num].nbval[0]++], message); + break; + case GmshServer::CLIENT_OPTION_2: + if(num >= 0) + strcpy(SINFO[num].option[1][SINFO[num].nbval[1]++], message); + break; + case GmshServer::CLIENT_OPTION_3: + if(num >= 0) + strcpy(SINFO[num].option[2][SINFO[num].nbval[2]++], message); + break; + case GmshServer::CLIENT_OPTION_4: + if(num >= 0) + strcpy(SINFO[num].option[3][SINFO[num].nbval[3]++], message); + break; + case GmshServer::CLIENT_OPTION_5: + if(num >= 0) + strcpy(SINFO[num].option[4][SINFO[num].nbval[4]++], message); + break; + case GmshServer::CLIENT_MERGE_FILE: + printf("merging %s\n", message); + if(num < 0 || (num >= 0 && SINFO[num].merge_views)) { + int n = List_Nbr(CTX.post.list); + MergeProblem(message); + Draw(); + if(n != List_Nbr(CTX.post.list)) + WID->set_context(menu_post, 0); + } + break; + case GmshServer::CLIENT_PARSE_STRING: + ParseString(message); Draw(); - if(n != List_Nbr(CTX.post.list)) - WID->set_context(menu_post, 0); + break; + case GmshServer::CLIENT_INFO: + Msg(SOLVER, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", message); + break; + case GmshServer::CLIENT_WARNING: + case GmshServer::CLIENT_ERROR: + Msg(SOLVERR, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", message); + break; + default: + Msg(WARNING, "Unknown type of message received from %s", + num >= 0 ? SINFO[num].name : "client"); + Msg(SOLVER, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", message); + break; } - break; - case GmshServer::CLIENT_INFO: - Msg(SOLVER, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", str); - break; - case GmshServer::CLIENT_WARNING: - case GmshServer::CLIENT_ERROR: - Msg(SOLVERR, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", str); - break; - default: - Msg(WARNING, "Unknown type of message received from %s", - num >= 0 ? SINFO[num].name : "client"); - Msg(SOLVER, "%-8.8s: %s", num >= 0 ? SINFO[num].name : "Client", str); + WID->check(); + } + else{ + Msg(WARNING, "Failed to receive message body on socket: arborting"); break; } - WID->check(); + delete [] message; } else{ - Msg(WARNING, "Failed to received data on socket: arborting"); + // didn't get any header, just abort break; } } diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp index 57bf6cdafed8886b190ffbe53a4548eb27da7297..897058d5c496c7296f58e66f893e2f473c70ffaf 100644 --- a/Parser/OpenFile.cpp +++ b/Parser/OpenFile.cpp @@ -1,4 +1,4 @@ -// $Id: OpenFile.cpp,v 1.88 2006-01-28 04:50:36 geuzaine Exp $ +// $Id: OpenFile.cpp,v 1.89 2006-02-23 21:59:08 geuzaine Exp $ // // Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle // @@ -214,7 +214,8 @@ void ParseString(char *str) if(!str) return; if((fp = fopen(CTX.tmp_filename_fullpath, "w"))) { - fprintf(fp, "%s\n", str); + fprintf(fp, str); + fprintf(fp, "\n"); fclose(fp); ParseFile(CTX.tmp_filename_fullpath, 0, 1); } diff --git a/utils/solvers/c++/GmshClient.h b/utils/solvers/c++/GmshClient.h index c07f1adb57089db6e9399fdc68b419effad2aca2..ddfa50723b827b2dd793f28a9c08fd843f4ced14 100644 --- a/utils/solvers/c++/GmshClient.h +++ b/utils/solvers/c++/GmshClient.h @@ -53,18 +53,19 @@ class GmshClient { private: - typedef enum{ CLIENT_START = 1, - CLIENT_STOP = 2, - CLIENT_INFO = 10, - CLIENT_WARNING = 11, - CLIENT_ERROR = 12, - CLIENT_PROGRESS = 13, - CLIENT_VIEW = 20, - CLIENT_OPTION_1 = 100, - CLIENT_OPTION_2 = 101, - CLIENT_OPTION_3 = 102, - CLIENT_OPTION_4 = 103, - CLIENT_OPTION_5 = 104 } MessageType; + typedef enum{ CLIENT_START = 1, + CLIENT_STOP = 2, + CLIENT_INFO = 10, + CLIENT_WARNING = 11, + CLIENT_ERROR = 12, + CLIENT_PROGRESS = 13, + CLIENT_MERGE_FILE = 20, // old name was CLIENT_VIEW + CLIENT_PARSE_STRING = 21, + CLIENT_OPTION_1 = 100, + CLIENT_OPTION_2 = 101, + CLIENT_OPTION_3 = 102, + CLIENT_OPTION_4 = 103, + CLIENT_OPTION_5 = 104 } MessageType; int _sock; void _SendData(void *buffer, int bytes) { @@ -193,9 +194,18 @@ class GmshClient { { _SendString(CLIENT_PROGRESS, str); } - void View(char *str) + void View(char *str) { - _SendString(CLIENT_VIEW, str); + // deprecated: use MergeFile(str) instead + _SendString(CLIENT_MERGE_FILE, str); + } + void MergeFile(char *str) + { + _SendString(CLIENT_MERGE_FILE, str); + } + void ParseString(char *str) + { + _SendString(CLIENT_PARSE_STRING, str); } void Option(int num, char *str) { diff --git a/utils/solvers/c++/solver.cpp b/utils/solvers/c++/solver.cpp index ce5cb34a6d82394c7fe04c827832586afd402833..48c883c2c9e07e11c8f7f3574d8b7ce75713820d 100644 --- a/utils/solvers/c++/solver.cpp +++ b/utils/solvers/c++/solver.cpp @@ -1,4 +1,4 @@ -// $Id: solver.cpp,v 1.6 2005-03-12 07:52:56 geuzaine Exp $ +// $Id: solver.cpp,v 1.7 2006-02-23 21:59:08 geuzaine Exp $ // // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle // @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) fprintf(file, "SP(%d,0,0){%g};\n", j,sin(j*i*M_PI/10.)); fprintf(file, "};\n"); fclose(file); - client.View("solver.pos"); + client.MergeFile("solver.pos"); } } client.Info("Done!"); diff --git a/utils/solvers/c/GmshClient.h b/utils/solvers/c/GmshClient.h index b0e26108417ee017e58d3fa8b6090fd731364f21..1b0a3de4c0b026a5aa5328acbecf103af632c834 100644 --- a/utils/solvers/c/GmshClient.h +++ b/utils/solvers/c/GmshClient.h @@ -29,22 +29,25 @@ * Please report all bugs and problems to <gmsh@geuz.org>. */ -#define GMSH_CLIENT_START 1 -#define GMSH_CLIENT_STOP 2 -#define GMSH_CLIENT_INFO 10 -#define GMSH_CLIENT_WARNING 11 -#define GMSH_CLIENT_ERROR 12 -#define GMSH_CLIENT_PROGRESS 13 -#define GMSH_CLIENT_VIEW 20 -#define GMSH_CLIENT_OPTION 100 -#define GMSH_CLIENT_OPTION_1 (GMSH_CLIENT_OPTION+0) -#define GMSH_CLIENT_OPTION_2 (GMSH_CLIENT_OPTION+1) -#define GMSH_CLIENT_OPTION_3 (GMSH_CLIENT_OPTION+2) -#define GMSH_CLIENT_OPTION_4 (GMSH_CLIENT_OPTION+3) -#define GMSH_CLIENT_OPTION_5 (GMSH_CLIENT_OPTION+4) +#define GMSH_CLIENT_START 1 +#define GMSH_CLIENT_STOP 2 +#define GMSH_CLIENT_INFO 10 +#define GMSH_CLIENT_WARNING 11 +#define GMSH_CLIENT_ERROR 12 +#define GMSH_CLIENT_PROGRESS 13 +#define GMSH_CLIENT_VIEW 20 /* deprecated: use MERGE_FILE instead */ +#define GMSH_CLIENT_MERGE_FILE 20 +#define GMSH_CLIENT_PARSE_STRING 21 +#define GMSH_CLIENT_OPTION 100 +#define GMSH_CLIENT_OPTION_1 (GMSH_CLIENT_OPTION+0) +#define GMSH_CLIENT_OPTION_2 (GMSH_CLIENT_OPTION+1) +#define GMSH_CLIENT_OPTION_3 (GMSH_CLIENT_OPTION+2) +#define GMSH_CLIENT_OPTION_4 (GMSH_CLIENT_OPTION+3) +#define GMSH_CLIENT_OPTION_5 (GMSH_CLIENT_OPTION+4) int Gmsh_Connect(char *sockname); void Gmsh_SendString(int socket, int type, char str[]); void Gmsh_Disconnect(int sock); + #endif diff --git a/utils/solvers/c/solver.c b/utils/solvers/c/solver.c index ca87416b37b3c4c1eecbd1bedb5aa51fe0b5bcdf..06d1596c697ec405c9159d28353a4b0c9a01f18d 100644 --- a/utils/solvers/c/solver.c +++ b/utils/solvers/c/solver.c @@ -1,4 +1,4 @@ -/* $Id: solver.c,v 1.2 2005-01-17 18:52:49 geuzaine Exp $ */ +/* $Id: solver.c,v 1.3 2006-02-23 21:59:08 geuzaine Exp $ */ /* * Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle * @@ -193,7 +193,7 @@ int main(int argc, char *argv[]) fprintf(file, "ST(0,0,0,1,0,0,0,1,0){0,1,2};\n"); fprintf(file, "};\n"); fclose(file); - Gmsh_SendString(s, GMSH_CLIENT_VIEW, "solver.pos"); + Gmsh_SendString(s, GMSH_CLIENT_MERGE_FILE, "solver.pos"); } break; } diff --git a/utils/solvers/perl/GMSH_CLIENT.pm b/utils/solvers/perl/GMSH_CLIENT.pm index ab98befc770908ae0e58cfb37dcbdf198aaea0cb..2be3fb613d7f302e83232cecab3e0b68eb3ba3b7 100755 --- a/utils/solvers/perl/GMSH_CLIENT.pm +++ b/utils/solvers/perl/GMSH_CLIENT.pm @@ -1,4 +1,4 @@ -# $Id: GMSH_CLIENT.pm,v 1.2 2005-01-16 20:41:42 geuzaine Exp $ +# $Id: GMSH_CLIENT.pm,v 1.3 2006-02-23 21:59:09 geuzaine Exp $ # # Copyright (c) 2002 Laurent CHAMPANEY <laurent.champaney@meca.uvsq.fr>. # All rights reserved. @@ -8,19 +8,21 @@ package GMSH_CLIENT; use Socket; -$START = 1; -$STOP = 2; -$INFO = 10; -$WARNING = 11; -$ERROR = 12; -$PROGRESS = 13; -$VIEW = 20; -$OPTION = 100; -$OPTION_1 = ($OPTION+0); -$OPTION_2 = ($OPTION+1); -$OPTION_3 = ($OPTION+2); -$OPTION_4 = ($OPTION+3); -$OPTION_5 = ($OPTION+4); +$START = 1; +$STOP = 2; +$INFO = 10; +$WARNING = 11; +$ERROR = 12; +$PROGRESS = 13; +$VIEW = 20; # deprecated: use MERGE_FILE instead +$MERGE_FILE = 20; +$PARSE_STRING = 21; +$OPTION = 100; +$OPTION_1 = ($OPTION+0); +$OPTION_2 = ($OPTION+1); +$OPTION_3 = ($OPTION+2); +$OPTION_4 = ($OPTION+3); +$OPTION_5 = ($OPTION+4); sub SocketSendData (*$;$$) { my ($socket, $buffer, $bytes) = @_; diff --git a/utils/solvers/perl/solver.pl b/utils/solvers/perl/solver.pl index 52abbefeb84745ba139364e3671e3f8a6ff52d5a..afcdc39cc1710ab0245306c939e6ad3a340c6420 100755 --- a/utils/solvers/perl/solver.pl +++ b/utils/solvers/perl/solver.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: solver.pl,v 1.2 2005-01-17 18:52:49 geuzaine Exp $ +# $Id: solver.pl,v 1.3 2006-02-23 21:59:09 geuzaine Exp $ # # Copyright (c) 2002 Laurent CHAMPANEY <laurent.champaney@meca.uvsq.fr>. # @@ -92,7 +92,7 @@ if ($opt_run) { print POSFIC "ST(0,0,0,1,0,0,0,1,0){0,1,2};\n"; print POSFIC "};\n"; close POSFIC; - GMSH_CLIENT::SendString(CLIENT, $GMSH_CLIENT::VIEW, "solver.pos"); + GMSH_CLIENT::SendString(CLIENT, $GMSH_CLIENT::MERGE_FILE, "solver.pos"); }; # # 3.3. We can now disconnect the solver from Gmsh: diff --git a/utils/solvers/python/Gmsh.py b/utils/solvers/python/Gmsh.py index ccbe8ae6cca0aa111b76685a1660e65ac6588649..91cd8dcf1858ebec909304285f6530c39748e3bf 100644 --- a/utils/solvers/python/Gmsh.py +++ b/utils/solvers/python/Gmsh.py @@ -26,19 +26,21 @@ import time import os import sys -START = 1 -STOP = 2 -INFO = 10 -WARNING = 11 -ERROR = 12 -PROGRESS = 13 -VIEW = 20 -OPTION = 100 -OPTION_1 = OPTION + 0 -OPTION_2 = OPTION + 1 -OPTION_3 = OPTION + 2 -OPTION_4 = OPTION + 3 -OPTION_5 = OPTION + 4 +START = 1 +STOP = 2 +INFO = 10 +WARNING = 11 +ERROR = 12 +PROGRESS = 13 +VIEW = 20 # deprecated: use MERGE_FILE instead +MERGE_FILE = 20 +PARSE_STRING = 21 +OPTION = 100 +OPTION_1 = OPTION + 0 +OPTION_2 = OPTION + 1 +OPTION_3 = OPTION + 2 +OPTION_4 = OPTION + 3 +OPTION_5 = OPTION + 4 # Module variable used to store the open communication socket with Gmsh sock = None @@ -72,8 +74,8 @@ def send(message, type=INFO): type -- the type of message being sent (default INFO) As of Gmsh version 1.56, type should be one of: - START STOP INFO WARNING ERROR PROGRESS VIEW OPTION - OPTION_1 OPTION_2 OPTION_3 OPTION_4 OPTION_5 + START STOP INFO WARNING ERROR PROGRESS MERGE_FILE PARSE_FILE + OPTION OPTION_1 OPTION_2 OPTION_3 OPTION_4 OPTION_5 If no socket has been opened (using a Gmsh.Client instance) then print the string sys.stderr. diff --git a/utils/solvers/python/postcsv.py b/utils/solvers/python/postcsv.py index f90dc1942d0130a2785b931abb8d33a029057a32..8e014fd26bce43a8ff550301118bd5df84111e7b 100755 --- a/utils/solvers/python/postcsv.py +++ b/utils/solvers/python/postcsv.py @@ -305,4 +305,4 @@ else: else: pmesh.makeviews(posfile) posfile.close() - Gmsh.send(posfile.name, Gmsh.VIEW) + Gmsh.send(posfile.name, Gmsh.MERGE_FILE)