//++ ------------------------------------------------------------------------------------ // Details: Create a command given the specified MI command name. The command data object // contains the options for the command. // Type: Method. // Args: vMiCmd - (R) Command's name, the MI command. // vCmdData - (RW) Command's metadata status/information/result object. // vpNewCmd - (W) New command instance. // Return: MIstatus::success - Functionality succeeded. // MIstatus::failure - Functionality failed. // Throws: None. //-- bool CMICmdFactory::CmdCreate( const CMIUtilString & vMiCmd, const SMICmdData & vCmdData, CMICmdBase *& vpNewCmd ) { bool bOk = MIstatus::success; vpNewCmd = nullptr; if( !IsValid( vMiCmd ) ) { SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMDFACTORY_ERR_INVALID_CMD_NAME ), vMiCmd.c_str() ) ); return MIstatus::failure; } if( !HaveAlready( vMiCmd ) ) { SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMDFACTORY_ERR_CMD_NOT_REGISTERED ), vMiCmd.c_str() ) ); return MIstatus::failure; } const MapMiCmdToCmdCreatorFn_t::const_iterator it = m_mapMiCmdToCmdCreatorFn.find( vMiCmd ); const CMIUtilString & rMiCmd( (*it).first ); MIunused( rMiCmd ); CmdCreatorFnPtr pFn = (*it).second; CMICmdBase * pCmd = (*pFn)(); SMICmdData cmdData( vCmdData ); cmdData.id = pCmd->GetGUID(); bOk = pCmd->SetCmdData( cmdData ); if( bOk ) vpNewCmd = pCmd; return bOk; }
//++ ------------------------------------------------------------------------------------ // Details: Called when a command has finished its Execution() work either synchronously // because the command executed was the type a non event type or asynchronoulsy // via the command's callback (because of an SB Listener event). Needs to be called // so that *this invoker call do some house keeping and then proceed to call // the command's Acknowledge() function. // Type: Method. // Args: vCmd - (R) Command object. // Return: MIstatus::success - Functionality succeeded. // MIstatus::failure - Functionality failed. // Throws: None. //-- bool CMICmdInvoker::CmdExecuteFinished( CMICmdBase & vCmd ) { // Command finished now get the command to gather it's information and form the MI // Result record if( !vCmd.Acknowledge() ) { // Report command acknowledge functionality failed const SMICmdData cmdData( vCmd.GetCmdData() ); CmdStdout( cmdData ); CmdDelete( cmdData.id ); // Proceed to wait or execute next command return MIstatus::success; } // Retrieve the command's latest data/information. Needed for commands of the event type so have // a record of commands pending finishing execution. const CMIUtilString & rMIResultRecord( vCmd.GetMIResultRecord() ); SMICmdData cmdData( vCmd.GetCmdData() ); // Make a copy as the command will be deleted soon cmdData.strMiCmdResultRecord = rMIResultRecord; // Precautionary copy as the command might forget to do this if( vCmd.HasMIResultRecordExtra() ) { cmdData.bHasResultRecordExtra = true; const CMIUtilString & rMIExtra( vCmd.GetMIResultRecordExtra() ); cmdData.strMiCmdResultRecordExtra = rMIExtra; // Precautionary copy as the command might forget to do this } // Send command's MI response to the client bool bOk = CmdStdout( cmdData ); // Delete the command object as do not require anymore bOk = bOk && CmdDelete( vCmd.GetCmdData().id ); return bOk; }
VsbRawConfig VsbDevice::getRawConfig() { ByteString data = doQuery(VSB_CMD_GETCFG); VsbRawConfig rawConfig = { .mode = data[0], .mods = data[1], .keycodes = ByteString(data, 2, getInfo().singlekeyNumKeys), .keyseqLen = data[8] }; return rawConfig; } void VsbDevice::setRawConfig(const VsbRawConfig& rawCfg) { ByteString cmdData(3+info->singlekeyNumKeys, 0); cmdData[0] = rawCfg.mode; cmdData[1] = rawCfg.mods; cmdData[cmdData.size()-1] = rawCfg.keyseqLen; for(int i=0; (i<rawCfg.keycodes.size()) && (i < cmdData.size()-1); ++i) cmdData[i+2] = rawCfg.keycodes[i]; doQuery(VSB_CMD_SETCFG, cmdData); }
bool TSmtpMailer::send() { QMutexLocker locker(&sendMutex); // Lock for load reduction of mail server if (pop) { // POP before SMTP pop->setUserName(userName); pop->setPassword(password); pop->connectToHost(); pop->quit(); Tf::msleep(100); // sleep } if (smtpHostName.isEmpty() || smtpPort <= 0) { tSystemError("SMTP: Bad Argument: hostname:%s port:%d", qPrintable(smtpHostName), smtpPort); return false; } if (mailMessage.fromAddress().trimmed().isEmpty()) { tSystemError("SMTP: Bad Argument: From-address empty"); return false; } if (mailMessage.recipients().isEmpty()) { tSystemError("SMTP: Bad Argument: Recipients empty"); return false; } if (!connectToHost(smtpHostName, smtpPort)) { tSystemError("SMTP: Connect Error: hostname:%s port:%d", qPrintable(smtpHostName), smtpPort); return false; } if (mailMessage.date().isEmpty()) { mailMessage.setCurrentDate(); } if (!cmdEhlo()) { tSystemError("SMTP: EHLO Command Failed"); cmdQuit(); return false; } if (tlsEnable && tlsAvailable) { if (!cmdStartTls()) { cmdQuit(); return false; } } if (authEnable) { if (!cmdAuth()) { tSystemError("SMTP: User Authentication Failed: username:%s : [%s]", userName.data(), qPrintable(lastServerResponse())); cmdQuit(); return false; } } if (!cmdRset()) { tSystemError("SMTP: RSET Command Failed: [%s]", qPrintable(lastServerResponse())); cmdQuit(); return false; } if (!cmdMail(mailMessage.fromAddress())) { tSystemError("SMTP: MAIL Command Failed: [%s]", qPrintable(lastServerResponse())); cmdQuit(); return false; } if (!cmdRcpt(mailMessage.recipients())) { tSystemError("SMTP: RCPT Command Failed: [%s]", qPrintable(lastServerResponse())); cmdQuit(); return false; } if (!cmdData(mailMessage.toByteArray())) { tSystemError("SMTP: DATA Command Failed: [%s]", qPrintable(lastServerResponse())); cmdQuit(); return false; } cmdQuit(); return true; }