summaryrefslogtreecommitdiff
path: root/replay/sv_sessionblockpublisher.h
blob: c9cfcf869d4bb4bbc48da2320b0e5640ee1d12a7 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
//=======================================================================================//

#ifndef SV_SESSIONBLOCKPUBLISHER_H
#define SV_SESSIONBLOCKPUBLISHER_H
#ifdef _WIN32
#pragma once
#endif

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

#include "sv_filepublish.h"
#include "replay/replayhandle.h"

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

class CServerRecordingSession;
class CServerRecordingSessionBlock;
class CSessionInfoPublisher;
class IDemoBuffer;

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

class CSessionBlockPublisher : public IPublishCallbackHandler
{
public:
	CSessionBlockPublisher( CServerRecordingSession *pSession, CSessionInfoPublisher *pSessionInfoPublisher );
	~CSessionBlockPublisher();

	void				Think();	// Called explicitly

	// Finish any publish jobs synchronously
	void				PublishAllSynchronous();

	// Abort any publishing
	void				AbortPublish();

	// Have all publish job completed?
	bool				IsDone() const;

	// This will flag this publish manager as recording
	void				OnStartRecording();

	// This will write out and publish any final session block
	void				OnStopRecord( bool bAborting );

	// Get the handle for the associated session
	ReplayHandle_t		GetSessionHandle() const;

#ifdef _DEBUG
	void				Validate();
#endif

private:
	//
	// IPublishCallback
	//
	virtual void		OnPublishComplete( const IFilePublisher *pPublisher, void *pUserData );
	virtual void		OnPublishAborted( const IFilePublisher *pPublisher );
	virtual void		AdjustHeader( const IFilePublisher *pPublisher, void *pHeaderData ) {}

	void				PublishBlock( CServerRecordingSessionBlock *pBlock );

	void				WriteAndPublishSessionBlock();
	void				PublishThink();
	void				WriteSessionBlockThink();
	void				SessionLockThink();
	void				GatherBlockData( uint8 *pSessionBuffer, int nSessionBufferSize, CServerRecordingSessionBlock *pBlock,
										 unsigned char **ppBlockData, int *pBlockSize );
	CServerRecordingSessionBlock	*FindBlockFromPublisher( const IFilePublisher *pPublisher );

	float				m_flLastBlockWriteTime;
	int					m_nDumpInterval;
	CUtlLinkedList< CServerRecordingSessionBlock *, int > m_lstPublishingBlocks;

	CServerRecordingSession	*m_pSession;
	CSessionInfoPublisher	*m_pSessionInfoPublisher;
};

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

#endif	// SV_SESSIONBLOCKPUBLISHER_H