diff --git a/Common/GmshDaemon.cpp b/Common/GmshDaemon.cpp index 3623490db69a4ba76898fdeeb75b24ceafc6d12f..3ddb1c3474e5b82ee3f18f946f67c1deb1f02e0a 100644 --- a/Common/GmshDaemon.cpp +++ b/Common/GmshDaemon.cpp @@ -3,14 +3,42 @@ // See the LICENSE.txt file for license information. Please report all // bugs and problems to <gmsh@geuz.org>. +#include <sstream> #include "Message.h" +#include "OS.h" #include "GmshSocket.h" int GmshDaemon(std::string socket) { - Msg::Info("Gmsh daemon running on socket %s", socket.c_str()); + GmshClient client; + + if(client.Connect(socket.c_str()) < 0){ + Msg::Error("Unable to connect to server on %s", socket.c_str()); + return 1; + } + client.Start(); + + int i = 0; while(1){ - ; + if(!client.Select(0, 1000)){ + // data is available to read: deal with it + int type, length; + if(client.ReceiveHeader(&type, &length)){ + printf("received header: %d %d\n", type, length); + char *msg = new char[length]; + if(client.ReceiveString(length, msg)){ + printf("received string: %s\n", msg); + } + delete [] msg; + + printf("stopping connection!\n"); + break; + } + } } + + client.Stop(); + client.Disconnect(); + return 0; } diff --git a/Common/GmshSocket.h b/Common/GmshSocket.h index 3f355c7ea7b4d36e748e8b7ab2f073bf8089deb5..5bf280b7d1d65103769584ba08d0d62d7cac6314 100644 --- a/Common/GmshSocket.h +++ b/Common/GmshSocket.h @@ -117,13 +117,14 @@ class GmshSocket{ #endif } // utility function to wait for some data to read on a socket (if - // seconds==0 we check for available data and return immediately, - // i.e., we do polling) - int Select(int socket, int seconds) + // 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) { struct timeval tv; tv.tv_sec = seconds; - tv.tv_usec = 0; + tv.tv_usec = microseconds; fd_set rfds; FD_ZERO(&rfds); FD_SET(socket, &rfds); @@ -239,6 +240,10 @@ class GmshClient : public GmshSocket { CloseSocket(_sock); return -2; // Error: Couldn't connect } + int Select(int seconds, int microseconds) + { + return GmshSocket::Select(_sock, seconds, microseconds); + } void Start() { char tmp[256]; @@ -310,7 +315,7 @@ class GmshServer : public GmshSocket{ // 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 without Cygwin + return -7; // Unix sockets not available on Windows #endif } else{ @@ -357,7 +362,7 @@ class GmshServer : public GmshSocket{ else{ // Wait at most maxdelay seconds for data, issue error if no // connection in that amount of time - if(!Select(tmpsock, maxdelay)){ + if(!Select(tmpsock, maxdelay, 0)){ CloseSocket(tmpsock); return -4; // Error: Socket listening timeout } diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp index 289a1404fe329fd18ea70c67b44e7d5f26142b58..0266d566f67e733c545787d185be3ceca3c93259 100644 --- a/Fltk/Opengl.cpp +++ b/Fltk/Opengl.cpp @@ -18,19 +18,20 @@ extern Context_T CTX; // Draw specialization -void SetOpenglContext(void) +void SetOpenglContext() { if(!WID) return; WID->make_opengl_current(); } -void Draw(void) +void Draw() { if(!WID) return; WID->redraw_opengl(); } -void Draw_String(const char *s, const char *font_name, int font_enum, int font_size, int align) +void Draw_String(std::string s, const char *font_name, int font_enum, + int font_size, int align) { if(CTX.printing && !CTX.print.text) return; @@ -43,7 +44,7 @@ void Draw_String(const char *s, const char *font_name, int font_enum, int font_s glGetDoublev(GL_CURRENT_RASTER_POSITION, pos); double x[3], w[3] = {pos[0], pos[1], pos[2]}; gl_font(font_enum, font_size); - float width = gl_width(s); + float width = gl_width(s.c_str()); float height = gl_height(); switch(align){ case 1: w[0] -= width/2.; break; // bottom center @@ -63,11 +64,11 @@ void Draw_String(const char *s, const char *font_name, int font_enum, int font_s if(!CTX.printing){ gl_font(font_enum, font_size); - gl_draw(s); + gl_draw(s.c_str()); } else{ if(CTX.print.format == FORMAT_TEX){ - std::string tmp = SanitizeTeXString(s, CTX.print.tex_as_equation); + std::string tmp = SanitizeTeXString(s.c_str(), CTX.print.tex_as_equation); int opt; switch(align){ case 1: opt = GL2PS_TEXT_B; break; // bottom center @@ -86,31 +87,31 @@ void Draw_String(const char *s, const char *font_name, int font_enum, int font_s CTX.print.format == FORMAT_EPS || CTX.print.format == FORMAT_PDF || CTX.print.format == FORMAT_SVG)){ - gl2psText(s, font_name, font_size); + gl2psText(s.c_str(), font_name, font_size); } else{ gl_font(font_enum, font_size); - gl_draw(s); + gl_draw(s.c_str()); } } } -void Draw_String(const char *s) +void Draw_String(std::string s) { Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 0); } -void Draw_String_Center(const char *s) +void Draw_String_Center(std::string s) { Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 1); } -void Draw_String_Right(const char *s) +void Draw_String_Right(std::string s) { Draw_String(s, CTX.gl_font, CTX.gl_font_enum, CTX.gl_fontsize, 2); } -void Draw_String(const char *s, double style) +void Draw_String(std::string s, double style) { unsigned int bits = (unsigned int)style; diff --git a/Fltk/Solvers.cpp b/Fltk/Solvers.cpp index 1469e8fb7bab5a3373df35e737303d9f9edb3418..d327375e7c6ec0fdf714785dfeaf6dc2a35dc1d2 100644 --- a/Fltk/Solvers.cpp +++ b/Fltk/Solvers.cpp @@ -43,10 +43,11 @@ class myGmshServer : public GmshServer{ // check if there is data (call select with a zero timeout to // return immediately, i.e., do polling) - int ret = Select(socket, 0); + int ret = Select(socket, 0, 0); if(ret == 0){ - // nothing available: wait at most waitint seconds + // nothing available: wait at most waitint seconds, and in the + // meantime respond to FLTK events WID->wait(waitint); } else if(ret > 0){ diff --git a/Graphics/Draw.h b/Graphics/Draw.h index 128cd109db08989c412c0fb3e8c609f3aedb4606..bbc3c4de01e2cbf40f7a548a47623cfd63d42b21 100644 --- a/Graphics/Draw.h +++ b/Graphics/Draw.h @@ -6,6 +6,7 @@ #ifndef _DRAW_H_ #define _DRAW_H_ +#include <string> #include "SBoundingBox3d.h" #define GMSH_RENDER 1 @@ -30,10 +31,10 @@ void Draw2d(); void DrawPlugin(void (*draw)()); void Draw(); -void Draw_String(const char *s); -void Draw_String(const char *s, double style); -void Draw_String_Center(const char *s); -void Draw_String_Right(const char *s); +void Draw_String(std::string); +void Draw_String(std::string, double style); +void Draw_String_Center(std::string); +void Draw_String_Right(std::string); void Draw_Geom(); void Draw_Mesh(); void Draw_Post(); diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp index a1ee51162e9412b5a9488ee9853505973f418e5d..a8c37225efb8589add4f70a69619e8be29bcf16b 100644 --- a/Graphics/Post.cpp +++ b/Graphics/Post.cpp @@ -1138,11 +1138,10 @@ static void drawNumberGlyphs(PView *p, int numNodes, int numComp, unsigned int col = opt->getColor(v, vmin, vmax); glColor4ubv((GLubyte *) & col); glRasterPos3d(pc.x(), pc.y(), pc.z()); - const char *txt = stringValue(numComp, d, v, opt->Format).c_str(); if(opt->CenterGlyphs) - Draw_String_Center(txt); + Draw_String_Center(stringValue(numComp, d, v, opt->Format)); else - Draw_String(txt); + Draw_String(stringValue(numComp, d, v, opt->Format)); } } else if(opt->GlyphLocation == PViewOptions::Vertex){ @@ -1152,11 +1151,10 @@ static void drawNumberGlyphs(PView *p, int numNodes, int numComp, unsigned int col = opt->getColor(v, vmin, vmax); glColor4ubv((GLubyte *) & col); glRasterPos3d(xyz[i][0], xyz[i][1], xyz[i][2]); - const char *txt = stringValue(numComp, val[i], v, opt->Format).c_str(); if(opt->CenterGlyphs) - Draw_String_Center(txt); + Draw_String_Center(stringValue(numComp, val[i], v, opt->Format)); else - Draw_String(txt); + Draw_String(stringValue(numComp, val[i], v, opt->Format)); } } } @@ -1445,7 +1443,7 @@ class drawPView { std::string str; data->getString3D(i, opt->TimeStep, str, x, y, z, style); glRasterPos3d(x, y, z); - Draw_String(str.c_str(), style); + Draw_String(str, style); } } diff --git a/demos/primitives.pos b/demos/primitives.pos index c92923d50ee0cb1b851b21791bbd7c98742fb26b..0c7547de6a413941b7d7a8fc70b9f01b3e0081b3 100644 --- a/demos/primitives.pos +++ b/demos/primitives.pos @@ -1,9 +1,6 @@ // Post-processing primitives in parsed format -General.FastRedraw = 0 ; -General.ColorScheme = 1 ; - x = 0; y = 15; z = 0; @@ -58,6 +55,15 @@ View "Primitives"{ x,y,z+.5, x+.5,y,z+.5, x,y+.5,z+.5) {1,0,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0,0, 1,0,0,0,0,0,0,0,0}; + + T3(x,y--,z,0){"Scalar, vector and tensor pyramids"}; + SY(x,y--,z, x+.5,y,z, x+.5,y+.5,z, x,y+.5,z, x+.25,y+.25,z+.5) + {1,2,3,4,2}; + VY(x,y--,z, x+.5,y,z, x+.5,y+.5,z, x,y+.5,z, x+.25,y+.25,z+.5) + {1,0,0, 2,0,0, 3,0,0, 4,0,0, 2,0,0}; + TY(x,y--,z, x+.5,y,z, x+.5,y+.5,z, x,y+.5,z, x+.25,y+.25,z+.5) + {1,0,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0,0, 3,0,0,0,0,0,0,0,0, + 4,0,0,0,0,0,0,0,0, 2,0,0,0,0,0,0,0,0}; }; Alias View[0]; diff --git a/utils/solvers/c++/GmshSocket.h b/utils/solvers/c++/GmshSocket.h index 3f355c7ea7b4d36e748e8b7ab2f073bf8089deb5..5bf280b7d1d65103769584ba08d0d62d7cac6314 100644 --- a/utils/solvers/c++/GmshSocket.h +++ b/utils/solvers/c++/GmshSocket.h @@ -117,13 +117,14 @@ class GmshSocket{ #endif } // utility function to wait for some data to read on a socket (if - // seconds==0 we check for available data and return immediately, - // i.e., we do polling) - int Select(int socket, int seconds) + // 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) { struct timeval tv; tv.tv_sec = seconds; - tv.tv_usec = 0; + tv.tv_usec = microseconds; fd_set rfds; FD_ZERO(&rfds); FD_SET(socket, &rfds); @@ -239,6 +240,10 @@ class GmshClient : public GmshSocket { CloseSocket(_sock); return -2; // Error: Couldn't connect } + int Select(int seconds, int microseconds) + { + return GmshSocket::Select(_sock, seconds, microseconds); + } void Start() { char tmp[256]; @@ -310,7 +315,7 @@ class GmshServer : public GmshSocket{ // 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 without Cygwin + return -7; // Unix sockets not available on Windows #endif } else{ @@ -357,7 +362,7 @@ class GmshServer : public GmshSocket{ else{ // Wait at most maxdelay seconds for data, issue error if no // connection in that amount of time - if(!Select(tmpsock, maxdelay)){ + if(!Select(tmpsock, maxdelay, 0)){ CloseSocket(tmpsock); return -4; // Error: Socket listening timeout }