Exemplo n.º 1
0
void CSocketEngine::GetData(){
  if(iCount==1){//如果是接收文件的第一个数据包
    if(!GetFirstData()) return;
  }
  if(0==iSpeed){//网速未知
    if(2==iCount){
      iTimeTestSpeed1.HomeTime();
      iSizeTestSpeed1=iData1.Length();
      iSizeTestSpeed2=iSizeTestSpeed1;
    }
    if(iCount>2){
      iSizeTestSpeed2+=iData1.Length();
      if((iSizeTestSpeed2-iSizeTestSpeed1)>iTestSpeedSize){
        iTimeTestSpeed2.HomeTime();
        TTimeIntervalSeconds seconds(0);
        TInt err=iTimeTestSpeed2.SecondsFrom(iTimeTestSpeed1,seconds);
        if(!err){
          TInt sec=seconds.Int();
          iSpeed=(sec>0)?((iSizeTestSpeed2-iSizeTestSpeed1)/sec):KMaxNetSpeed;
          OnHttpSktEvent(EHttpSktEvtSpeedKnown);
        }
      }
    }
  }
  if(bSearch){
    if(iCount==1){
      iData->Des().Zero();
      iReceivedLen=0;
    }
    TBool needSaveFile=this->iDownloadFilePath.Length()>0;
    if(!needSaveFile){
      TInt n=iData->Des().Length()+iData1.Length();
      TInt m=iData->Des().MaxLength();
      if(n<m) iData->Des().Append(iData1);
    }
    iReceivedLen+=iData1.Length();
    if((iReceivedLen-iHttpHeadOverPos)<iTotalLen){
      if(needSaveFile) this->SaveToFile(iData1);
      ReceiveData();
    }else{
      if(iTimer->IsActive()) iTimer->Cancel();
      if(needSaveFile){
        this->SaveToFile(iData1);
        if(iObserver) iObserver->OnDownloadFinished(this->iDownloadFilePath);
      }else if(iObserver){
        int iLen=iData->Length()-iHttpHeadOverPos;
        if(iLen<=0){
          iObserver->OnResponseReceived(_L8(""));
        }else{
          iObserver->OnResponseReceived(iData->Mid(iHttpHeadOverPos,iLen));
        }
      }
      iDownloading=EFalse;
      Cancel();
      iSocket.Close();
    }
  }else{
    if(iObserver) iObserver->OnResponseReceived(iData1);
  }
}
Exemplo n.º 2
0
void mitk::NavigationDataPlayer::InitPlayer()
{
  if (m_Stream == NULL)
  {
    StreamInvalid("Playing not possible. Wrong file name or path?");
    return;
  }

  if (!m_Stream->good())
  {
    StreamInvalid("Playing not possible. Stream is not good!");
    return;
  }

  //first get the file version
  m_FileVersion = GetFileVersion(m_Stream);

  //check if we have a valid version: m_FileVersion has to be always bigger than 1 for playing
  if (m_FileVersion < 1)
  {
    StreamInvalid("Playing not possible. Invalid file version!");
    return;
  }

  if(m_NumberOfOutputs == 0) {m_NumberOfOutputs = GetNumberOfNavigationDatas(m_Stream);}

  //with the information about the tracked tool number we can generate the output
  if (m_NumberOfOutputs > 0)
  {
    //Generate the output only if there are changes to the amount of outputs
    //This happens when the player is stopped and start again with different file
    if (this->GetNumberOfOutputs() != m_NumberOfOutputs) {SetNumberOfOutputs(m_NumberOfOutputs);}
    //initialize the player with first data
    GetFirstData();
    //set stream valid
    m_ErrorMessage = "";
    m_StreamValid = true;
  }
  else
  {
    StreamInvalid("The input stream seems to have NavigationData incompatible format");
    return;
  }

}