void FSBrowser::refresh() { clearItems(); StopProcessing(); if (_model->requiresAuthentication() && !_model->isAuthenticated()) { _authWidget->setUsernameclearPassword(); _authWidget->show(); } else { _authWidget->hide(); bool compact = false; if (_viewType == ListView) { compact = true; _scrollPaneLayout->setContentsMargins(12, 8, 8, 8); //Position Folders _scrollPaneLayout->setSpacing(0); } else { _scrollPaneLayout->setContentsMargins(12, 12, 12, 12); //Position Files in recent _scrollPaneLayout->setSpacing(8); } int id = 0; foreach (const FSEntry &entry, _model->entries()) { FSEntryWidget *button = new FSEntryWidget(entry, _scrollPane); button->setCompact(compact); _buttonGroup->addButton(button, id++); _scrollPaneLayout->addWidget(button); connect(button, SIGNAL(selected()), this, SLOT(entrySelectedHandler())); connect(button, SIGNAL(opened()), this, SLOT(entryOpenedHandler())); } } }
////////////////////////////////////////////////////////////////////////////////////// // Execute a single command // // Once the command is sent, wait for a response. If received and of the correct // ID, save the contents (if any) and quit. If no response, send RESYNC commands // every few seconds to get response from other end. On receipt of a RESYNC // command, resend the previous command. After no response for a minute or so, quit. ////////////////////////////////////////////////////////////////////////////////////// int CSTATEngine::SendSingleCommand(CSTATScriptCommand *pSendCommand, CSTATScriptCommand **ppRecvCommand) { int iTotalCommandTime = 0; int ret = GENERAL_FAILURE; LogDetails("Send", pSendCommand); // send the command EnterCriticalSection(&CriticalSection); ret = pComms->Send(pSendCommand->cCommandID, pSendCommand->Command(), pSendCommand->Length()); LeaveCriticalSection(&CriticalSection); if (ret != ITS_OK) { Message(pComms->Error()); return ret; } // The refresh command will not return anything due to the transport getting restarted. // So, don't wait for a response. if( (ret == ITS_OK) && (pSendCommand->cCommandID == STAT_REFRESH || pSendCommand->cCommandID == STAT_REBOOT) ) { return ret; } // wait for a response unsigned long ulLength = 0; char *pData = NULL; while(iTotalCommandTime < iMaxTimeLimit) { if (StopProcessing()) { pComms->Send(STAT_RESYNCID); ret = E_USERCANCEL; break; } EnterCriticalSection(&CriticalSection); ret = pComms->Receive(&oRecvCommand.cCommandID, &pData, &ulLength); LeaveCriticalSection(&CriticalSection); if (ret == ITS_OK) { if (oRecvCommand.SetData(pData, ulLength)) { oRecvCommand.ulLength = ulLength; *ppRecvCommand = &oRecvCommand; // invalid response received if (pSendCommand->cCommandID != oRecvCommand.cCommandID) { // need to resync back to start of this command if (oRecvCommand.cCommandID == STAT_RESYNCID) { Message("RESYNC response received - retrying command..."); ret = E_RESYNCCOMMAND; } else { if (oRecvCommand.cCommandID == STAT_FAILURE) { if (oRecvCommand.Command() && oRecvCommand.Length()) { Message("Command failed with error code %s", oRecvCommand.Command()); iDeviceCode = atoi(oRecvCommand.Command()); } } else Message("Invalid response received - expected %c received %c", pSendCommand->cCommandID, oRecvCommand.cCommandID); ret = GENERAL_FAILURE; } } else LogDetails("Receive", *ppRecvCommand); } else ret = E_OUTOFMEM; // at this point we have received something whether it's what we were expecting or not so exit loop break; } else if (ret == NO_DATA_AT_PORT) { // Message("Waiting for response"); Sleep(STAT_RETRYDELAY); iTotalCommandTime += STAT_RETRYDELAY; ret = E_TOOMUCHTIME; } else { Message(pComms->Error()); break; } } return ret; }
//---------------------------------------------------------------------------- // Execute a script file int CSTATEngine::RunScript(ScriptProgressMonitor *const monitor) { int ret = ITS_OK; iCurrentCommand = 0; eStopProcessing = STAT_RUN; iDeviceCode = 0; // anything smaller can cause problems and doesn't make sense anyway! if (iMaxTimeLimit < 1000) iMaxTimeLimit = 1000; // pointers to our command structures CSTATScriptCommand *pSendCommand; CSTATScriptCommand *pRecvCommand; char lastCommand = NULL; receivedData.Empty( ); // get a command from the script while (pDecoder->GetNextCommand(&pSendCommand) && ret == ITS_OK) { iCurrentCommand++; if (StopProcessing()) { pComms->Send(STAT_RESYNCID); ret = E_USERCANCEL; break; } if (lastCommand == STAT_REBOOT) { ret = ITS_OK; break; } switch(pSendCommand->cCommandID) { case 'P': Message(pSendCommand->Command()); Sleep(atol(pSendCommand->Command())); break; case '/': Message(pSendCommand->Command()); break; case '#': { Message(pSendCommand->Command()); cScreenshotDirectory = pSendCommand->Command(); if(cScreenshotDirectory.Right(1) != _T("\\")) cScreenshotDirectory += _T("\\"); CreateAllDirectories(cScreenshotDirectory); } break; default: { // send the command and retrieve a response int iResyncErrors = 0; while ((ret = SendCommand(pSendCommand, &pRecvCommand)) == E_RESYNCCOMMAND) { Sleep(STAT_RETRYDELAY); iResyncErrors++; if (iResyncErrors > STAT_MAXERRORS) { Message("Too many resync errors - stopping"); ret = E_COMMANDFAILED; break; } } if (ret == ITS_OK) { // perform special operations for these commands switch(pSendCommand->cCommandID) { case 'D': StoreData(pRecvCommand->Command(), pRecvCommand->Length(), pDeviceInfo); AppendCommandToSTATLog("*** DEVICE INFORMATION ***", pRecvCommand->Command(), pRecvCommand->Length()); break; case 'S': { // convert and save the data returned in the response CString image = pSendCommand->Command(); ret = ConvertAndSaveScreeenshot(image, pRecvCommand->Command(), pRecvCommand->Length()); // imave verification if (ret == ITS_OK) { if (pImageVerify->IsActive() && pConverter->bWriteToFile) { ret = pImageVerify->VerifyImage(image); if (ret == VERIFICATION_PASS) ret = ITS_OK; } } break; } case 'T': { if(dataSocket==NULL) { // filename has been sent, now send the file itself CSTATScriptCommand oSendCommand; oSendCommand.cCommandID = pRecvCommand->cCommandID; // read and send the file contents if ((ret = ReadTransferFile(pSendCommand->Command(), &oSendCommand)) == ITS_OK) { int iResyncErrors = 0; while ((ret = SendCommand(&oSendCommand, &pRecvCommand)) == E_RESYNCCOMMAND) { Sleep(STAT_RETRYDELAY); iResyncErrors++; if (iResyncErrors > STAT_MAXERRORS) { Message("Too many resync errors - stopping"); ret = E_COMMANDFAILED; break; } } } } else { //release the socket ret = ReleaseSocket(); } break; } case 'R': case 'X': { if(dataSocket==NULL) { // save the file contents ret = SaveTransferFile(pSendCommand->Command(), pRecvCommand->Command(), pRecvCommand->Length()); } else { //release the socket ret = ReleaseSocket(); } break; } case 'G': { // upload the device log file and write to STAT log file AppendCommandToSTATLog("*** DEVICE LOG ***", pRecvCommand->Command(), pRecvCommand->Length()); break; } case STAT_REFRESH: case STAT_END: { ret = END_SCRIPT; break; } case 'N': { // Retrieve the TEF shared data StoreData(pRecvCommand->Command(), pRecvCommand->Length(), iTEFSharedData); AppendCommandToSTATLog("*** RETRIEVE TEF SHARED DATA ***", pRecvCommand->Command(), pRecvCommand->Length()); } break; default: { Sleep(iDelay); break; } } } if (ret == ITS_OK) { // Data received from certain of the commands is stored // for retreival later. switch(pSendCommand->cCommandID) { case 'W': case 'V': //execute returns pid case 'J': //poll returns 0 1 case '3': receivedData += oRecvCommand.Command(); break; default: break; } } } break; } lastCommand = pSendCommand->cCommandID; if(monitor) { monitor->OnCompleteCommand( iCurrentCommand ); } } pDecoder->Release(); return ret; }
int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) { DialogBox(hinstExe, MAKEINTRESOURCE(IDD_QUEUE), NULL, Dlg_Proc); StopProcessing(); return(0); }
DWORD WINAPI StoppingThread(PVOID pvParam) { StopProcessing(); return(0); }