summaryrefslogtreecommitdiff
path: root/replay/sv_sessionpublishmanager.cpp
blob: 96921d5b8c2d523f0abeeede2af113bcff547a9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//

#include "sv_sessionpublishmanager.h"
#include "sv_recordingsession.h"
#include "sv_sessionblockpublisher.h"
#include "sv_sessioninfopublisher.h"
#include "replay_dbg.h"
#include "vprof.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

//----------------------------------------------------------------------------------------

CSessionPublishManager::CSessionPublishManager( CServerRecordingSession *pSession )
:	m_pSession( pSession ),
	m_pBlockPublisher( NULL ),
	m_pSessionInfoPublisher( NULL )
{
	m_pSessionInfoPublisher = new CSessionInfoPublisher( pSession );
	m_pBlockPublisher = new CSessionBlockPublisher( pSession, m_pSessionInfoPublisher );
}

CSessionPublishManager::~CSessionPublishManager()
{
	delete m_pBlockPublisher;
	delete m_pSessionInfoPublisher;
}

void CSessionPublishManager::PublishAllSynchronous()
{
	Msg( "Finishing up replay publish...\n" );

	m_pBlockPublisher->PublishAllSynchronous();
	m_pSessionInfoPublisher->PublishAllSynchronous();
}

void CSessionPublishManager::OnStartRecording()
{
	// Lock the session (which will propagate the lock to all contained blocks)
	m_pSession->SetLocked( true );

	Assert( m_pSession->m_bRecording );
}

void CSessionPublishManager::OnStopRecord( bool bAborting )
{
	// Recording should be turned off on the session by this point
	Assert( !m_pSession->m_bRecording );

	m_pBlockPublisher->OnStopRecord( bAborting );
	m_pSessionInfoPublisher->OnStopRecord( bAborting );
}

ReplayHandle_t CSessionPublishManager::GetSessionHandle() const
{
	return m_pSession->GetHandle();
}

bool CSessionPublishManager::IsDone() const
{
	return !m_pSession->m_bRecording &&
		m_pBlockPublisher->IsDone() &&
		m_pSessionInfoPublisher->IsDone();
}

void CSessionPublishManager::Think()
{
	// NOTE: This gets called even if replay is disabled.  This is intentional.
	VPROF_BUDGET( "CSessionPublishManager::Think", VPROF_BUDGETGROUP_REPLAY );

	// Call publishers
	m_pBlockPublisher->Think();
	m_pSessionInfoPublisher->Think();

#ifdef _DEBUG
	m_pSession->VerifyLocks();
#endif
}

void CSessionPublishManager::UnlockSession()
{
	Assert( !m_pSession->m_bRecording );
	Assert( m_pBlockPublisher->IsDone() );
	Assert( m_pSessionInfoPublisher->IsDone() );

	IF_REPLAY_DBG( Warning( "Unlocking session %s\n", m_pSession->GetDebugName() ) );

	m_pSession->SetLocked( false );
}

void CSessionPublishManager::AbortPublish()
{
	m_pBlockPublisher->AbortPublish();
	m_pSessionInfoPublisher->AbortPublish();
}

#ifdef _DEBUG
void CSessionPublishManager::Validate()
{
	m_pBlockPublisher->Validate();
}
#endif

//----------------------------------------------------------------------------------------