bool UTransBuffer::Redo()
{
	CheckState();

	if (!CanRedo())
	{
		RedoDelegate.Broadcast(FUndoSessionContext(), false);

		return false;
	}

	// Apply the redo changes.
	GIsTransacting = true;
	{
		FTransaction& Transaction = UndoBuffer[ UndoBuffer.Num() - UndoCount-- ];
		UE_LOG(LogEditorTransaction, Log,  TEXT("Redo %s"), *Transaction.GetTitle().ToString() );
		CurrentTransaction = &Transaction;

		BeforeRedoUndoDelegate.Broadcast(Transaction.GetContext());
		Transaction.Apply();
		RedoDelegate.Broadcast(Transaction.GetContext(), true);

		CurrentTransaction = nullptr;
	}
	GIsTransacting = false;

	CheckState();

	return true;
}
void UTransBuffer::Reset( const FText& Reason )
{
	CheckState();

	if( ActiveCount != 0 )
	{
		FString ErrorMessage = TEXT("");
		ErrorMessage += FString::Printf(TEXT("Non zero active count in UTransBuffer::Reset") LINE_TERMINATOR );
		ErrorMessage += FString::Printf(TEXT("ActiveCount : %d"	) LINE_TERMINATOR, ActiveCount );
		ErrorMessage += FString::Printf(TEXT("SessionName : %s"	) LINE_TERMINATOR, *GetUndoContext(false).Context );
		ErrorMessage += FString::Printf(TEXT("Reason      : %s"	) LINE_TERMINATOR, *Reason.ToString() );

		ErrorMessage += FString::Printf( LINE_TERMINATOR );
		ErrorMessage += FString::Printf(TEXT("Purging the undo buffer...") LINE_TERMINATOR );

		UE_LOG(LogEditorTransaction, Log, TEXT("%s"), *ErrorMessage);

	
		// Clear out the transaction buffer...
		Cancel(0);
	}

	// Reset all transactions.
	UndoBuffer.Empty();
	UndoCount    = 0;
	ResetReason  = Reason;
	ActiveCount  = 0;

	CheckState();
}
void UTransBuffer::Cancel( int32 StartIndex /*=0*/ )
{
	CheckState();

	// if we don't have any active actions, we shouldn't have an active transaction at all
	if ( ActiveCount > 0 )
	{
		if ( StartIndex == 0 )
		{
			// clear the global pointer to the soon-to-be-deleted transaction
			GUndo = NULL;
			
			// remove the currently active transaction from the buffer
			UndoBuffer.Pop();
		}
		else
		{
			int32 RecordsToKeep = 0;
			for (int32 ActiveIndex = 0; ActiveIndex <= StartIndex; ++ActiveIndex)
			{
				RecordsToKeep += ActiveRecordCounts[ActiveIndex];
			}

			FTransaction& Transaction = UndoBuffer.Last();
			Transaction.RemoveRecords(Transaction.GetRecordCount() - RecordsToKeep);
		}

		// reset the active count
		ActiveCount = StartIndex;
		ActiveRecordCounts.SetNum(StartIndex);
	}

	CheckState();
}
void UTransBuffer::Cancel( int32 StartIndex /*=0*/ )
{
	CheckState();

	// if we don't have any active actions, we shouldn't have an active transaction at all
	if ( ActiveCount > 0 )
	{
		if ( StartIndex == 0 )
		{
			// clear the global pointer to the soon-to-be-deleted transaction
			GUndo = NULL;
			
			// remove the currently active transaction from the buffer
			UndoBuffer.Pop();
		}
		else
		{
			FTransaction& Transaction = UndoBuffer.Last();
			Transaction.RemoveRecords(ActiveCount - StartIndex);
		}

		// reset the active count
		ActiveCount = StartIndex;
	}

	CheckState();
}
int32 UTransBuffer::End()
{
	CheckState();
	const int32 Result = ActiveCount;
	// Don't assert as we now purge the buffer when resetting.
	// So, the active count could be 0, but the code path may still call end.
	if (ActiveCount >= 1)
	{
		if( --ActiveCount==0 )
		{
#if 0 // @todo DB: please don't remove this code -- thanks! :)
			// End the current transaction.
			if ( GUndo && GLog )
			{
				// @todo DB: Fix this potentially unsafe downcast.
				static_cast<FTransaction*>(GUndo)->DumpObjectMap( *GLog );
			}
#endif
			GUndo = NULL;
		}
		ActiveRecordCounts.Pop();
		CheckState();
	}
	return Result;
}
int32 UTransBuffer::Begin( const TCHAR* SessionContext, const FText& Description )
{
	CheckState();
	const int32 Result = ActiveCount;
	if( ActiveCount++==0 )
	{
		// Cancel redo buffer.
		if( UndoCount )
		{
			UndoBuffer.RemoveAt( UndoBuffer.Num()-UndoCount, UndoCount );
		}
		UndoCount = 0;

		// Purge previous transactions if too much data occupied.
		while( GetUndoSize() > MaxMemory )
		{
			UndoBuffer.RemoveAt( 0 );
		}

		// Begin a new transaction.
		GUndo = new(UndoBuffer)FTransaction( SessionContext, Description, 1 );
	}
	CheckState();
	return Result;
}
void UMatineeTransBuffer::EndSpecial()
{
	CheckState();
	check(ActiveCount>=1);
	if( --ActiveCount==0 )
	{
		GUndo = NULL;
	}
	CheckState();
}
bool UTransBuffer::CanUndo( FText* Text )
{
	CheckState();
	if( ActiveCount )
	{
		if( Text )
		{
			*Text = NSLOCTEXT("TransactionSystem", "CantUndoDuringTransaction", "(Can't undo while action is in progress)");
		}
		return false;
	}
	
	if (UndoBarrierStack.Num())
	{
		const int32 UndoBarrier = UndoBarrierStack.Last();
		if (UndoBuffer.Num() - UndoCount <= UndoBarrier)
		{
			if (Text)
			{
				*Text = NSLOCTEXT("TransactionSystem", "HitUndoBarrier", "(Hit Undo barrier; can't undo any further)");
			}
			return false;
		}
	}

	if( UndoBuffer.Num()==UndoCount )
	{
		if( Text )
		{
			*Text = FText::Format( NSLOCTEXT("TransactionSystem", "CantUndoAfter", "(Can't undo after: {0})"), ResetReason );
		}
		return false;
	}
	return true;
}
// UObject interface.
void UTransBuffer::Serialize( FArchive& Ar )
{
	check( !Ar.IsPersistent() );

	CheckState();

	Super::Serialize( Ar );

	if ( IsObjectSerializationEnabled() || !Ar.IsObjectReferenceCollector() )
	{
		Ar << UndoBuffer;
	}
	Ar << ResetReason << UndoCount << ActiveCount << ActiveRecordCounts;

	CheckState();
}
Exemple #10
0
nsresult
FileHandleBase::OpenInputStream(bool aWholeFile, uint64_t aStart,
                                uint64_t aLength, nsIInputStream** aResult)
{
  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");
  MOZ_ASSERT(mRequestMode == PARALLEL,
             "Don't call me in other than parallel mode!");

  // Common state checking
  ErrorResult error;
  if (!CheckState(error)) {
    return error.StealNSResult();
  }

  // Do nothing if the window is closed
  if (!CheckWindow()) {
    return NS_OK;
  }

  nsRefPtr<OpenStreamHelper> helper =
    new OpenStreamHelper(this, aWholeFile, aStart, aLength);

  nsresult rv = helper->Enqueue();
  NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);

  nsCOMPtr<nsIInputStream>& result = helper->Result();
  NS_ENSURE_TRUE(result, NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);

  result.forget(aResult);
  return NS_OK;
}
Exemple #11
0
void cSocketTCP::run()
{
	while(!World::IsStopped())
	{
		if(!isConnected)
			Connect();

		// if connect fail, wait 5 sec
		if(!isConnected)
		{
			ACE_Based::Thread::Sleep(5000);
			continue;
		}

		Packet pck;
		if(CheckState(m_sock->Receive(pck)))
			HandlePacket(&pck);

		if(m_session)
			m_session->Update();

		ACE_Based::Thread::Sleep(100);
	}
	Close();
}
//--------------------------------------------------------------------------------
bool CSocketServerMainThread::MainLoop()
	{
	DWORD nState = GetState();
	if(nState == STATE_PAUSE)
		{
		if(m_pSub->IsClosePortsOnPause())
			m_socket.Close();
		return true;
		}

	if(m_socket.IsValid())
		{
		if(m_socket.Listen(5))
			{
			CSmallSocket sock;
			if(m_socket.Accept(sock))
				{
				SOCKET hSocket = sock.Detach();
				if(! m_pSub->PostNextThreadMessage(CSocketServerSubSystem::MsgConnect, (WPARAM) hSocket, 0))
					sock.Attach(hSocket);
				}
			}
		}

	return CheckState();
	}
