Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

CdgProcess.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## CdgProcess - interface for a cdgp process. 00013 ## This class wraps arround a cdgp command spawned in the background and tries 00014 ## to provide all you need to handle a cdgp job. The class communicates with 00015 ## the cdgp job connecting to its STDIN and reads back all its output on STDOUT. 00016 ## \ingroup YadaScheduler 00017 ## 00018 ## \author Michael Daum 00019 ## 00020 ## $Id: CdgProcess.tcl,v 1.14 2004/07/13 13:32:27 micha Exp $ 00021 ## ---------------------------------------------------------------------------- 00022 class CdgProcess { 00023 inherit Process 00024 00025 # variables ---------------------------------------------------------------- 00026 00027 ## the file where to store the xml output of the logfile 00028 public variable xmlFile "" 00029 00030 ## if you like to call cdgp with an init file (-i commandline option), put 00031 ## that filename in here. 00032 public variable initFile "" 00033 00034 ## binary copy usage. 00035 ## This flag indicates whether to use a private copy of the cdgp binary in a 00036 ## temp directory or not. 00037 public variable useCopy 0 00038 00039 ## binary location. 00040 ## This variable stores the absolute path to the cdgp binary that we wrap arround. 00041 public variable cdgp "" 00042 00043 constructor {args} {}; ## \type TclList 00044 destructor {} 00045 00046 00047 # methods ------------------------------------------------------------------ 00048 public method start {{command ""}}; ## \type TclString 00049 public method stop {} 00050 00051 }; 00052 00053 ## ---------------------------------------------------------------------------- 00054 ## constructor. 00055 ## This constructor builds a cdgp wrapper object. If you don't specify a 00056 ## cdgp binary yourself (with -cdgp "/here/it/is/cdgp"), we assume the binary 00057 ## to be in \c "$env(YADA_TMP)/cdgp-[pid]". 00058 ## ---------------------------------------------------------------------------- 00059 body CdgProcess::constructor {args} { 00060 global env 00061 00062 eval configure $args 00063 00064 # did we already provide a command or not 00065 if {$cdgp == ""} { 00066 if {$useCopy} { 00067 set cdgp "$env(YADA_TMP)/cdgp-[pid]" 00068 00069 # making a copy of the original cdgp 00070 exec cp $env(YADA_CDGP) $cdgp 00071 } else { 00072 set cdgp $env(YADA_CDGP) 00073 } 00074 } 00075 } 00076 00077 ## ---------------------------------------------------------------------------- 00078 ## destructor. 00079 ## Before we leave we remove the private copy of the cdgp binary iff \c useCopy 00080 ## is \c true. 00081 ## ---------------------------------------------------------------------------- 00082 body CdgProcess::destructor {} { 00083 00084 if {$useCopy} { 00085 # delete the binary which we made a copy of 00086 exec rm $cdgp 00087 } 00088 } 00089 00090 ## ---------------------------------------------------------------------------- 00091 ## start the cdgp process. 00092 ## This forks the cdgp in the background, which is actually done in Process::start(). 00093 ## \param command this lets you overwrite the command given in CdgProcess::cdgp. 00094 ## ---------------------------------------------------------------------------- 00095 body CdgProcess::start {{command ""}} { 00096 00097 # prepair the command line 00098 if {$command == ""} { 00099 if {![file exists $cdgp]} { 00100 return -1; 00101 } 00102 set command "$cdgp" 00103 } 00104 00105 if {$xmlFile != ""} { 00106 # strip off gz 00107 regsub {^(.*)\.gz$} $xmlFile {\1} clearXmlFile 00108 append command " -x $clearXmlFile" 00109 } 00110 00111 if {$initFile == ""} { 00112 append command " -i none" 00113 } else { 00114 append command " -i $initFile" 00115 } 00116 00117 # start the process 00118 set pid [chain $command] 00119 00120 return $pid 00121 } 00122 00123 ## ---------------------------------------------------------------------------- 00124 ## stop the cdgp process. 00125 ## This method stops a started cdgp process and gzips the xmllogfile. Afterwards 00126 ## Process::stop() is called to finalize everything. There the job scheduled 00127 ## to be \a consumed. 00128 ## ---------------------------------------------------------------------------- 00129 body CdgProcess::stop {} { 00130 00131 # compress xmlFile 00132 if {$xmlFile != ""} { 00133 regsub {^(.*)\.gz$} $xmlFile {\1} clearXmlFile 00134 if {[file exists $clearXmlFile]} { 00135 if {[catch {exec gzip -f $clearXmlFile} errMsg]} { 00136 print "ERROR: $errMsg\n$::errorInfo\n" 00137 } 00138 } 00139 } 00140 00141 # Process::stop and consume 00142 chain 00143 }

YADA 2.0-alpha (20 Oct 2004)