EgtGeneral 1.5c3 :

- modifiche a CmdParser per esecutori.
This commit is contained in:
Dario Sassi
2014-03-23 12:30:31 +00:00
parent 0690c2c7de
commit 32124ef079
3 changed files with 76 additions and 41 deletions
+64 -33
View File
@@ -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 ;
}
//----------------------------------------------------------------------------