mday@cgl.ucsf.edu (06/21/88)
I'm having some problems communicating between the NeWS server and client. Perhaps a more enlightened NeWS programmer can point out the error in my ways. The first problems I am having, is coming up with an acceptable method of sending a larger number of lineto's from a client, in response to an event posted by the server. I have tried several approaches, with no success. Plan A) Normally in a C program, I would pass the data array by address. Of course this won't work under NeWS because the client and server don't share address space. Plan B) Use the cid utilities to synchronize communication between the client and the server. In response to a repaint event at the server, invoke a procedure that sets up the correct graphics context. Then for each vector to be drawn, perform lineto_ps (id, x, y) where lineto_ps is defined to be: cdef lineto_ps (int id, float x, float y) id { x y lineto } sendcidevent The problem with this approach is it is painfully slow. The NeWS Application Scenario admits that the cid utilities have too much overhead to be used when sending lots of vectors. Unfortunately, the manual doesn't spell out a more efficient alternative. Plan C) Only use the cid utilities to set up the correct graphics context. After the context is set up, invoke a PostScript routine on the server that performs a lineto without using sendcidevent. Since, cid utilities are only used to begin and terminate each event, this shouldn't exhibit the poor performance of Plan B. Unfortunately, my implementation of this doesn't seem to work. It seems that there is an implicit save and restore of the graphics context bracketing each sendcidevent, so that the lineto procedure isn't being sent to the correct canvas, or perhaps is being ignored completely. The second problem I am having is closely related to the above. I would like to send a variable number of character strings to the NeWS server in response to a user generated event. I haven't found any way of invoking a cdef routine with a variable number of arguments, so a reasonable thing to do is put all of the strings into an array on the stack. As an example my PostScript code for a repaint event is: /PaintClient { DAMAGE_TAG tagprint uniquecid dup typedprint [exch cidinterest] forkeventmgr waitprocess pop show_strings } def cdef repaired (int id) id { exit } sendcidevent the show_strings procedure simply prints the passed strings into a window. The server side code looks like: if (get_damage(&id)) { while (fgets(buff, sizeof(buff), fptr)) psio_fprintf(PostScript, "%s\n", buff); repaired(id); } This approach fails, because after the waitprocess exits, there isn't anything on the stack. I assumed that by using psio_fprintf, all of the characters I sent would end on the stack of the server. This is obviously not happening. Does using waitprocess preclude the use of the psio routines? Does anybody have any pointers? Should I abandon the use of the cid utilities? The NeWS manuals suggest that synchronization between client and server is a good thing, but either I am not using these utilities correctly, or they are more trouble than they are worth. Thanks in advance, Mark ---------- Mark Day UUCP: ..ucbvax!ucsfcgl!mday ARPA: mday@cgl.ucsf.edu BITNET: mday@ucsfcgl.BITNET
greg@gergle.UUCP (06/29/88)
>Does anybody have any pointers? Should I abandon the use of the cid utilities? >The NeWS manuals suggest that synchronization between client and server is >a good thing, but either I am not using these utilities correctly, or they >are more trouble than they are worth. I am assuming that you have a simple application. It is hard to give good advice without more details. Blow off the cid utilities. In response to damage have your PaintClient send something back to the C code. (D) print. In most cases sending simple ascii messages from the PostScript to the C code is plenty fast, and much easier to debug. Have your C code block with a psio_getc(PostScript). Check for an ioerror, and then switch off the character you receive. ... case 'D': myps_begindamage(); for(i = 0; i < points ; i++) { myps_sendpoints(points[i].x, points[i].y); } myps_doline(points); myps_enddamage(); break; ...... cdef myps_begindamage() gsave ... set state mywindow /ClientCanvas get setcanvas cdef myps_enddamage() grestore cdef myps_sendpoints(float x, float y) x y % shove 2 points on stack cdef myps_doline(int points) points % loop to draw lines Good Luck. -greg.