メインページ   モジュール   名前空間一覧   クラス階層   アルファベット順一覧   構成   ファイル一覧   構成メンバ   ファイルメンバ   関連ページ    

TExecuteCommand.cc

解説を見る。
00001 // =====================================================================
00002 //  $Id: TExecuteCommand.cc,v 1.7 2004/03/07 10:30:28 goiwai Exp $
00003 //  $Name: CLDAQ-1-14-03 $
00004 //  $Log: TExecuteCommand.cc,v $
00005 //  Revision 1.7  2004/03/07 10:30:28  goiwai
00006 //  ROOTに組みこむためのおまじないマクロを埋めこみました。
00007 //  全てにおいて完全に動作するわけではありません。
00008 //
00009 //  Revision 1.6  2003/11/25 19:13:10  goiwai
00010 //  *** empty log message ***
00011 //
00012 //  Revision 1.5  2003/11/25 14:39:45  goiwai
00013 //  mutexで排他制御しないといけませんね.ちょっと謎です.
00014 //
00015 //  Revision 1.4  2003/11/25 13:43:22  goiwai
00016 //  とりあえず,ループ時の問題を解消しました.
00017 //  まだ満足に動きません.特にスリープするようなコマンドに対して.
00018 //
00019 //  Revision 1.3  2003/10/06 17:02:37  goiwai
00020 //  *** empty log message ***
00021 //
00022 //  Revision 1.2  2003/07/30 16:17:31  goiwai
00023 //  ファイルにコミットログをつけることにしました.
00024 //
00025 // =====================================================================
00026 #include "TExecuteCommand.hh"
00027 #include "TRunManager.hh"
00028 #include "TUserInterface.hh"
00029 
00030 static const Tstring _name = "/system/execute";
00031 static const Tstring _desc =
00032 "read a macro file, execute."
00033 "\n"
00034 "1st argument is filename, 2nd argument(omiitable) is a number of loop, you wish."
00035 "\n"
00036 "CLDAQ> /system/execute sample.macro"
00037 "\n"
00038 "CLDAQ> /system/execute sample.macro 100";
00039 
00040 TExecuteCommand::TExecuteCommand( TRunManager* manager )
00041   : TCommand( manager, _name, _desc ), theMacroFileParser()
00042 {;}
00043 
00044 TExecuteCommand::~TExecuteCommand()
00045 {;}
00046 
00047 Tvoid TExecuteCommand::Execute( const TstringList& arguments )
00048 {
00049   TUserInterface* ui = theRunManager -> GetUserInterface();
00050   static const Tstring head = "TExecuteCommand::Execute: ";
00051 
00052   if ( ui ) {
00053     if ( arguments.empty() ) {
00054       ShowCommandDetail();
00055     } else if ( arguments.size() == 1 ) {
00056       Tstring filename = arguments[ 0 ];
00057       doExecute( ui, filename );
00058     } else if ( arguments.size() == 2 ) {
00059       Tstring filename = arguments[ 0 ];
00060       Tint nloop = strtol( arguments[ 1 ].c_str(), 0, 0 );
00061       doExecute( ui, filename, nloop );
00062     } else {
00063       Tcerr << head << "number of arguments should be 1 or 2." << Tendl;
00064       ShowCommandDetail();
00065     }
00066   } else {
00067     Tcerr << head << "UserInterface doesn't exist." << Tendl;
00068   }
00069   return;
00070 }
00071 
00072 //まともに機能せず
00073 Tvoid TExecuteCommand::doExecute( TUserInterface* ui, const Tstring& filename, Tint nloop )
00074 {
00075   TMacroFileParser macro( filename );
00076   TstringList readbuf;
00077 
00078   for ( Tint i = 0; i < nloop; i ++ ) {
00079     macro.Open();
00080     while ( macro.IsSuccess() ) {
00081       readbuf = macro.ReadLine();
00082       if ( macro.IsExecutable( readbuf ) ) {
00083         Tstring command = macro.GetCommand( readbuf );
00084         TstringList args = macro.GetArguments( readbuf );
00085         ui -> ExecuteCommand( command, args );
00086 
00087 
00088         //TODO
00089         //マクロを実行するとダメ同期処理しないとだめなんかな?
00090         //CLDAQ_DEBUG(command.c_str());
00091         //for ( Tsize_t i = 0; i < args.size(); i ++ ) {
00092         //CLDAQ_DEBUG(args[i].c_str());
00093         //}
00094         // mutex で排他制御しなとかもしんないですね
00095         //usleep(1000*1000);  //sleep はさんだところでだめ
00096       }
00097     }
00098   }
00099   macro.Close();
00100 
00101   return;
00102 }
00103 
00104 #ifdef __CLDAQ_ROOT_DLL
00105     ClassImp(TExecuteCommand)
00106 #endif


CLDAQ - a Class Library for DataAcQuisition (Version 1.14.3)
Go IWAI -- goiwai at users.sourceforge.jp