From 32124ef0792221e82da8feca16bbc379a025984c Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Sun, 23 Mar 2014 12:30:31 +0000 Subject: [PATCH] EgtGeneral 1.5c3 : - modifiche a CmdParser per esecutori. --- CmdParser.cpp | 97 +++++++++++++++++++++++++++++++++----------------- CmdParser.h | 20 ++++++----- EgtGeneral.rc | Bin 11630 -> 11630 bytes 3 files changed, 76 insertions(+), 41 deletions(-) diff --git a/CmdParser.cpp b/CmdParser.cpp index 924614e..27b98a5 100644 --- a/CmdParser.cpp +++ b/CmdParser.cpp @@ -33,8 +33,17 @@ CreateCmdParser( void) //---------------------------------------------------------------------------- CmdParser::CmdParser( void) - : m_pTheExecutor( nullptr), m_nLev( 0) { + m_nLev = 0 ; + // assegno chiavi a funzioni di esecuzione + m_ExecMgr.Init( 16) ; + m_ExecMgr.Insert( "COUNTER", &CmdParser::ExecuteCounter) ; + m_ExecMgr.Insert( "DIR", &CmdParser::ExecuteDir) ; + m_ExecMgr.Insert( "FILE", &CmdParser::ExecuteFile) ; + m_ExecMgr.Insert( "PAUSE", &CmdParser::ExecutePause) ; + m_ExecMgr.Insert( "RESET", &CmdParser::ExecuteReset) ; + m_ExecMgr.Insert( "RUN", &CmdParser::ExecuteRun) ; + m_ExecMgr.Insert( "SET", &CmdParser::ExecuteSet) ; } //---------------------------------------------------------------------------- @@ -44,16 +53,43 @@ CmdParser::~CmdParser( void) //---------------------------------------------------------------------------- bool -CmdParser::Init( ICmdExecutor* pCmdExec) +CmdParser::SetExecutor( ICmdExecutor* pCmdExec) +{ + // pulisco lista esecutori + m_CmdExecList.clear() ; + + // verifico la validità dell'esecutore + if ( pCmdExec == nullptr) + return false ; + + // salvo il riferimento all'esecutore e mi registro + try { m_CmdExecList.push_back( pCmdExec) ; } + catch(...) { return false ; } + pCmdExec->SetCmdParser( this) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +CmdParser::AddExecutor( ICmdExecutor* pCmdExec) { // verifico la validità dell'esecutore if ( pCmdExec == nullptr) return false ; // salvo il riferimento all'esecutore e mi registro - m_pTheExecutor = pCmdExec ; - m_pTheExecutor->SetCmdParser( this) ; + try { m_CmdExecList.push_back( pCmdExec) ; } + catch(...) { return false ; } + pCmdExec->SetCmdParser( this) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +CmdParser::Init( void) +{ // reimposto le variabili ResetAllVariables() ; @@ -209,10 +245,13 @@ CmdParser::ResetAllVariables( void) m_NameMap.clear() ; m_NameMap.rehash( 100) ; // installo variabili standard - if ( m_pTheExecutor != nullptr) - return m_pTheExecutor->AddStandardVariables() ; - else - return true ; + PCmdExecList::iterator Iter ; + for ( Iter = m_CmdExecList.begin() ; Iter != m_CmdExecList.end() ; ++ Iter) { + if ( (*Iter) == nullptr || + ! (*Iter)->AddStandardVariables()) + return false ; + } + return true ; } //---------------------------------------------------------------------------- @@ -232,13 +271,8 @@ CmdParser::GetInitSpaces( void) bool CmdParser::ExecCommand( const string& sCmd, const string& sParams) { - string sCmd1 ; - string sCmd2 ; - STRVECTOR vsParams ; - STRVECTOR::iterator Iter ; - - // divido il comando e lo normalizzo + string sCmd1, sCmd2 ; SplitFirst( sCmd, ".", sCmd1, sCmd2) ; Trim( sCmd1) ; ToUpper( sCmd1) ; @@ -246,7 +280,9 @@ CmdParser::ExecCommand( const string& sCmd, const string& sParams) ToUpper( sCmd2) ; // divido i parametri + STRVECTOR vsParams ; Tokenize( sParams, ",", "(", ")", vsParams) ; + STRVECTOR::iterator Iter ; for ( Iter = vsParams.begin() ; Iter != vsParams.end() ; ++ Iter) Trim( (*Iter)) ; @@ -263,25 +299,20 @@ CmdParser::ExecCommand( const string& sCmd, const string& sParams) sOut += ")" ; LOG_DBG_INFO( GetEGnLogger(), sOut.c_str()) - // eseguo il comando con i suoi parametri - if ( sCmd1 == "COUNTER") - return ExecuteCounter( sCmd2, vsParams) ; - else if ( sCmd1 == "DIR") - return ExecuteDir( sCmd2, vsParams) ; - else if ( sCmd1 == "FILE") - return ExecuteFile( sCmd2, vsParams) ; - else if ( sCmd1 == "PAUSE") - return ExecutePause( sCmd2, vsParams) ; - else if ( sCmd1 == "RESET") - return ExecuteReset( sCmd2, vsParams) ; - else if ( sCmd1 == "RUN") - return ExecuteRun( sCmd2, vsParams) ; - else if ( sCmd1 == "SET") - return ExecuteSet( sCmd2, vsParams) ; - else if ( m_pTheExecutor != nullptr) - return m_pTheExecutor->Execute( sCmd1, sCmd2, vsParams) ; - else - return false ; + // eseguo il comando cercando nell'esecutore di comandi locale + int nRes = m_ExecMgr.Execute( *this, sCmd1, sCmd2, vsParams) ; + if ( nRes != ER_MISSING) + return ( nRes == ER_OK) ; + // eseguo il comando cercando negli esecutori di comandi installati + PCmdExecList::iterator IterCEL ; + for ( IterCEL = m_CmdExecList.begin() ; IterCEL != m_CmdExecList.end() ; ++ IterCEL) { + if ( (*IterCEL) == nullptr) + return false ; + nRes = (*IterCEL)->Execute( sCmd1, sCmd2, vsParams) ; + if ( nRes != ER_MISSING) + return ( nRes == ER_OK) ; + } + return false ; } //---------------------------------------------------------------------------- diff --git a/CmdParser.h b/CmdParser.h index 7904134..9a84672 100644 --- a/CmdParser.h +++ b/CmdParser.h @@ -17,20 +17,22 @@ #include "/EgtDev/Include/EgtPerfCounter.h" #include "/EgtDev/Include/EgnStringBase.h" #include "/EgtDev/Include/EgnCmdParser.h" -#include +#include "/EgtDev/Include/EgtExecMgr.h" //---------------------------------------------------------------------------- class CmdParser : public ICmdParser { public : // ICmdParser virtual ~CmdParser( void) ; - virtual bool Init( ICmdExecutor* pCmdExec) ; - virtual bool Run( const std::string& sCmdFile, bool bIsolated = true) ; - virtual bool ExecLine( const std::string& sCmdLine, bool bIsolated = false) ; + virtual bool Init( void) ; + virtual bool SetExecutor( ICmdExecutor* pCmdExec) ; + virtual bool AddExecutor( ICmdExecutor* pCmdExec) ; virtual bool AddVariable( const std::string& sName, int nVal) ; virtual bool SetVariable( const std::string& sName, int nVal) ; virtual bool GetVariable( const std::string& sName, int& nVal) ; virtual bool RemoveVariable( const std::string& sName) ; + virtual bool Run( const std::string& sCmdFile, bool bIsolated = true) ; + virtual bool ExecLine( const std::string& sCmdLine, bool bIsolated = false) ; public : CmdParser( void) ; @@ -49,11 +51,13 @@ class CmdParser : public ICmdParser bool GetNamesParam( const std::string& sParam, STRVECTOR& vsNames) ; private : + typedef std::list PCmdExecList ; typedef std::unordered_map NameMap ; private : - ICmdExecutor* m_pTheExecutor ; - NameMap m_NameMap ; - int m_nLev ; - PerformanceCounter m_Counter ; + PCmdExecList m_CmdExecList ; + NameMap m_NameMap ; + ExecManager m_ExecMgr ; + int m_nLev ; + PerformanceCounter m_Counter ; } ; diff --git a/EgtGeneral.rc b/EgtGeneral.rc index dc23dee62594e5e187ec8d33a8f951879527626a..0b766d67016de83fd48fe13521f0fbf0806f0cc2 100644 GIT binary patch delta 86 zcmaDC^)70|H#SD&&8x*uGfj?D3<5GYDrPcnuH$xL1`At)sEvy0jGI%0-Oz=6q@hAc In)h-806PF2_5c6? delta 86 zcmaDC^)70|H#SD2&8x*uGfj?D3<5GYDrPcnuH$xL1`At)sEvy0jGI%0-Oz=6q@hAc In)h-806DN6?f?J)