; Copyright (c) 2000, Perforce Software, All rights reserved. ; ; This software was originally developed by Silicon Graphics, Inc (SGI). ; ; Redistribution and use in source and binary forms, with or ; without modification, are permitted provided that the following ; conditions are met: ; ; Redistributions of source code must retain the above copyright notice, ; this list of conditions and the following disclaimer. ; ; Redistributions in binary form must reproduce the above copyright ; notice, this list of conditions and the following disclaimer in the ; documentation and/or other materials provided with the distribution. ; ; Neither name of Perforce Software nor SGI nor the names of its ; contributors may be used to endorse or promote products derived from ; this software without specific prior written permission. ; ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ; ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. procedure(CDS_P4IPCDirectCommand(command) ;_Jul 25 00 sikand 320 ;; front end caller for direct ipc calls ;; unbuffered ;; piping handled by stdHandler in BeginDirectProcess let((child) CDS_P4IPCBeginDirectProcess(command) ipcWait(CDS_P4IPCProc) status = ipcGetExitStatus(CDS_P4IPCProc) ;; ugly 0 ) ; ** let ** ) ; ** procedure CDS_P4IPCDirectCommand ** procedure(CDS_P4IPCCommand(command) ;_Jun 17 99 sikand 94 ;; equivalent to a buffered skillserver command CDS_P4IPCBeginProcess(command) ) ; ** procedure CDS_P4IPCDirectCommand ** procedure(CDS_P4IPCBeginProcess(command) ;; command thru the server, buffered let( (pcommand) if( CDS_P4CurrentClient then pcommand = strcat("-c " CDS_P4CurrentClient " " command "\n") else pcommand = strcat(command "\n") ) ;;printf("Executing %s",pcommand) CDS_P4ServerBufferCommand(pcommand) ) ; ** let ** ) ; ** procedure CDS_P4IPCBeginProcess ** procedure(CDS_P4IPCBeginDirectProcess(command ;_Apr 4 00 sikand 342 @key (stdHandler "CDS_P4IPCLog") (errHandler "CDS_P4Error") (doneFunc "") (logFile "")) ;; execute the command directly without saving output in buffer let( (pcommand) if( CDS_P4CurrentClient then pcommand = strcat("p4 -c " CDS_P4CurrentClient " " command) else pcommand = strcat("p4 " command) ) CDS_P4IPCProc = ipcBeginProcess(pcommand "" stdHandler errHandler doneFunc logFile) ) ) ; ** procedure CDS_P4IPCBeginDirectProcess ** procedure(CDS_P4IPCLog(childId data) ;_Jun 17 99 sikand 121 ;;fprintf(CDS_P4Port "%s" data) ;drain(CDS_P4Port) ;; NO action for now, too noisy t ) procedure(CDS_P4IPCError(childId data) ;_Jun 17 99 sikand 121 ;;fprintf(CDS_P4Port "%s" data) ;drain(CDS_P4Port) ;; NO action for now, too noisy printf("Message: %s\n" data) t ) procedure(CDS_P4IPCDirectBufferProcess(command ;_Jul 25 00 sikand 529 @key (stdHandler "CDS_P4IPCAssignToGlobal") (errHandler "CDS_P4IPCAssignToGlobal") (doneFunc "") (logFile "")) ;; execute a command directly, and store the output in the ;; buffer let((child pcommand) ;; clear the buffer CDS_IPCBuffer= nil pcommand = strcat("p4 " command) child = ipcBeginProcess(pcommand "" stdHandler errHandler doneFunc logFile) ipcWait(child) ;;ipcGetExitStatus(child) ;; ugly 0 ) ; ** let ** ) ; ** procedure CDS_P4IPCDirectBufferProcess ** procedure(CDS_P4IPCBufferProcess(command) ;; communicate with the skillserver as a buffered read let((child pcommand) ;; clear the buffer if( CDS_P4CurrentClient then pcommand = strcat("-c " CDS_P4CurrentClient " " command "\n") else pcommand = strcat(command "\n") ) ;;printf("Executing %s",pcommand) CDS_P4ServerBufferCommand(pcommand) ) ; ** let ** ) ; ** procedure CDS_P4IPCBufferProcess ** procedure(CDS_P4IPCAssignToGlobal(childId data) ;_Jun 17 99 sikand 0 let((temp) if( CDS_IPCBuffer then temp = strcat(CDS_IPCBuffer data) CDS_IPCBuffer = temp else CDS_IPCBuffer =data ) ; ** if CDS_IPCBuffer ** ;;fprintf(CDS_P4Port "Buffer: %s" data) ;drain(CDS_P4Port) ) ; ** let ** ) ; ** procedure CDS_P4IPCAssignToGlobal ** procedure(CDS_P4IPCAssignToGlobalQ(childId data) ;_Jun 17 99 sikand 0 let((temp) if( CDS_IPCBuffer then temp = strcat(CDS_IPCBuffer data) CDS_IPCBuffer = temp else CDS_IPCBuffer= data ) ; ** if CDS_IPCBuffer ** ) ; ** let ** ) ; ** procedure CDS_P4IPCAssignToGlobalQ ** procedure(CDS_P4ServerBufferCommand(cmd) ;_Mar 24 00 sikand 158 prog((child data) child = CDS_P4ServerId CDS_IPCBuffer = "" CDS_P4rawcount = 0 ;; need to flush the buffer in the client ;; since it may not be empty ;; if a previous read failed due to a trigger ;; call to 'error' for example ;; so do a set of non blocking reads ;; assumption: the client has acutally finished the previous ;; command in question by the time we return here ;; ....if not, it could get a bit ugly ;; since the buffer won't have flushed correctly while( (data = ipcReadProcess(child)) != "" t ) rexCompile("p4skillservercmddone") ;;printf("Writing server %s" cmd) unless( ipcWriteProcess(child cmd) return() ) return(CDS_P4ReadData(child)) ;;printf("G %s\n", CDS_IPCBuffer) ) ; ** prog ** ) ; ** procedure CDS_P4ServerBufferCommand ** procedure(CDS_P4ReadDataBuff(child) ;_Jun 29 01 sikand 885 prog((x y error) CDS_P4IPCError = nil error=nil ;; 30 second blocking default x = ipcReadProcess(child 30) when( x ;;printf("Raw: %s\n" x) if( x == "" then CDS_P4rawcount++ else CDS_P4rawcount = 0 ) when( CDS_P4rawcount > 30 CDS_P4rawcount = 0 error("FATAL: Failed to communicate or massive data overrun!") ) ;;printf("End of raw\n") ;; ;; rely on rexCompile from ServerBufferCommand if( rexExecute(x) then ;;x = rexReplace(x "" 1) when( rexMatchp("p4skillservercmddoneerr" x) rexCompile("p4skillservercmddoneerr") y = rexReplace(x "" 1) CDS_IPCBuffer = strcat(CDS_IPCBuffer y) ;;when( CDS_P4Debug ;;warn("p4skillserver command completed with errors!") printf("\np4: %s\n" CDS_IPCBuffer) ;;) error=t ;; all error trapping disabled ;; ugly ;;CDS_P4IPCError = nil ;;return(t) ) ; ** when rexMatchp ** if(error then rexCompile("p4skillservercmddoneerr") error=nil else rexCompile("p4skillservercmddone") ) y = rexReplace(x "" 1) CDS_IPCBuffer = strcat(CDS_IPCBuffer y) return(nil) ) ; ** if rexMatchp ** CDS_IPCBuffer = strcat(CDS_IPCBuffer x) ) ; ** when x ** return(t) ) ; ** let ** ) ; ** procedure CDS_P4ReadDataBuff ** procedure(CDS_P4ReadData(child) ;_Jul 25 00 sikand 194 prog(() while( CDS_P4ReadDataBuff(child) t ) ;;printf("info: %d buffered reads\n" b) if( CDS_P4IPCError then CDS_P4IPCError = nil return(1) else return(0) ) ) ; ** let ** ) ; ** procedure CDS_P4Read_data **