summaryrefslogtreecommitdiff
path: root/Runtime/Profiler/ProfilerConnection.h
blob: ffde5b35b7532a0c4c5b28a9212c5bd6861b1116 (plain)
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
#ifndef _PROFILERCONNECTION_H_
#define _PROFILERCONNECTION_H_

#if ENABLE_PROFILER

#include "Configuration/UnityConfigure.h"

#include "Runtime/Threads/Thread.h"
#include "ProfilerImpl.h"
#include "Runtime/Misc/SystemInfo.h"
#include "Runtime/Serialize/SerializationMetaFlags.h"

class ProfilerFrameData;

enum ConnectedProfiler
{
	kConnectedProfilerEditor,
	kConnectedProfilerStandalone,
	kConnectedProfilerWeb,
	kConnectedProfileriPhone,
	kConnectedProfilerAndroid,
	kConnectedProfilerXenon,
	kConnectedProfilerPS3,
	kConnectedProfilerWII,
	kConnectedProfilerPepper,
	kConnectedProfilerCount
};

class ProfilerConnection
{
public:
	static void Initialize();
	static void Cleanup();
	// Singleton accessor for ProfilerConnection
	static ProfilerConnection& Get() { return *ms_Instance; }

#if UNITY_EDITOR
	void GetAvailableProfilers (std::vector<UInt32>& values);

	void EnableConnectedProfiler ( bool enable );
	void SetConnectedProfiler (UInt32 guid, bool sendDisable = true);
	UInt32 GetConnectedProfiler ();
	static UInt32 GetEditorGuid();
	void DirectIPConnect(const std::string& IP);

	std::string GetConnectionIdentification(UInt32 guid);
	bool IsIdentifierConnectable(UInt32 guid);
	bool IsIdentifierOnLocalhost(UInt32 guid);
	bool IsConnectionEditor();
	void SetupTargetSpecificConnection(BuildTargetPlatform targetPlatform);

	static void HandleFileDataMessage (const void* data, UInt32 size, UInt32 guid);
	void SendCaptureHeapshotMessage();

	void SendGetObjectMemoryProfile();
#endif
	
	void SendFrameDataToEditor( ProfilerFrameData& data );


private:
	ProfilerConnection();

#if ENABLE_PLAYERCONNECTION 

	void PrepareConnections();
	void RemoveConnections();
	
	static void HandleProfilerDataMessage (const void* data, UInt32 size, UInt32 guid);
	static void HandleObjectMemoryProfileDataMessage (const void* data, UInt32 size, UInt32 guid);
	static void HandlePlayerConnectionMessage (const void* data, UInt32 size, UInt32 guid);
	static void HandleConnectionMessage (UInt32 guid);
	static void HandleDisconnectionMessage (UInt32 guid);
	static void EnableProfilerMessage ( const void* data, UInt32 size, UInt32 guid);
	static void GetObjectMemoryProfile( const void* data, UInt32 size, UInt32 guid);
	static void HandleCaptureHeapshotMessage ( const void* data, UInt32 size, UInt32 guid);
#endif

private:	
	UInt32 m_ConnectedProfiler;
	int	m_CurrentBuildTarget;

	// ProfilerConnection instance to use with singleton pattern
	static ProfilerConnection* ms_Instance;
	static UInt32 ms_EditorGuid;
	static UInt32 ms_CustomIPGuid;
};

#endif

#endif