int detectStaLtaINT32(DETECTOR_STALTA *stalta, INT32 *data, UINT32 nsamp)
{
BOOL SeenDetection = FALSE; /* TRUE if at least one sample results in a detection ON */
UINT32 i;

    if (stalta->debug.enabled && stalta->debug.nsamp < nsamp) {
        stalta->debug.diff = (INT32 *) realloc(stalta->debug.diff, nsamp * sizeof(INT32));
        stalta->debug.sta = (INT32 *) realloc(stalta->debug.sta, nsamp * sizeof(INT32));
        stalta->debug.lta = (INT32 *) realloc(stalta->debug.lta, nsamp * sizeof(INT32));
        stalta->debug.tla = (INT32 *) realloc(stalta->debug.tla, nsamp * sizeof(INT32));
        stalta->debug.ratio = (REAL32 *) realloc(stalta->debug.ratio, nsamp * sizeof(REAL32));
        stalta->debug.state = (INT32 *) realloc(stalta->debug.state, nsamp * sizeof(INT32));
        stalta->debug.nsamp = nsamp;
    }

/* Update and test for detection sample by sample */

    for (i = 0; i < nsamp; i++) {
        UpdateRatio(stalta, data[i]);
        CheckState(stalta);
        if (!SeenDetection && stalta->work.crnt.state == DETECTOR_STATE_ON) SeenDetection = TRUE;
        if (stalta->debug.enabled) {
            stalta->debug.diff[i] = stalta->work.diff;
            stalta->debug.sta[i] = stalta->work.crnt.sta;
            stalta->debug.lta[i] = stalta->work.crnt.lta;
            stalta->debug.tla[i] = stalta->trigger.lta;
            stalta->debug.ratio[i] = stalta->work.crnt.ratio;
            stalta->debug.state[i] = stalta->work.crnt.state;
        }
    }

    stalta->state = SeenDetection ? DETECTOR_STATE_ON : DETECTOR_STATE_OFF;

    return stalta->state;
}
Exemple #14
0
int OtherThreadFunc(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, int p9, int p10)
{
    Wait4State( BINARY_OTHER );

    Go2State( BINARY_OPPOSITE, "BINARY_OPPOSITE" );
    if( semGive( s_binary ) != OK )
        perror( "Error giving in BINARY_OTHER state" );

    Wait4State( COUNTING_OTHER );

    Go2State( COUNTING_OPPOSITE, "COUNTING_OPPOSITE" );
    if( semGive( s_counting ) != OK )
        perror( "Error giving in COUNTING_OTHER state" );

    Wait4State( MUTEX_OTHER_GIVE );
    if( semGive( s_mutex ) == OK )
        printf( "Error in MUTEX_OTHER_GIVE: give operation must fail, but it succeeded\n");

    Go2State( MUTEX_OTHER_WAIT, "MUTEX_OTHER_WAIT" );
    if( semTake( s_mutex, WAIT_FOREVER ) != OK )
        perror( "Error taking in MUTEX_OTHER_WAIT state" );

    CheckState(MUTEX_OTHER_WAIT, MUTEX_GIVE_ALL );

    Go2State( MUTEX_OPPOSITE_TO, "MUTEX_OPPOSITE_TO" );

    Wait4State( MUTEX_OPPOSITE_GIVE );
    if( semGive( s_mutex ) != OK )
        perror("Error giving in MUTEX_OPPOSITE_GIVE state");

    Wait4State( MUTEX_UNBLOCK );
    printf( "Other thread is complete.\n");

    return 0;
}
Exemple #15
0
already_AddRefed<IDBFileRequest>
IDBFileHandle::GetMetadata(const IDBFileMetadataParameters& aParameters,
                           ErrorResult& aRv)
{
  MOZ_ASSERT(NS_IsMainThread(), "Wrong thread!");

  // Common state checking
  if (!CheckState(aRv)) {
    return nullptr;
  }

  // Do nothing if the window is closed
  if (!CheckWindow()) {
    return nullptr;
  }

  nsRefPtr<MetadataParameters> params =
    new MetadataParameters(aParameters.mSize, aParameters.mLastModified);
  if (!params->IsConfigured()) {
    aRv.ThrowTypeError(MSG_METADATA_NOT_CONFIGURED);
    return nullptr;
  }

  nsRefPtr<FileRequestBase> fileRequest = GenerateFileRequest();

  nsRefPtr<MetadataHelper> helper =
    new MetadataHelper(this, fileRequest, params);

  if (NS_WARN_IF(NS_FAILED(helper->Enqueue()))) {
    aRv.Throw(NS_ERROR_DOM_FILEHANDLE_UNKNOWN_ERR);
    return nullptr;
  }

  return fileRequest.forget().downcast<IDBFileRequest>();
}
Exemple #16
0
// **********************************************************
//		Undo
// **********************************************************
STDMETHODIMP CUndoList::Undo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	*retVal = VARIANT_FALSE;
	if (!CheckState()) return S_OK;

	IShapeEditor* editor = _mapCallback->_GetShapeEditor();

	if (_position >= 0) 
	{
		int pos = _position;
		int id = _list[pos]->BatchId;
		UndoListItem* item = _list[pos];

		while (_list[_position]->BatchId == id)
  	    {
			_position--;
			UndoSingleItem(_list[_position + 1]);
			if (_position < 0) break;
		}

		if (item->Operation != uoRemoveShape)
			ZoomToShape(zoomToShape, item->Operation == uoAddShape ? _position: pos);

		FireUndoListChanged();
		*retVal = VARIANT_TRUE;
	}
	return S_OK;
}
Exemple #17
0
// **********************************************************
//		Redo
// **********************************************************
STDMETHODIMP CUndoList::Redo(VARIANT_BOOL zoomToShape, VARIANT_BOOL* retVal)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	*retVal = VARIANT_FALSE;
	if (!CheckState()) return S_OK;

	int maxIndex = (int)_list.size() - 1;
	if (_position + 1 <= maxIndex)
	{
		int pos = _position + 1;
		int id = _list[pos]->BatchId;
		UndoListItem* item = _list[pos];

		while (_list[_position + 1]->BatchId == id)
		{
			UndoSingleItem(_list[_position + 1]);
			_position++;
			if (_position + 1 > maxIndex) 
				break;
		}

		ZoomToShape(zoomToShape, item->Operation == uoRemoveShape ? _position: pos );

		FireUndoListChanged();
		*retVal = VARIANT_TRUE;
	}
	return S_OK;
}
/**
 * @brief DialogEndLine create dialog
 * @param data container with data
 * @param parent parent widget
 */
