Exemplo n.º 1
0
bool ExchangeMerger::Close() {
  LOG(INFO) << " exchange_merger_id = " << state_.exchange_id_ << " closed!"
            << " exhausted lower senders num = " << exhausted_lowers
            << " lower sender num = " << lower_num_ << std::endl;

  CancelReceiverThread();
  CloseSocket();
  for (unsigned i = 0; i < lower_num_; i++) {
    if (NULL != block_for_socket_[i]) {
      delete block_for_socket_[i];
      block_for_socket_[i] = NULL;
    }
  }
  if (NULL != block_for_deserialization) {
    delete block_for_deserialization;
    block_for_deserialization = NULL;
  }
  if (NULL != all_merged_block_buffer_) {
    delete all_merged_block_buffer_;
    all_merged_block_buffer_ = NULL;
  }

  /* rest the status of this iterator instance, such that the following calling
   * of open() and next() can act correctly.
   */
  ResetStatus();

  Environment::getInstance()->getExchangeTracker()->LogoutExchange(
      ExchangeID(state_.exchange_id_, partition_offset_));
  LOG(INFO) << "exchange merger id = " << state_.exchange_id_ << " is closed!"
            << std::endl;
  return true;
}
Exemplo n.º 2
0
void CBufferOutputAudioEngine::Play()
{
		//BufferTrace("CBufferOutputAudioEngine::Play()....\n");
		if (!m_bFilled && m_mapOutputAudioBuf.size() < (1.0f*BUFFER_PERSEC_AUDIO_NUMBER*BUFFER_OUTPUT_ONMIC_AUDIO_MAX_LIMIT)/1000){
			return ;
		}

		if (!m_bFilled) {
			m_fLastPlayTime = GetTickCount();
			m_iStartPlayCount = 0;
			m_bFilled = true;
		}
		if (m_mapOutputAudioBuf.size() < 1 || (GetTickCount() - m_lastRecvTime) > 1000*10){//10s钟没有收到数据 超时 刷新
			MutexLocker locker(&m_mutex);//播放线程 网络线程 m_mapOutputAudioBuf
			ResetStatus();
			return;
		}

		IsCanCalcRecvRate()?m_fRecvRate = CalcRecevRate():NULL;
		m_fSendRate = CanCalcPlayRate();

		//ErrTrace("CBufferOutputAudioEngine::Play() m_mapOutputAudioBuf.size()=%d,seq=%d,m_fRecvRate=%f,m_fSendRate=%f\n",m_mapOutputAudioBuf.size(),m_iMaxSequenceId - m_iMinSequenceId+1,m_fRecvRate,m_fSendRate);

		unsigned int iLimit = 0;
		DWORD dwCurrTime = GetTickCount();
		while (m_fLastPlayTime < dwCurrTime && ++iLimit<5)
		{
			m_fLastPlayTime += m_fSendRate;
			m_iStartPlayCount++;
			PlayPackets();
			SwitchToThread();
		}
		CheckPacket();
		RefreshStatus();
}
Exemplo n.º 3
0
void Write1770Register(unsigned char Register, unsigned char Value) {
	unsigned char ComBits,HComBits;
	int SectorCycles=0; // Number of cycles to wait for sector to come round
#ifdef USE_FD_LOG
	//fprintf(fdclog,"Write of %02X to Register %d\n",Value, Register);
	// fflush(fdclog);
#endif
	// Write 1770 Register - NOT the FDC Control register @ &FE24
	if (Register==0) {
		NMIStatus &= ~(1<<nmi_floppy); // reset INTRQ
		// Control Register - can only write if current drive is open
		// Changed, now command returns errors if no disc inserted
		ComBits=Value & 0xf0;
		HComBits=Value & 0xe0;
		if (HComBits<0x80) {
			// Type 1 Command
			SetStatus(0);
			ResetStatus(3);
			ResetStatus(4);
			if (HComBits==0x40) { FDCommand=4; HeadDir=1; UpdateTrack=(Value & 16)>>4; } // Step In
Exemplo n.º 4
0
unsigned char Read1770Register(unsigned char Register) {
	// ResetStatus(5);
#ifdef USE_FD_LOG
	//fprintf(fdclog,"Read of Register %d - Status is %02X\n",Register,Status);
	// fflush(fdclog);
#endif
	// Read 1770 Register. Note - NOT the FDC Control register @ &FE24
	if ((FDCommand<6) && (FDCommand!=0)) Status^=2; // Fool anything reading the
	// Index pulse signal by alternating it on each read.
	if (Register==0) {
		NMIStatus &= ~(1<<nmi_floppy);
		return(Status);
	}
	if (Register==1) return(ATrack); 
	if (Register==2) return(Sector);
	if (Register==3) {
		if (FDCommand>5) 
		{
			ResetStatus(1); NMIStatus &= ~(1<<nmi_floppy); 
		}
		return(Data);
	}
	return(0);
}
Exemplo n.º 5
0
void CMainFrame::OnFileOpen()
{
	// TODO: 在此添加命令处理程序代码
	// TODO: 在此添加命令处理程序代码
	CFileDialog dialog(
		TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
		NULL,
		NULL,
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		TEXT("STEP file(*.step;*.stp)|*.step;*.stp|All Files (*.*)|*.*||"),
		this);

	if (dialog.DoModal() == IDOK) {
		CString filePath = dialog.GetPathName();
		char file_str[1024] = {0};
		WideCharToMultiByte(CP_ACP, 0, filePath.GetString(), filePath.GetLength(), file_str, 1024, NULL, NULL);

		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
		SetStatus(_T("加载文件中..."));

		STEPControl_Reader reader;
		if (reader.ReadFile(file_str) != IFSelect_RetDone) {
			AfxMessageBox(_T("文件打开错误!"));
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
			ResetStatus();
			return;
		}
		SetStatus(_T("模型转换"));

		Handle(AIS_InteractiveContext) m_context = ((CMCApp*)AfxGetApp())->GetAISContext();

		Standard_Integer nbRoots = reader.NbRootsForTransfer();
		cout << "Number of roots in STEP file: " << nbRoots << endl;

		Standard_Integer NbTrans = reader.TransferRoots();
		// translates all transferable roots, and returns the number of
		//successful translations
		cout << "STEP roots transferred: " << NbTrans << endl;
		Standard_Integer NbShapes = reader.NbShapes();
		cout << "Number of resulting shapes is: " << NbShapes << endl;

		m_rootTopoShape = reader.Shape();// reader.OneShape();
		if (!m_rootTopoShape.IsNull()) {
			if (m_context->HasOpenedContext())
				m_context->CloseAllContexts();
			m_context->RemoveAll();
			TopAbs_ShapeEnum shapeType = m_rootTopoShape.ShapeType();
			if (shapeType == TopAbs_COMPOUND) {
				Quantity_NameOfColor colors[] = {
					Quantity_NOC_RED,
					Quantity_NOC_SKYBLUE,
					Quantity_NOC_SALMON,
					Quantity_NOC_GREEN,
					Quantity_NOC_ORANGE,
					Quantity_NOC_DEEPSKYBLUE1,
					Quantity_NOC_GOLD,
					Quantity_NOC_CYAN4,
					Quantity_NOC_DEEPPINK4,
					Quantity_NOC_INDIANRED,
					Quantity_NOC_BROWN
				};

				Standard_Integer i=0;
				for (TopExp_Explorer solidExp(m_rootTopoShape, TopAbs_SOLID); solidExp.More(); solidExp.Next(), ++i)
				{
					TopoDS_Shape solid = TopoDS::Solid(solidExp.Current());
					for (TopExp_Explorer faceExp(solid, TopAbs_FACE); faceExp.More(); faceExp.Next())
					{
						//Geom_BezierSurface 
						//Geom_Geometry *g;
						//g->GetType();
					}
					Handle(AIS_Shape) aisShape = new AIS_Shape(solid);
					m_context->SetDisplayMode(aisShape, 1, Standard_False);
					m_context->Display(aisShape, Standard_False);
					m_context->SetWidth(aisShape, 2, Standard_False);
					m_context->SetMaterial(aisShape, Graphic3d_NOM_PLASTIC, Standard_False);
					m_context->SetColor(aisShape, colors[i % (sizeof(colors) / sizeof(Quantity_NameOfColor))], Standard_False);
				}

			}
			else {
				m_rootAISShape = new AIS_Shape(m_rootTopoShape);
				//m_context->SetColor(m_rootAISShape, Quantity_NOC_SALMON);
				//m_context->SetMaterial(m_rootAISShape, Graphic3d_NOM_METALIZED);
				m_context->SetDisplayMode(m_rootAISShape, true);
				m_context->Display(m_rootAISShape);
				m_context->SetSelectionMode(m_rootAISShape, 4);
				m_context->SetHilightColor(Quantity_NOC_LIGHTBLUE);
			}
			
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		}
		else {
			SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
			AfxMessageBox(_T("模型为空!"));
		}


		SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
		ResetStatus();
		m_wndView.Reset();
	}
}
Exemplo n.º 6
0
void CBufferOutputVideoEngine::Play()
{
		//视频填充
		if (!m_bFilled && m_mapOutputVideoBuf.size() < (1.0f*BUFFER_PERSEC_VIDEO_NUMBER*1300)/1000){ //缓冲1.3s的数据
			return ;
		}

		if (!m_bFilled) {
			m_dwLastPlayTime = GetTickCount();
			m_iStartPlayCount = 0;
			m_bFilled = true;
		}

		//BufferTrace("CBufferOutputVideoEngine::Play().....\n");
		if (m_iMinSequenceId == 0) return;
		if (m_bStartPlay && m_iMinSequenceId>0){
			if (m_dwStartPlayTime==0){
				m_dwStartPlayTime = GetTickCount();
			}
			if (GetTickCount()-m_dwStartPlayTime>BUFFER_VIDEO_PREVIEW_TIME){
				m_bStartPlay = false;
			}
		}
		//计算缓冲区大小
		if (m_pRate){
			if (CanCalcAudioParam()){
				if (m_pInPlace){
					m_iAudioBufferSize = m_pInPlace->GetBufferSize(m_iFromUin,bfAudio);
					m_dwLastRecvAudioTime = m_pInPlace->GetRecvTime(m_iFromUin,bfAudio);
				}else{
					m_dwLastRecvAudioTime = 0;
					m_iAudioBufferSize = BUFFER_OUTPUT_ONMIC_AUDIO_MAX_LIMIT;

					AssertVS(0,m_iFromUin,"CBufferOutputVideoEngine::Play m_pInPlace=NULL");
				}
			}
			m_iBufferSize = m_pRate->CalcBufferSize(
				BUFFER_OUTPUT_ONMIC_VIDEO_MIN_LIMIT, //缓冲区最小缓冲时间 - 麦上 最小
				BUFFER_OUTPUT_ONMIC_VIDEO_MAX_LIMIT, //缓冲区最大缓冲时间 - 麦上 最大
				BUFFER_OUTPUT_UNMIC_VIDEO_MIN_LIMIT, //缓冲区最小缓冲时间 - 麦下 最小
				BUFFER_OUTPUT_UNMIC_VIDEO_MAX_LIMIT, //缓冲区最大缓冲时间 - 麦下 最大
				BUFFER_PERSEC_AUDIO_NUMBER,			 //平均速率
				m_fLostRate,						 //当前丢包率
				m_dwLastCalcBufSizeTime,			 //上一次计算缓冲区时间
				m_iBufferSize,
				m_iAudioBufferSize,
				m_dwLastRecvAudioTime
				);

			//BufferTrace("计算缓冲区大小 m_iBufferSize=%d, lostrate=%f, m_dwLastCalcBufSizeTime=%d,m_iAudioBufferSize=%d,m_dwLastRecvAudioTime=%d\n",
			//	m_iBufferSize,m_fLostRate,m_dwLastCalcBufSizeTime,m_iAudioBufferSize,m_dwLastRecvAudioTime);
		}else{
			AssertVS(0,m_iFromUin,"CBufferOutputVideoEngine::Play m_pRate=NULL");
		}
		
		//计算接收视频速率
		m_fRecvRate = CalcRecevRate();
		m_fRecvFrameRate = CalcRecevFrameRate();
		if (IsCanCalcPlayRate()){
			if (m_pRate){ //计算发送数据帧的速率
				if (m_bStartPlay){
					m_dwSendRate = 1000 / BUFFER_PERSEC_VIDEO_FRAMES;
				}else{
					m_dwSendRate = m_pRate->CalcSendRate(
						m_iBufferSize, //缓冲区大小
						(UInt32)m_mapOutputVideoBuf.size(), //缓冲区中当前数据包个数
						m_iMaxFrameId - m_iMinFrameId+1,
						m_fRecvRate, //收包速率
						m_dwSendRate //上次计算的发送数据时间间隔大小
						);
				}

				//ErrTrace("CBufferOutputVideoEngine::Play() m_mapOutputVideoBuf.size()=%d,frames=%d,m_fRecvRate=%f,m_fRecvFrameRate=%f,m_dwSendRate=%d\n",m_mapOutputVideoBuf.size(),m_iMaxFrameId - m_iMinFrameId+1,m_fRecvRate,m_fRecvFrameRate,m_dwSendRate);
			}else{
				AssertVS(0,m_iFromUin,"CBufferOutputVideoEngine m_pRate=NULL");
			}
		}
		
		if(m_dwSendRate==0){
			Assert(0);
		}

		//播放数据 按帧播放
		unsigned int iLoop = 0;
		while (m_dwLastPlayTime < GetTickCount() && m_dwSendRate>0 && iLoop++ <10){
// 			BufferTrace("CBufferOutputVideoEngine::Play() while1 m_mapOutputVideoBuf.size()=%d,m_mapFrameToSeq.size()=%d,m_fRecvRate=%f,m_fRecvFrameRate=%f,m_dwSendRate=%d time=%d………… %d\n",m_mapOutputVideoBuf.size(),m_mapFrameToSeq.size(),m_fRecvRate,m_fRecvFrameRate,m_dwSendRate,GetTickCount());
 			(m_dwLastPlayTime==0)?(m_dwLastPlayTime=GetTickCount()+m_dwSendRate):(m_dwLastPlayTime += m_dwSendRate);
			m_iStartPlayCount++;
			PlayFrames();
			SwitchToThread();
		}
		RemoveExpireFrame();
		CheckPacket();
		
		if (m_mapOutputVideoBuf.size()==0 && GetTickCount()-m_lastRecvTime>=2000){ //2s没有收到数据,重置状态
			ResetStatus();
		}

		if(GetTickCount()-m_lastRecvTime>=10000){ //10s没有收到数据,且buf中有数据
			ResetStatus();
		}
}
Exemplo n.º 7
0
void
IORequest::NotifyFinished()
{
	TRACE("IORequest::NotifyFinished(): request: %p\n", this);

	MutexLocker locker(fLock);

	if (fStatus == B_OK && !fPartialTransfer && RemainingBytes() > 0) {
		// The request is not really done yet. If it has an iteration callback,
		// call it.
		if (fIterationCallback != NULL) {
			ResetStatus();
			locker.Unlock();
			bool partialTransfer = false;
			status_t error = fIterationCallback(fIterationCookie, this,
				&partialTransfer);
			if (error == B_OK && !partialTransfer)
				return;

			// Iteration failed, which means we're responsible for notifying the
			// requests finished.
			locker.Lock();
			fStatus = error;
			fPartialTransfer = true;
		}
	}

	ASSERT(fPendingChildren == 0);
	ASSERT(fChildren.IsEmpty()
		|| dynamic_cast<IOOperation*>(fChildren.Head()) == NULL);

	// unlock the memory
	if (fBuffer->IsMemoryLocked())
		fBuffer->UnlockMemory(fTeam, fIsWrite);

	// Cache the callbacks before we unblock waiters and unlock. Any of the
	// following could delete this request, so we don't want to touch it
	// once we have started telling others that it is done.
	IORequest* parent = fParent;
	io_request_finished_callback finishedCallback = fFinishedCallback;
	void* finishedCookie = fFinishedCookie;
	status_t status = fStatus;
	size_t lastTransferredOffset = fRelativeParentOffset + fTransferSize;
	bool partialTransfer = status != B_OK || fPartialTransfer;
	bool deleteRequest = (fFlags & B_DELETE_IO_REQUEST) != 0;

	// unblock waiters
	fIsNotified = true;
	fFinishedCondition.NotifyAll();

	locker.Unlock();

	// notify callback
	if (finishedCallback != NULL) {
		finishedCallback(finishedCookie, this, status, partialTransfer,
			lastTransferredOffset);
	}

	// notify parent
	if (parent != NULL) {
		parent->SubRequestFinished(this, status, partialTransfer,
			lastTransferredOffset);
	}

	if (deleteRequest)
		delete this;
}
Exemplo n.º 8
0
/*!	Note: SetPartial() must be called first!
*/
status_t
IOOperation::Prepare(IORequest* request)
{
	if (fParent != NULL)
		fParent->RemoveOperation(this);

	fParent = request;

	fTransferredBytes = 0;

	// set initial phase
	fPhase = PHASE_DO_ALL;
	if (fParent->IsWrite()) {
		// Copy data to bounce buffer segments, save the partial begin/end vec,
		// which will be copied after their respective read phase.
		if (UsesBounceBuffer()) {
			TRACE("  write with bounce buffer\n");
			uint8* bounceBuffer = (uint8*)fDMABuffer->BounceBufferAddress();
			addr_t bounceBufferStart
				= fDMABuffer->PhysicalBounceBufferAddress();
			addr_t bounceBufferEnd = bounceBufferStart
				+ fDMABuffer->BounceBufferSize();

			const iovec* vecs = fDMABuffer->Vecs();
			uint32 vecCount = fDMABuffer->VecCount();
			size_t vecOffset = 0;
			uint32 i = 0;

			off_t offset = fOffset;
			off_t endOffset = fOffset + fLength;

			if (HasPartialBegin()) {
				// skip first block
				size_t toSkip = fBlockSize;
				while (toSkip > 0) {
					if (vecs[i].iov_len <= toSkip) {
						toSkip -= vecs[i].iov_len;
						i++;
					} else {
						vecOffset = toSkip;
						break;
					}
				}

				offset += fBlockSize;
			}

			if (HasPartialEnd()) {
				// skip last block
				size_t toSkip = fBlockSize;
				while (toSkip > 0) {
					if (vecs[vecCount - 1].iov_len <= toSkip) {
						toSkip -= vecs[vecCount - 1].iov_len;
						vecCount--;
					} else
						break;
				}

				endOffset -= fBlockSize;
			}

			for (; i < vecCount; i++) {
				const iovec& vec = vecs[i];
				addr_t base = (addr_t)vec.iov_base + vecOffset;
				size_t length = vec.iov_len - vecOffset;
				vecOffset = 0;

				if (base >= bounceBufferStart && base < bounceBufferEnd) {
					if (offset + length > endOffset)
						length = endOffset - offset;
					status_t error = fParent->CopyData(offset,
						bounceBuffer + (base - bounceBufferStart), length);
					if (error != B_OK)
						return error;
				}

				offset += length;
			}
		}

		if (HasPartialBegin())
			fPhase = PHASE_READ_BEGIN;
		else if (HasPartialEnd())
			fPhase = PHASE_READ_END;

		_PrepareVecs();
	}

	ResetStatus();

	if (fParent != NULL)
		fParent->AddOperation(this);

	return B_OK;
}
Exemplo n.º 9
0
bool
IOOperation::Finish()
{
	TRACE("IOOperation::Finish()\n");
	if (fStatus == B_OK) {
		if (fParent->IsWrite()) {
			TRACE("  is write\n");
			if (fPhase == PHASE_READ_BEGIN) {
				TRACE("  phase read begin\n");
				// repair phase adjusted vec
				fDMABuffer->VecAt(fSavedVecIndex).iov_len = fSavedVecLength;

				// partial write: copy partial begin to bounce buffer
				bool skipReadEndPhase;
				status_t error = _CopyPartialBegin(true, skipReadEndPhase);
				if (error == B_OK) {
					// We're done with the first phase only (read in begin).
					// Get ready for next phase...
					fPhase = HasPartialEnd() && !skipReadEndPhase
						? PHASE_READ_END : PHASE_DO_ALL;
					_PrepareVecs();
					ResetStatus();
						// TODO: Is there a race condition, if the request is
						// aborted at the same time?
					return false;
				}

				SetStatus(error);
			} else if (fPhase == PHASE_READ_END) {
				TRACE("  phase read end\n");
				// repair phase adjusted vec
				iovec& vec = fDMABuffer->VecAt(fSavedVecIndex);
				vec.iov_base = (uint8*)vec.iov_base
					+ vec.iov_len - fSavedVecLength;
				vec.iov_len = fSavedVecLength;

				// partial write: copy partial end to bounce buffer
				status_t error = _CopyPartialEnd(true);
				if (error == B_OK) {
					// We're done with the second phase only (read in end).
					// Get ready for next phase...
					fPhase = PHASE_DO_ALL;
					ResetStatus();
						// TODO: Is there a race condition, if the request is
						// aborted at the same time?
					return false;
				}

				SetStatus(error);
			}
		}
	}

	if (fParent->IsRead() && UsesBounceBuffer()) {
		TRACE("  read with bounce buffer\n");
		// copy the bounce buffer segments to the final location
		uint8* bounceBuffer = (uint8*)fDMABuffer->BounceBufferAddress();
		addr_t bounceBufferStart = fDMABuffer->PhysicalBounceBufferAddress();
		addr_t bounceBufferEnd = bounceBufferStart
			+ fDMABuffer->BounceBufferSize();

		const iovec* vecs = fDMABuffer->Vecs();
		uint32 vecCount = fDMABuffer->VecCount();

		status_t error = B_OK;

		// We iterate through the vecs we have read, moving offset (the device
		// offset) as we go. If [offset, offset + vec.iov_len) intersects with
		// [startOffset, endOffset) we copy to the final location.
		off_t offset = fOffset;
		const off_t startOffset = fOriginalOffset;
		const off_t endOffset = fOriginalOffset + fOriginalLength;

		for (uint32 i = 0; error == B_OK && i < vecCount; i++) {
			const iovec& vec = vecs[i];
			addr_t base = (addr_t)vec.iov_base;
			size_t length = vec.iov_len;

			if (offset < startOffset) {
				// If the complete vector is before the start offset, skip it.
				if (offset + length <= startOffset) {
					offset += length;
					continue;
				}

				// The vector starts before the start offset, but intersects
				// with it. Skip the part we aren't interested in.
				size_t diff = startOffset - offset;
				offset += diff;
				base += diff;
				length -= diff;
			}

			if (offset + length > endOffset) {
				// If we're already beyond the end offset, we're done.
				if (offset >= endOffset)
					break;

				// The vector extends beyond the end offset -- cut it.
				length = endOffset - offset;
			}

			if (base >= bounceBufferStart && base < bounceBufferEnd) {
				error = fParent->CopyData(
					bounceBuffer + (base - bounceBufferStart), offset, length);
			}

			offset += length;
		}

		if (error != B_OK)
			SetStatus(error);
	}

	return true;
}
Exemplo n.º 10
0
void
IORequest::SetUnfinished()
{
	MutexLocker _(fLock);
	ResetStatus();
}