; This function opens the wave output file and grabs all the ; text after the last "#" character, which will be the Wave output ; since the last command sent to the Wave RPC server. ; ;..locals 50 FUNCTION wave_output COMMON javacom, path, x, y ; Read the file as a byte array filename = 'java.log' OPENR, unit, /Get_lun, path+filename stat = FSTAT(unit) nbuff = stat.size buff = BYTARR(nbuff, /Nozero) READU, unit, buff FREE_LUN, unit ; Get all the text after the last "#" in the file sepchar = BYTE('#') sepr = WHERE(buff eq sepchar(0)) lst = sepr(N_ELEMENTS(sepr)-1) begbuff = lst + 2 endbuff = N_ELEMENTS(buff)-1 IF endbuff GE begbuff THEN text = buff(begbuff:endbuff) ELSE text = '\012' RETURN, STRING(text) END ; This procedure saves the contents of the Z buffer to a GIF ; file. This uses the user library dc_write_image ; procedure which requires the "Image Magic" public domain ; utility be installed and compiled. ; PRO Redraw COMMON javacom, path, x, y filename = 'java.gif' ; Copy the contents of the Z buffer img=tvrd(0,0,x,y) ; Get the current color palette (which we must switch ; to a device other than the Z buffer to do, because ; TVLCT returns an error with the Z buffer device). set_plot,'PS' TVLCT, r, g, b, /Get set_plot,'Z' ; Save the image and color palette to the GIF file res=dc_write_image(path+filename, $ img, type='GIF', order=1, $ Colormap=TRANSPOSE([[r],[g],[b]])) END ; This is the main RPC server application. It simply loops ; forever calling UNIX_LISTEN(), waiting for a string to be ; passed to it from the RPC client app. When it gets the ; string it just passes it through the EXECUTE function ; (in most cases). ; PRO JAVA_SERVER ..locals 50 COMMON javacom, path, x, y @UT_COMMON ON_ERROR_GOTO, errtrap ; These commands will cause the server to add the REDRAW ; string in the reply to the RPC client, which will signal ; the Java applet to get a new copy of the graphic image. redraw_commands = [ $ 'ERASE', $ 'PLOT', $ 'PLOTS', $ 'CONTOUR', $ 'SURFACE', $ 'SHADE_SURF', $ 'LOADCT', $ 'TVLCT', $ 'AXIS', $ 'MAP', $ 'POLY', $ 'RENDER', $ 'SHOW3', $ 'TV', $ 'TVSCL', $ 'VECTOR_FIELD3', $ 'VEL', $ 'VELOVECT' ] ; These commands will not be allowed and an error ; message will be returned if used. Note: this ; list is NOT complete, and does not insure the ; security if run on a public network, but is ; probably secure enough for an intranet environment. ; Better security could be obtained by having a ; list of acceptable commands and restricting the ; server to only accept these. not_allowed = [ $ 'EXECUTE', $ 'HELP', $ 'SET_PLOT', $ 'WINDOW', $ 'WSET', $ 'WT', $ 'WW', $ 'WG', $ 'WZ', $ 'SPAWN', $ 'NAVIGATOR', $ 'DEMO' ] ; Default path to the log file and gif file, and the size of the gif file. path = '/www/jwave/wapplet/' x= 400 y= 350 ; Open the Z buffer set_plot,'Z' device,set_resolution=[x,y] ; Put a time stamp in the log file (for debugging) DT_TO_STR, today(), d, t, date_fm=1, time_fmt=-1 print,'Server started: ',d,' ',t print,'#' ; Loop till sent the command to shut down the server cmd = '' WHILE STRUPCASE(cmd) NE 'EXIT' DO BEGIN ; Wait for the server to be called cnt = UNIX_LISTEN() cmd = UT_PARAM0 ; UT_PARAM0 is in the UT_COMMON block and ; filled by UNIX_LISTEN() with a string from ; the RPC client app. ; Execute the passed command unless a shutdown message CASE STRUPCASE(cmd) OF 'EXIT': BEGIN ; Reply the status status = UNIX_REPLY("Bye-bye, leaving PV-WAVE...") device,/close END 'QUIT': BEGIN ; Reply the status status = UNIX_REPLY("Bye-bye, leaving PV-WAVE...") device,/close END ; Execute the command passed ELSE: BEGIN ; REDRAW is a special command send by the Redraw button in the ; applet to refresh the gif file. We don't need to echo this ; command, but will for anything else. upcmd = STRUPCASE(cmd) IF cmd NE 'REDRAW' THEN print,'WAVE> '+cmd ; Check for disallowed commands match = 0 FOR i=0, N_ELEMENTS(not_allowed)-1 DO $ IF STRMATCH(upcmd, not_allowed(i)) THEN match = 1 IF match EQ 0 THEN BEGIN ; This command is allowed ; Any color table commands require that we switch to a device ; other than the Z buffer. Else just EXECUTE the command. IF STRMATCH(upcmd,'LOADCT') OR STRMATCH(upcmd,'TVLCT') THEN BEGIN SET_PLOT, 'PS' status = EXECUTE(cmd) SET_PLOT, 'Z' ENDIF ELSE BEGIN status = EXECUTE(cmd) ENDELSE ; Check for calls requiring a redraw match = 0 FOR i=0, N_ELEMENTS(redraw_commands)-1 DO $ IF STRMATCH(upcmd, redraw_commands(i)) THEN match = 1 ; If this command requires a graphic update, then create ; a new GIF file by calling redraw, and add "REDRAW" to ; the log file which signals the applet to get a new copy ; and display it. IF match THEN BEGIN REDRAW print,'REDRAW' ENDIF ENDIF ELSE BEGIN ; This command is not allowed print, '% This command is not allowed for the applet version.' ENDELSE ; Get the output from wave and send it back as the reply ; to the RPC client. (It is a sting containing LF's) ; Truncate to the max string length allowed (by default) ; by the Wave RPC handler. wout = wave_output() IF STRLEN(wout) GT 450 THEN BEGIN wout = STRMID(wout,0,449) + $ '\012 % Max output for applet exceeded... \012' ENDIF status = UNIX_REPLY(wout) END ENDCASE ; Put a "#" character after the output from this command so that ; we can parse out the latest output from Wave when a new command ; comes in. print,'#' ENDWHILE GOTO, finis errtrap: PRINT, 'Error Encountered. Server Exiting...' finis: END