![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /Framework/src/APPSequenceCommand.cc
Go to the documentation of this file.00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: APPSequenceCommand.cc,v 1.25 2002/03/28 22:04:47 desilva Exp $ 00004 // 00005 // Description: 00006 // Class APPSequenceCommand. Command handler for the "sequence" command 00007 // for the BaBar Application Framework. Valid subcommands are: 00008 // 00009 // sequence append <seq> <mod1> [<seq1>..] Append module(s)/sequence(s) 00010 // sequence create <seq> <mod1> [<seq2>..] Create a new sequence 00011 // sequence delete <seq> Delete a sequence 00012 // sequence disable <seq1> [<path2> ..] Disable sequence(s) 00013 // sequence enable <seq1> [<path2> ..] Enable sequence(s) 00014 // sequence help Show help for this command 00015 // sequence insert <seq> <mod1> [<seq1>..] Insert module(s)/sequence(s) 00016 // sequence list List sequence 00017 // sequence remove <seq> <mod1> [<seq1>..] Remove module(s)/sequence(s) 00018 // 00019 // Environment: 00020 // Software developed for the BaBar Detector at the SLAC B-Factory. 00021 // 00022 // Author List: 00023 // David R. Quarrie Original Author 00024 // Marc Turcotte Merged in TK interface 5/15/98 00025 // Marc Turcotte Improved error reporting to 00026 // name already in use. 7/1/98 00027 // Marc Turcotte Added wrap around TK calls. 8/24/98 00028 // 00029 // Copyright Information: 00030 // Copyright (C) 1994, 1995 Lawrence Berkeley Laboratory 00031 // Copyright (C) 1998 University of Texas at Dallas 00032 // 00033 //------------------------------------------------------------------------ 00034 #include "Experiment/Experiment.hh" 00035 00036 //----------------------- 00037 // This Class's Header -- 00038 //----------------------- 00039 #include "Framework/APPSequenceCommand.hh" 00040 00041 //------------- 00042 // C Headers -- 00043 //------------- 00044 #include <assert.h> 00045 #include <string.h> 00046 00047 //------------------------------- 00048 // Collaborating Class Headers -- 00049 //------------------------------- 00050 #include "Framework/APPFramework.hh" 00051 #include "Framework/APPModule.hh" 00052 #include "Framework/APPSequence.hh" 00053 #include "Framework/APPExecNode.hh" 00054 #include "Framework/APPNameNode.hh" 00055 #include "FrameUtil/AbsInterp.hh" 00056 00057 #include "FrameUtil/APPList.hh" 00058 #include "FrameUtil/APPListIterator.hh" 00059 00060 // ---------------------------------------- 00061 // -- Public Function Member Definitions -- 00062 // ---------------------------------------- 00063 00064 //---------------- 00065 // Constructors -- 00066 //---------------- 00067 00068 APPSequenceCommand::APPSequenceCommand( 00069 const char* const theCommand, AppModule* theTarget ) 00070 : APPBasicCommand( theCommand, theTarget ) 00071 { 00072 } 00073 00074 //-------------- 00075 // Destructor -- 00076 //-------------- 00077 00078 APPSequenceCommand::~APPSequenceCommand( ) 00079 { 00080 } 00081 00082 00083 // ------------------------------------------- 00084 // -- Protected Function Member Definitions -- 00085 // ------------------------------------------- 00086 00087 int 00088 APPSequenceCommand::appendHandler( ) 00089 { 00090 AppFramework* theFrame = (AppFramework*)target( ); 00091 APPNameNode* theNode = NULL; 00092 APPNameNode* otherNode = NULL; 00093 char* theName; 00094 APPExecutable* theExec; 00095 APPExecutable* theOther = NULL; 00096 APPSequence* theSeq; 00097 int index = firstIndex; 00098 int result = AbsInterp::ERROR; 00099 00100 if ( NULL != ( theName = getArgument( index ) ) ) { 00101 if ( NULL != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00102 index++; 00103 while( NULL != ( theName = getArgument( index ) ) ) { 00104 if ( 0 == strcmp( theName, "-after" ) || 00105 0 == strcmp( theName, "-a" ) ) { 00106 index++; 00107 if ( NULL != otherNode ) { 00108 delete otherNode; 00109 } 00110 otherNode = getNameNode( &index ); 00111 if ( NULL != otherNode ) { 00112 theOther = theFrame->execFromName( otherNode->name( ) ); 00113 } 00114 } 00115 if ( NULL != theNode) { 00116 delete theNode; 00117 } 00118 if ( NULL != ( theNode = getNameNode( &index ) ) ) { 00119 theExec = theFrame->execFromName( theNode->name( ) ); 00120 if ( NULL != theExec ) { 00121 if ( NULL == theOther ) { 00122 theSeq->append( theExec, theNode->mode( ) ); 00123 } else { 00124 theSeq->append( 00125 theExec, 00126 theNode->mode( ), 00127 theOther, otherNode->mode( ) ); 00128 // Setup the just appended node to be append after 00129 delete otherNode; 00130 otherNode = theNode; 00131 theNode = 0; 00132 theOther = theExec; 00133 } 00134 } else { 00135 FwkString theSeqName(theName); 00136 FwkString theTrailer(": unknown name"); 00137 FwkString theMessage=theSeqName+theTrailer; 00138 theFrame->setError( theMessage.c_str() ); 00139 } 00140 } 00141 } 00142 if ( NULL != theNode ) { 00143 delete theNode; 00144 } 00145 if ( NULL != otherNode ) { 00146 delete otherNode; 00147 } 00148 result = AbsInterp::OK; 00149 } else { 00150 FwkString theSeqName(theName); 00151 FwkString theTrailer(": unknown name"); 00152 FwkString theMessage=theSeqName+theTrailer; 00153 theFrame->setError( theMessage.c_str() ); 00154 } 00155 } else { 00156 theFrame->setError( "no name specified" ); 00157 } 00158 return result; 00159 } 00160 00161 int 00162 APPSequenceCommand::createHandler( ) 00163 { 00164 AppFramework* theFrame = (AppFramework*)target( ); 00165 APPNameNode* theNode; 00166 char* theName; 00167 APPExecutable* theExec; 00168 APPSequence* theSeq = NULL; 00169 int index = firstIndex; 00170 int result = AbsInterp::ERROR; 00171 00172 if ( NULL != ( theName = getArgument( index ) ) ) { 00173 if ( NULL != ( theSeq = newSeq( theFrame, theName ) ) ) { 00174 index++; 00175 while( NULL != ( theNode = getNameNode( &index ) ) ) { // new happens 00176 theExec = theFrame->execFromName( theNode->name( ) ); 00177 if ( NULL != theExec ) { 00178 theSeq->append( theExec, theNode->mode( ) ); 00179 } else { 00180 FwkString theSeqName(theName); 00181 FwkString theTrailer(": unknown name"); 00182 FwkString theMessage=theSeqName+theTrailer; 00183 theFrame->setError( theMessage.c_str() ); 00184 } 00185 delete theNode; 00186 } 00187 result = AbsInterp::OK; 00188 } else { 00189 FwkString theSeqName(theName); 00190 FwkString theTrailer(": name already in use"); 00191 FwkString theMessage=theSeqName+theTrailer; 00192 theFrame->setError( theMessage.c_str() ); 00193 } 00194 } else { 00195 theFrame->setError( "no name specified" ); 00196 } 00197 return result; 00198 } 00199 00200 int 00201 APPSequenceCommand::deleteHandler( ) 00202 { 00203 AppFramework* theFrame = (AppFramework*)target( ); 00204 char* theName; 00205 APPSequence* theSeq; 00206 int index = firstIndex; 00207 int result = AbsInterp::ERROR; 00208 00209 while ( NULL != ( theName = getArgument( index ) ) ) { 00210 if ( NULL != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00211 theFrame->remove( theSeq ); 00212 delete theSeq; // ownership is given up by APPFramework 00213 result = AbsInterp::OK; 00214 } else { 00215 FwkString theSeqName(theName); 00216 FwkString theTrailer(": unknown name"); 00217 FwkString theMessage=theSeqName+theTrailer; 00218 theFrame->setError( theMessage.c_str() ); 00219 } 00220 index++; 00221 } 00222 return result; 00223 } 00224 00225 int 00226 APPSequenceCommand::disableHandler( ) 00227 { 00228 AppFramework* theFrame = (AppFramework*)target( ); 00229 char* theName; 00230 APPSequence* theSeq; 00231 int index = firstIndex; 00232 int result = AbsInterp::ERROR; 00233 00234 while ( NULL != ( theName = getArgument( index ) ) ) { 00235 00236 if ( NULL != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00237 theSeq->setEnabled( false ); 00238 result = AbsInterp::OK; 00239 00240 } else if ( 0 == strcmp(theName, "all") ) { 00241 APPList< APPSequence* >* sequences; 00242 sequences = fetchSeqs( theFrame ); 00243 if ( ! sequences->isEmpty( ) ) { 00244 APPSequence** aSeq; 00245 APPListIterator<APPSequence*> theIterator( *sequences ); 00246 while ( aSeq = theIterator( ) ) { 00247 (*aSeq)->setEnabled( false ); 00248 result = AbsInterp::OK; 00249 } 00250 } 00251 00252 } else { 00253 FwkString theSeqName(theName); 00254 FwkString theTrailer(": unknown name"); 00255 FwkString theMessage=theSeqName+theTrailer; 00256 theFrame->setError( theMessage.c_str() ); 00257 result = AbsInterp::ERROR; 00258 return result; 00259 } 00260 00261 index++; 00262 } 00263 return result; 00264 } 00265 00266 int 00267 APPSequenceCommand::enableHandler( ) 00268 { 00269 AppFramework* theFrame = (AppFramework*)target( ); 00270 char* theName; 00271 APPSequence* theSeq; 00272 int index = firstIndex; 00273 int result = AbsInterp::ERROR; 00274 00275 while ( NULL != ( theName = getArgument( index ) ) ) { 00276 00277 if ( NULL != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00278 theSeq->setEnabled( true ); 00279 result = AbsInterp::OK; 00280 00281 } else if ( 0 == strcmp(theName, "all") ) { 00282 APPList< APPSequence* >* sequences; 00283 sequences = fetchSeqs( theFrame ); 00284 if ( ! sequences->isEmpty( ) ) { 00285 APPListIterator<APPSequence*> theIterator( *sequences ); 00286 APPSequence** aSeq; 00287 while ( aSeq = theIterator( ) ) { 00288 (*aSeq)->setEnabled( true ); 00289 result = AbsInterp::OK; 00290 } 00291 } 00292 00293 } else { 00294 FwkString theSeqName(theName); 00295 FwkString theTrailer(": unknown name"); 00296 FwkString theMessage=theSeqName+theTrailer; 00297 theFrame->setError( theMessage.c_str() ); 00298 result = AbsInterp::ERROR; 00299 return result; 00300 } 00301 index++; 00302 } 00303 return result; 00304 } 00305 00306 int 00307 APPSequenceCommand::helpHandler( ) 00308 { 00309 AppFramework* theFrame = (AppFramework*)target( ); 00310 00311 APPBasicCommand::helpHandler( ); 00312 00313 theFrame->partialReport( " append <seq> [-a(fter) <mod/seq>] "); 00314 theFrame->fullReport("<mod1/seq1> [<mod2/seq2> ..]"); 00315 theFrame->partialReport( " " ); 00316 theFrame->fullReport("Append module(s)/sequence(s)"); 00317 00318 theFrame->partialReport( " create <seq> [<mod1/seq1> ..] " ); 00319 theFrame->fullReport("Create a new sequence"); 00320 00321 theFrame->partialReport( " delete <seq1> [<seq2> ..] " ); 00322 theFrame->fullReport("Delete sequence(s)"); 00323 00324 theFrame->partialReport( " disable <seq1> [<seq2> ..] " ); 00325 theFrame->fullReport("Disable sequence(s)*"); 00326 00327 theFrame->partialReport( " enable <seq1> [<seq2> ..] " ); 00328 theFrame->fullReport("Enable sequence(s)*"); 00329 00330 theFrame->partialReport( " help " ); 00331 theFrame->fullReport("Show available commands"); 00332 00333 theFrame->partialReport( " insert <seq> [-b(efore) <mod/seq>] " ); 00334 theFrame->fullReport("<mod1/seq1> [<mod2/seq2> ..]"); 00335 theFrame->partialReport( " " ); 00336 theFrame->fullReport("Insert module(s)/sequence(s)"); 00337 00338 theFrame->partialReport( " list " ); 00339 theFrame->fullReport("List sequence(s)"); 00340 00341 theFrame->fullReport( " remove <seq> <mod1/seq1> [<mod2/seq2> ..] " ); 00342 theFrame->partialReport( " " ); 00343 theFrame->fullReport("Remove module(s)/sequence(s)"); 00344 00345 theFrame->fullReport(" "); 00346 theFrame->fullReport("* = 'all' can be used in place of <seq1>."); 00347 00348 return AbsInterp::OK; 00349 00350 } 00351 00352 int 00353 APPSequenceCommand::insertHandler( ) 00354 { 00355 AppFramework* theFrame = (AppFramework*)target( ); 00356 APPNameNode* theNode=0; 00357 APPNameNode* otherNode =0; 00358 char* theName=0; 00359 APPExecutable* theExec=0; 00360 APPExecutable* theOther =0; 00361 APPSequence* theSeq=0; 00362 APPExecNode* first=0; 00363 int index = firstIndex; 00364 int result = AbsInterp::ERROR; 00365 00366 if ( 0 != ( theName = getArgument( index ) ) ) { 00367 if ( 0 != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00368 index++; 00369 while( 0 != ( theName = getArgument( index ) ) ) { 00370 if ( 0 == strcmp( theName, "-before" ) || 00371 0 == strcmp( theName, "-b" ) ) { 00372 index++; 00373 if ( 0 != otherNode ) { 00374 delete otherNode; 00375 } 00376 otherNode = getNameNode( &index ); 00377 if ( 0 != otherNode ) { 00378 theOther = theFrame->execFromName( otherNode->name( ) ); 00379 } 00380 } 00381 if ( 0 != ( theNode = getNameNode( &index ) ) ) { 00382 theExec = theFrame->execFromName( theNode->name( ) ); 00383 if ( 0 != theExec ) { 00384 first = theSeq->head( ); 00385 if ( 0 == theOther ) { 00386 if (0 != first) { 00387 theOther =first->target( ); 00388 otherNode = new APPNameNode ( 00389 theOther->name( ), 00390 first->mode( ) ); 00391 } 00392 } 00393 if (0 != first) { 00394 theSeq->insert( 00395 theExec, 00396 theNode->mode( ), 00397 theOther, otherNode->mode( ) ); 00398 } 00399 else { 00400 theSeq->insert(theExec, theNode->mode()); 00401 } 00402 } else { 00403 FwkString theSeqName(theName); 00404 FwkString theTrailer(": unknown name"); 00405 FwkString theMessage=theSeqName+theTrailer; 00406 theFrame->setError( theMessage.c_str() ); 00407 } 00408 } 00409 delete theNode; 00410 } 00411 if ( 0 != otherNode ) { 00412 delete otherNode; 00413 } 00414 result = AbsInterp::OK; 00415 } else { 00416 FwkString theSeqName(theName); 00417 FwkString theTrailer(": unknown name"); 00418 FwkString theMessage=theSeqName+theTrailer; 00419 theFrame->setError( theMessage.c_str() ); 00420 } 00421 } else { 00422 theFrame->setError( "no name specified" ); 00423 } 00424 return result; 00425 } 00426 00427 int 00428 APPSequenceCommand::listHandler( ) 00429 { 00430 AppFramework* theFrame = (AppFramework*)target( ); 00431 APPSequence** seq; 00432 APPList< APPSequence* >* sequences; 00433 00434 sequences = fetchSeqs( theFrame ); 00435 if ( ! sequences->isEmpty( ) ) { 00436 APPListIterator<APPSequence*> theIterator( *sequences ); 00437 while ( seq = theIterator( ) ) { 00438 (*seq)->report( ); 00439 } 00440 } else { 00441 theFrame->fullReport( " None defined" ); 00442 } 00443 return AbsInterp::OK; 00444 } 00445 00446 int 00447 APPSequenceCommand::removeHandler( ) 00448 { 00449 AppFramework* theFrame = (AppFramework*)target( ); 00450 APPNameNode* theNode; 00451 char* theName; 00452 APPExecutable* theExec; 00453 APPSequence* theSeq; 00454 int index = firstIndex; 00455 int result = AbsInterp::ERROR; 00456 00457 if ( NULL != ( theName = getArgument( index ) ) ) { 00458 if ( NULL != ( theSeq = fetchSeq( theFrame, theName ) ) ) { 00459 index++; 00460 while( NULL != ( theNode = getNameNode( &index ) ) ) { 00461 theExec = theFrame->execFromName( theNode->name( ) ); 00462 if ( NULL != theExec ) { 00463 theSeq->remove( theExec, theNode->mode( ) ); 00464 } else { 00465 FwkString theSeqName(theName); 00466 FwkString theTrailer(": unknown name"); 00467 FwkString theMessage=theSeqName+theTrailer; 00468 theFrame->setError( theMessage.c_str() ); 00469 } 00470 delete theNode; 00471 } 00472 result = AbsInterp::OK; 00473 } else { 00474 FwkString theSeqName(theName); 00475 FwkString theTrailer(": name already in use"); 00476 FwkString theMessage=theSeqName+theTrailer; 00477 theFrame->setError( theMessage.c_str() ); 00478 } 00479 } else { 00480 theFrame->setError( "no name specified" ); 00481 } 00482 return result; 00483 } 00484 00485 APPSequence* 00486 APPSequenceCommand::fetchSeq( 00487 AppFramework* theFrame, 00488 const char* const theName ) 00489 { 00490 return theFrame->fetchSequence( theName ); 00491 } 00492 00493 APPSequence* 00494 APPSequenceCommand::newSeq( 00495 AppFramework* theFrame, 00496 const char* const theName ) 00497 { 00498 APPSequence* result = NULL; 00499 if ( ! theFrame->has( theName ) ) { 00500 result = new APPSequence( theName, NULL ); 00501 theFrame->add( result ); 00502 } 00503 return result; 00504 } 00505 00506 APPList< APPSequence* >* 00507 APPSequenceCommand::fetchSeqs( AppFramework* theFrame ) 00508 { 00509 return theFrame->sequences( ); 00510 } 00511 00512 FwkString 00513 APPSequenceCommand::description( ) const 00514 { 00515 return "Command used to create, modify and control sequences"; 00516 } 00517 00518 void 00519 APPSequenceCommand::show( ) const 00520 { 00521 } 00522 bool 00523 APPSequenceCommand::isShowable( ) const 00524 { 00525 return false; 00526 }
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002