Ejemplo n.º 1
0
//++ ------------------------------------------------------------------------------------
// Details:	Interpret the text data and match against current commands to see if there 
//			is a match. If a match then the command is issued and actioned on. If a
//			command cannot be found to match then vwbCmdYesValid is set to false and
//			nothing else is done here.
//			This function is used by the application's main thread.
// Type:	Method.
// Args:	vTextLine			- (R) Text data representing a possible command.
//			vwbCmdYesValid		- (W) True = Command invalid, false = command acted on.
// Return:	MIstatus::success - Functional succeeded.
//			MIstatus::failure - Functional failed.
// Throws:	None.
//--
bool CMIDriver::InterpretCommandThisDriver( const CMIUtilString & vTextLine, bool & vwbCmdYesValid )
{
	vwbCmdYesValid = false;

	bool bCmdNotInCmdFactor = false;
	SMICmdData cmdData;
	CMICmdMgr & rCmdMgr = CMICmdMgr::Instance();
	if( !rCmdMgr.CmdInterpret( vTextLine, vwbCmdYesValid, bCmdNotInCmdFactor, cmdData ) )
		return MIstatus::failure;
	
	if( vwbCmdYesValid )
	{
		// For debugging only
		//m_pLog->WriteLog( cmdData.strMiCmdAll.c_str() );
		
		return ExecuteCommand( cmdData );
	}

	// Write to the Log that a 'command' was not valid. 
	// Report back to the MI client via MI result record.
	CMIUtilString strNotInCmdFactory;
	if( bCmdNotInCmdFactor )
		strNotInCmdFactory = CMIUtilString::Format( MIRSRC( IDS_DRIVER_CMD_NOT_IN_FACTORY ), cmdData.strMiCmd.c_str() );
	const CMIUtilString strNot( CMIUtilString::Format( "%s ", MIRSRC( IDS_WORD_NOT ) ) );
	const CMIUtilString msg( CMIUtilString::Format( MIRSRC( IDS_DRIVER_CMD_RECEIVED ), vTextLine.c_str(), strNot.c_str(), strNotInCmdFactory.c_str() ) );
	const CMICmnMIValueConst vconst = CMICmnMIValueConst( msg );
	const CMICmnMIValueResult valueResult( "msg", vconst );
	const CMICmnMIResultRecord miResultRecord( cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, valueResult );
	m_rStdOut.WriteMIResponse( miResultRecord.GetString() );
	
	// Proceed to wait for or execute next command
	return MIstatus::success;
}
Ejemplo n.º 2
0
//++
// Details: Short cut function to enter error information into the command's
// metadata
//          object and set the command's error status.
// Type:    Method.
// Args:    rErrMsg - (R) Status description.
// Return:  None.
// Throws:  None.
//--
void CMICmdBase::SetError(const CMIUtilString &rErrMsg) {
  m_cmdData.bCmdValid = false;
  m_cmdData.strErrorDescription = rErrMsg;
  m_cmdData.bCmdExecutedSuccessfully = false;

  const CMICmnMIValueResult valueResult("msg", CMICmnMIValueConst(rErrMsg));
  const CMICmnMIResultRecord miResultRecord(
      m_cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error,
      valueResult);
  m_miResultRecord = miResultRecord;
  m_cmdData.strMiCmdResultRecord = miResultRecord.GetString();
}
Ejemplo n.º 3
0
//++ ------------------------------------------------------------------------------------
// Details: Interpret the text data and match against current commands to see if there
//          is a match. If a match then the command is issued and actioned on. If a
//          command cannot be found to match then vwbCmdYesValid is set to false and
//          nothing else is done here.
//          This function is used by the application's main thread.
// Type:    Method.
// Args:    vTextLine           - (R) Text data representing a possible command.
//          vwbCmdYesValid      - (W) True = Command valid, false = command not handled.
// Return:  MIstatus::success - Functional succeeded.
//          MIstatus::failure - Functional failed.
// Throws:  None.
//--
bool
CMIDriver::InterpretCommandThisDriver(const CMIUtilString &vTextLine, bool &vwbCmdYesValid)
{
    // Convert any CLI commands into MI commands
    const CMIUtilString vMITextLine(WrapCLICommandIntoMICommand(vTextLine));

    vwbCmdYesValid = false;
    bool bCmdNotInCmdFactor = false;
    SMICmdData cmdData;
    CMICmdMgr &rCmdMgr = CMICmdMgr::Instance();
    if (!rCmdMgr.CmdInterpret(vMITextLine, vwbCmdYesValid, bCmdNotInCmdFactor, cmdData))
        return MIstatus::failure;

    if (vwbCmdYesValid)
    {
        // For debugging only
        // m_pLog->WriteLog( cmdData.strMiCmdAll.c_str() );

        return ExecuteCommand(cmdData);
    }

    // Check for escape character, may be cursor control characters
    // This code is not necessary for application operation, just want to keep tabs on what
    // has been given to the driver to try and interpret.
    if (vMITextLine.at(0) == 27)
    {
        CMIUtilString logInput(MIRSRC(IDS_STDIN_INPUT_CTRL_CHARS));
        for (MIuint i = 0; i < vMITextLine.length(); i++)
        {
            logInput += CMIUtilString::Format("%d ", vMITextLine.at(i));
        }
        m_pLog->WriteLog(logInput);
        return MIstatus::success;
    }

    // Write to the Log that a 'command' was not valid.
    // Report back to the MI client via MI result record.
    CMIUtilString strNotInCmdFactory;
    if (bCmdNotInCmdFactor)
        strNotInCmdFactory = CMIUtilString::Format(MIRSRC(IDS_DRIVER_CMD_NOT_IN_FACTORY), cmdData.strMiCmd.c_str());
    const CMIUtilString strNot(CMIUtilString::Format("%s ", MIRSRC(IDS_WORD_NOT)));
    const CMIUtilString msg(
        CMIUtilString::Format(MIRSRC(IDS_DRIVER_CMD_RECEIVED), vMITextLine.c_str(), strNot.c_str(), strNotInCmdFactory.c_str()));
    const CMICmnMIValueConst vconst = CMICmnMIValueConst(msg);
    const CMICmnMIValueResult valueResult("msg", vconst);
    const CMICmnMIResultRecord miResultRecord(cmdData.strMiCmdToken, CMICmnMIResultRecord::eResultClass_Error, valueResult);
    const bool bOk = m_rStdOut.WriteMIResponse(miResultRecord.GetString());

    // Proceed to wait for or execute next command
    return bOk;
}