!I 1937152 from //dev_game_hunt/consoles_candidate: !B Remove allocations of unnecess...
[CRYENGINE.git] / Code / CryPlugins / CryLobby / Module / DurangoLive / DurangoChat / ChatIntegrationLayer.h
blob031b88563fb73f5c1677d0a469705d395d2b1ce8
1 // XXX - ATG
3 //// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
4 //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
5 //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
6 //// PARTICULAR PURPOSE.
7 ////
8 //// Copyright (c) Microsoft Corporation. All rights reserved
10 #ifndef __CRYDURANGOCHAT_H__
11 #define __CRYDURANGOCHAT_H__
13 #pragma once
15 #if CRY_PLATFORM_DURANGO && USE_DURANGOLIVE
17 #include <CryLobby/ICryLobby.h>
19 #include "../CryDurangoLiveMatchMaking.h"
20 #include "../CryDurangoLiveLobbyPacket.h"
22 class ChatIntegrationLayer
24 public:
25 ChatIntegrationLayer();
26 ~ChatIntegrationLayer();
28 ECryLobbyError Initialize(bool jitterBufferEnabled, CCryDurangoLiveMatchMaking* pMatchMaking, DWORD cpuCore = 5);
29 void Shutdown();
30 void Reset();
32 void AddRemoteConnection(CryLobbySessionHandle h, CryMatchMakingConnectionID connectionID, uint32 consoleId);
33 void RemoveRemoteConnection(CryLobbySessionHandle h, CryMatchMakingConnectionID connectionID, uint32 consoleID);
35 void AddLocalUserToChatChannel(
36 __in uint8 channelIndex,
37 __in Windows::Xbox::System::IUser^ user
40 void RemoveUserFromChatChannel(
41 __in uint8 channelIndex,
42 __in Windows::Xbox::System::IUser^ user
45 void RemoveRemoteConsole(
46 Platform::Object^ uniqueRemoteConsoleIdentifier
49 void ReceivePacket(CCryDurangoLiveLobbyPacket* pPacket);
51 void OnIncomingChatMessage(
52 Windows::Storage::Streams::IBuffer^ chatPacket,
53 Platform::Object^ uniqueRemoteConsoleIdentifier
56 Windows::Foundation::Collections::IVectorView<Microsoft::Xbox::GameChat::ChatUser^>^ GetChatUsers();
57 bool HasMicFocus();
58 void HandleChatUserMuteStateChanged(
59 __in INT chatUserIndex
62 void HandleChatChannelChanged(
63 __in uint8 oldChatChannelIndex,
64 __in uint8 newChatChannelIndex,
65 __in INT index
67 void OnSecureDeviceAssocationConnectionEstablished(__in Platform::Object^ uniqueConsoleIdentifier);
69 private:
70 void AddAllLocallySignedInUsersToChatClient(
71 __in uint8 channelIndex,
72 __in Windows::Foundation::Collections::IVectorView<Windows::Xbox::System::User^>^ locallySignedInUsers
74 void RegisterChatManagerEventHandlers();
76 void OnDebugMessageReceived(
77 __in Microsoft::Xbox::GameChat::DebugMessageEventArgs^ args
80 void OnOutgoingChatPacketReady(
81 __in Microsoft::Xbox::GameChat::ChatPacketEventArgs^ args
84 static inline Platform::Object^ Uint32ToPlatformObject(__in uint32 val) { return Windows::Foundation::PropertyValue::CreateUInt32(val); }
85 static inline uint32 PlatformObjectToUint32(__in Platform::Object^ obj) { return safe_cast<Windows::Foundation::IPropertyValue^>(obj)->GetUInt32(); }
87 Microsoft::Xbox::GameChat::ChatUser^ GetChatUserByXboxUserId(
88 __in Platform::String^ xboxUserId
91 inline bool ChatIntegrationLayer::CompareUniqueConsoleIdentifiers(
92 __in Platform::Object^ uniqueRemoteConsoleIdentifier1,
93 __in Platform::Object^ uniqueRemoteConsoleIdentifier2
96 if (uniqueRemoteConsoleIdentifier1 == nullptr || uniqueRemoteConsoleIdentifier2 == nullptr)
98 return false;
101 return (PlatformObjectToUint32(uniqueRemoteConsoleIdentifier1) == PlatformObjectToUint32(uniqueRemoteConsoleIdentifier2));
104 void OnUserAudioDeviceAdded(Windows::Xbox::System::AudioDeviceAddedEventArgs^ eventArgs);
106 Concurrency::critical_section m_lock;
107 Microsoft::Xbox::GameChat::ChatManager^ m_chatManager;
108 Windows::Foundation::EventRegistrationToken m_tokenOnDebugMessage;
109 Windows::Foundation::EventRegistrationToken m_tokenOnOutgoingChatPacketReady;
110 Windows::Foundation::EventRegistrationToken m_tokenOnCompareUniqueConsoleIdentifiers;
111 Windows::Foundation::EventRegistrationToken m_tokenResourceAvailabilityChanged;
112 Windows::Foundation::EventRegistrationToken m_tokenAudioDeviceAdded;
113 float m_ackTimer;
114 CCryDurangoLiveMatchMaking* m_pMatchMaking;
116 struct ConnectionData
118 CryLobbySessionHandle sessionHandle;
119 CryMatchMakingConnectionID connectionID;
120 uint32 remoteConsoleId;
122 std::vector<ConnectionData> m_remoteConsoleConnections;
124 void CreatePacket(_Inout_ CCryDurangoLiveLobbyPacket* pPacket, _In_ Windows::Storage::Streams::IBuffer^ pBuffer, _In_ bool reliable);
125 void UnwrapPacket(_In_ CCryDurangoLiveLobbyPacket* pPacket, _Out_ byte** ppData, _Out_ uint* size);
129 static ChatIntegrationLayer* GetChatIntegrationLayer()
131 static ChatIntegrationLayer* pChatIntegrationLayerInstance;
132 if (pChatIntegrationLayerInstance == nullptr)
134 pChatIntegrationLayerInstance = new ChatIntegrationLayer();
137 return pChatIntegrationLayerInstance;
140 static void ShutdownChatIntegrationLayer()
142 delete GetChatIntegrationLayer();
145 #endif
146 #endif // __CRYDURANGOCHAT_H__