DialogEndLine::DialogEndLine(const VContainer *data, QWidget *parent)
    :DialogTool(data, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), formula(QString()),
      angle(0), basePointId(0), formulaBaseHeight(0)
{
    ui->setupUi(this);
    InitVariables(ui);
    InitFormulaUI(ui);
    labelEditNamePoint = ui->labelEditNamePoint;
    this->formulaBaseHeight = ui->plainTextEditFormula->height();

    InitOkCancelApply(ui);
    flagFormula = false;
    flagName = false;
    CheckState();

    FillComboBoxPoints(ui->comboBoxBasePoint);
    FillComboBoxTypeLine(ui->comboBoxLineType);

    InitArrow(ui);

    connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogEndLine::PutHere);
    connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogEndLine::PutVal);
    connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogEndLine::EvalFormula);
    connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogEndLine::NamePointChanged);
    connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogEndLine::FormulaTextChanged);
    connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogEndLine::DeployFormulaTextEdit);
}
/**
 * @brief DialogCutSplinePath create dialog.
 * @param data container with data
 * @param parent parent widget
 */
DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent)
    :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()),
      splinePathId(NULL_ID), formulaBaseHeight(0), path(nullptr)
{
    ui->setupUi(this);
    InitVariables(ui);
    InitFormulaUI(ui);
    ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel));
    labelEditNamePoint = ui->labelEditNamePoint;
    this->formulaBaseHeight = ui->plainTextEditFormula->height();
    ui->plainTextEditFormula->installEventFilter(this);

    InitOkCancelApply(ui);
    flagFormula = false;
    CheckState();

    FillComboBoxSplinesPath(ui->comboBoxSplinePath);

    connect(ui->toolButtonPutHere, &QPushButton::clicked, this, &DialogCutSplinePath::PutHere);
    connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &DialogCutSplinePath::PutVal);
    connect(ui->toolButtonEqual, &QPushButton::clicked, this, &DialogCutSplinePath::EvalFormula);
    connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged);
    connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged);
    connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit);

    path = new VisToolCutSplinePath(data);
}
void ChildSupervisor::HandleStateChanged(otChangedFlags aFlags)
{
    if ((aFlags & (OT_CHANGED_THREAD_ROLE | OT_CHANGED_THREAD_CHILD_ADDED | OT_CHANGED_THREAD_CHILD_REMOVED)) != 0)
    {
        CheckState();
    }
}
Exemple #21
0
void JamDetector::HandleStateChanged(uint32_t aFlags)
{
    if (aFlags & OT_CHANGED_THREAD_ROLE)
    {
        CheckState();
    }
}
void UTransBuffer::Initialize(SIZE_T InMaxMemory)
{
	MaxMemory = InMaxMemory;
	// Reset.
	Reset( NSLOCTEXT("UnrealEd", "Startup", "Startup") );
	CheckState();

	UE_LOG(LogInit, Log, TEXT("Transaction tracking system initialized") );
}
void CButton::Update()
{
    m_oldState = m_state;
    m_state = ButtonStateNormal;
    
    CheckState();
    
    m_holdFrame = (ButtonStateHighlight == m_state) ? m_holdFrame + 1 : 0;
}
Exemple #24
0
// **********************************************************
//		get_RedoCount
// **********************************************************
STDMETHODIMP CUndoList::get_RedoCount(LONG* pVal)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	long totalLength, undoCount;
	get_TotalLength(&totalLength);
	get_UndoCount(&undoCount);
	*pVal = CheckState() ? totalLength - undoCount : -1;
	return S_OK;
}
bool UTransBuffer::Redo()
{
	CheckState();
	if( !CanRedo() )
	{
		return false;
	}

	// Apply the redo changes.
	FTransaction& Transaction = UndoBuffer[ UndoBuffer.Num() - UndoCount-- ];

	UE_LOG(LogEditorTransaction, Log,  TEXT("Redo %s"), *Transaction.GetTitle().ToString() );
	Transaction.Apply();

	CheckState();

	return true;
}
void UTransBuffer::FinishDestroy()
{
	if ( !HasAnyFlags(RF_ClassDefaultObject) )
	{
		CheckState();
		UE_LOG(LogExit, Log, TEXT("Transaction tracking system shut down") );
	}
	Super::FinishDestroy();
}
bool  CGameUpdate::UpdateBefore(__int64 qUpdateBytes)
{
	//check disk free room.
	wchar_t szLog[1024] = {0};
	qUpdateBytes += SAVE_DISK_ROOMSIZE;
	LARGE_INTEGER liSize = {0};
	hy_GetDiskRoomSize(m_strCliPath[0], &liSize);
	if (liSize.QuadPart >= qUpdateBytes)
		return true;
	
	//删除游戏,保证空间足够。
	if (m_dwUptFlag & UPDATE_FLAG_DELETE_GAME)
	{
		SetUpdateStatus(UPDATE_STATUS_DELETE_GAME);
		std::vector<tagGameInfo*> list;
		GetAllGameList(list);
		for (size_t idx=0; idx<list.size(); idx++)
		{
			if (!CheckState())
			{
				std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
				return false;
			}

			tagGameInfo* pGame = list[idx];
			if (PathFileExistsA(pGame->CliPath) && pGame->CliPath[0] == m_strCliPath[0] &&
				lstrcmpiW(_bstr_t(pGame->CliPath), m_strCliPath.c_str()) != 0)
			{
				std::wstring str(_bstr_t(pGame->CliPath));
				std::wstring str2 = hy_ConvertPath(str);
				
				SetUpdateInfo(INFO_STR_DELETEGAME, str.c_str());

				DeleteGame(str2.c_str());
				hy_DyncaRefreDriver(str[0]);

				hy_GetDiskRoomSize(m_strCliPath[0], &liSize);
				if (liSize.QuadPart >= qUpdateBytes)
				{
					std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
					return true;
				}
				else
				{
					swprintf_s(szLog, L"i8desk: free size:%dM, need size:%dM.", (DWORD)(liSize.QuadPart / 1000 / 1000),
						(DWORD)(qUpdateBytes / 1000 / 1000));
					OutputDebugStringW(szLog);
				}
			}
		}
		std::for_each(list.begin(), list.end(), Delete_Pointer<tagGameInfo>);
	}
	//空间不足,返回错误。
	SetErrorInfo(UPT_ERR_DISKNOROOM, (DWORD)(liSize.QuadPart / 1000 / 1000), (DWORD)(qUpdateBytes / 1000 / 1000));
	return false;
}
UTrackEntry* USpineSkeletonAnimationComponent::AddEmptyAnimation (int trackIndex, float mixDuration, float delay) {
	CheckState();
	if (state) {
		spTrackEntry* entry = spAnimationState_addEmptyAnimation(state, trackIndex, mixDuration, delay);
		UTrackEntry* uEntry = NewObject<UTrackEntry>();
		uEntry->SetTrackEntry(entry);
		trackEntries.Add(uEntry);
		return uEntry;
	} else return NewObject<UTrackEntry>();
}
UTransBuffer::UTransBuffer( const class FPostConstructInitializeProperties& PCIP, SIZE_T InMaxMemory )
:	UTransactor(PCIP)
,	MaxMemory( InMaxMemory )
{
	// Reset.
	Reset( NSLOCTEXT("UnrealEd", "Startup", "Startup") );
	CheckState();

	UE_LOG(LogInit, Log, TEXT("Transaction tracking system initialized") );
}
Exemple #30
0
void DEMONPEGTOP::Move()
{
	if (App->inter->enemies_movement) {
		
		CheckState();
		PerformActions();
		

	}
}