Skip to content

Commit

Permalink
2110 GDK QFE4 (#585)
Browse files Browse the repository at this point in the history
* 2110 GDK QFE4
  • Loading branch information
natiskan authored Mar 16, 2022
1 parent 8f47116 commit f2aa2b6
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 58 deletions.
2 changes: 1 addition & 1 deletion External/Xal/Source/Xal/Include/Xal/xal_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ extern "C"
/// YYYYMMDD Date string describing the date the build was created
/// rrr QFE number (000 indicates base release)
/// </summary>
#define XAL_VERSION "2021.10.20220111.002"
#define XAL_VERSION "2021.10.20220228.003"

}
2 changes: 2 additions & 0 deletions Include/xsapi-c/notification_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ STDAPI XblNotificationSubscribeToNotificationsAsync(
) XBL_NOEXCEPT;
#endif

#if HC_PLATFORM == HC_PLATFORM_IOS || HC_PLATFORM == HC_PLATFORM_ANDROID || HC_PLATFORM == HC_PLATFORM_UWP
/// <summary>
/// Unsubscribes the title from push notifications.
/// </summary>
Expand All @@ -44,4 +45,5 @@ STDAPI XblNotificationUnsubscribeFromNotificationsAsync(
_In_ XblContextHandle xboxLiveContext,
_In_ XAsyncBlock* asyncBlock
) XBL_NOEXCEPT;
#endif
}
4 changes: 4 additions & 0 deletions Include/xsapi-c/xbox_live_global_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#pragma warning(disable: 4062)
#endif

#if (!defined(HC_LINK_STATIC) || HC_LINK_STATIC == 0) && HC_PLATFORM_IS_APPLE
#include <HttpClient/XAsync.h>
#else
#include <XAsync.h>
#endif

extern "C"
{
Expand Down
23 changes: 12 additions & 11 deletions Source/Services/Presence/presence_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ XblFunctionContext PresenceService::AddTitlePresenceChangedHandler(
{
for (auto& titlePair : xuidPair.second.titlePresenceChangedSubscriptions)
{
titlePair.second = MakeShared<TitlePresenceChangeSubscription>(xuidPair.first, titlePair.first, shared_from_this());
m_rtaManager->AddSubscription(m_user, titlePair.second);
}
}
Expand All @@ -79,6 +80,7 @@ void PresenceService::RemoveTitlePresenceChangedHandler(
for (auto& titlePair : xuidPair.second.titlePresenceChangedSubscriptions)
{
m_rtaManager->RemoveSubscription(m_user, titlePair.second);
titlePair.second.reset();
}
}
}
Expand All @@ -95,6 +97,7 @@ XblFunctionContext PresenceService::AddDevicePresenceChangedHandler(
{
for (auto& pair : m_trackedXuids)
{
pair.second.devicePresenceChangedSub = MakeShared<DevicePresenceChangeSubscription>(pair.first, shared_from_this());
m_rtaManager->AddSubscription(m_user, pair.second.devicePresenceChangedSub);
}
}
Expand All @@ -115,6 +118,7 @@ void PresenceService::RemoveDevicePresenceChangedHandler(
for (auto& pair : m_trackedXuids)
{
m_rtaManager->RemoveSubscription(m_user, pair.second.devicePresenceChangedSub);
pair.second.devicePresenceChangedSub.reset();
}
}
}
Expand All @@ -133,23 +137,21 @@ HRESULT PresenceService::TrackUsers(
{
TrackedXuidSubscriptions newSubs{};
newSubs.refCount = 1;
newSubs.devicePresenceChangedSub = MakeShared<DevicePresenceChangeSubscription>(xuid, shared_from_this());
for (auto& pair : m_trackedTitles)
{
auto& title{ pair.first };
newSubs.titlePresenceChangedSubscriptions[title] = MakeShared<TitlePresenceChangeSubscription>(xuid, title, shared_from_this());
}

// If there are existing handlers, add the new subs to RTA managers
if (!m_devicePresenceChangedHandlers.empty())
{
newSubs.devicePresenceChangedSub = MakeShared<DevicePresenceChangeSubscription>(xuid, shared_from_this());
RETURN_HR_IF_FAILED(m_rtaManager->AddSubscription(m_user, newSubs.devicePresenceChangedSub));
}

if (!m_titlePresenceChangedHandlers.empty())
{
for (auto& pair : newSubs.titlePresenceChangedSubscriptions)
for (auto& pair : m_trackedTitles)
{
RETURN_HR_IF_FAILED(m_rtaManager->AddSubscription(m_user, pair.second));
auto sub{ MakeShared<TitlePresenceChangeSubscription>(xuid, pair.first, shared_from_this()) };
newSubs.titlePresenceChangedSubscriptions[pair.first] = sub;
RETURN_HR_IF_FAILED(m_rtaManager->AddSubscription(m_user, sub));
}
}
m_trackedXuids[xuid] = std::move(newSubs);
Expand Down Expand Up @@ -207,12 +209,11 @@ HRESULT PresenceService::TrackAdditionalTitles(
// If its a new title, create the appropriate subscriptions
for (auto& pair : m_trackedXuids)
{
auto sub{ MakeShared<TitlePresenceChangeSubscription>(pair.first, titleId, shared_from_this()) };
pair.second.titlePresenceChangedSubscriptions[titleId] = sub;

// Add new subs to RTA manager if we have handlers
if (!m_titlePresenceChangedHandlers.empty())
{
auto sub{ MakeShared<TitlePresenceChangeSubscription>(pair.first, titleId, shared_from_this()) };
pair.second.titlePresenceChangedSubscriptions[titleId] = sub;
RETURN_HR_IF_FAILED(m_rtaManager->AddSubscription(m_user, sub));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ HRESULT Connection::AddSubscription(
// If our connection is active, immediately register with RTA service
if (m_state == XblRealTimeActivityConnectionState::Connected)
{
return SendSubscribeMessage(sub);
return SendSubscribeMessage(sub, std::move(lock));
}
return S_OK;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ HRESULT Connection::RemoveSubscription(
{
// Unregister subscription from RTA service
m_unsubscribeAsyncContexts[sub->m_state->clientId] = std::move(async);
return SendUnsubscribeMessage(sub);
return SendUnsubscribeMessage(sub, std::move(lock));
}
case Subscription::State::ServiceStatus::PendingSubscribe:
{
Expand Down Expand Up @@ -333,9 +333,7 @@ size_t Connection::SubscriptionCount() const noexcept
return m_subs.size();
}

HRESULT Connection::SendSubscribeMessage(
std::shared_ptr<Subscription> sub
) const noexcept
JsonDocument Connection::AssembleSubscribeMessage(std::shared_ptr<Subscription> sub) const noexcept
{
// Payload format [<API_ID>, <SEQUENCE_N>, “<RESOURCE_URI>”]

Expand All @@ -348,14 +346,32 @@ HRESULT Connection::SendSubscribeMessage(
request.PushBack(sub->m_state->clientId, a);
request.PushBack(JsonValue{ sub->m_resourceUri.data(), a }, a);

return request;
}

HRESULT Connection::SendSubscribeMessage(
std::shared_ptr<Subscription> sub,
std::unique_lock<std::mutex>&& lock
) const noexcept
{
JsonDocument request = AssembleSubscribeMessage(sub);

lock.unlock();

return SendAssembledMessage(request);
}

HRESULT Connection::SendAssembledMessage(_In_ const JsonValue& request) const noexcept
{
String requestString{ JsonUtils::SerializeJson(request) };
LOGS_DEBUG << __FUNCTION__ << "[" << this << "]: " << requestString;

return m_websocket->Send(requestString.data());
}

HRESULT Connection::SendUnsubscribeMessage(
std::shared_ptr<Subscription> sub
std::shared_ptr<Subscription> sub,
std::unique_lock<std::mutex>&& lock
) const noexcept
{
// Payload format [<API_ID>, <SEQUENCE_N>, <SUB_ID>]
Expand All @@ -369,6 +385,8 @@ HRESULT Connection::SendUnsubscribeMessage(
request.PushBack(sub->m_state->clientId, a);
request.PushBack(sub->m_state->serviceId, a);

lock.unlock();

String requestString{ JsonUtils::SerializeJson(request) };
LOGS_DEBUG << __FUNCTION__ << "[" << this << "]: " << requestString;

Expand Down Expand Up @@ -409,6 +427,9 @@ void Connection::SubscribeResponseHandler(_In_ const JsonValue& message) noexcep
m_activeSubs[sub->m_state->serviceId][sub->m_state->clientId] = sub;
}

AsyncContext<Result<void>> asyncContext{ std::move(m_subscribeAsyncContexts[sub->m_state->clientId]) };
m_subscribeAsyncContexts.erase(sub->m_state->clientId);

switch (sub->m_state->serviceStatus)
{
case Subscription::State::ServiceStatus::Subscribing:
Expand All @@ -420,7 +441,7 @@ void Connection::SubscribeResponseHandler(_In_ const JsonValue& message) noexcep
{
// Client has removed the subscription while subscribe handshake was happening,
// so immediately begin unsubscribing.
SendUnsubscribeMessage(sub);
SendUnsubscribeMessage(sub, std::move(lock));
break;
}
default:
Expand All @@ -431,10 +452,10 @@ void Connection::SubscribeResponseHandler(_In_ const JsonValue& message) noexcep
}
}

AsyncContext<Result<void>> asyncContext{ std::move(m_subscribeAsyncContexts[sub->m_state->clientId]) };
m_subscribeAsyncContexts.erase(sub->m_state->clientId);

lock.unlock();
if (lock)
{
lock.unlock();
}

asyncContext.Complete(ConvertRTAErrorCode(errorCode));
sub->OnSubscribe(data);
Expand Down Expand Up @@ -526,6 +547,9 @@ void Connection::UnsubscribeResponseHandler(_In_ const JsonValue& message) noexc

LOGS_DEBUG << __FUNCTION__ << ": [" << sub->m_state->clientId <<"] ServiceStatus=" << EnumName(sub->m_state->serviceStatus);

AsyncContext<Result<void>> asyncContext{ std::move(m_unsubscribeAsyncContexts[clientId]) };
m_unsubscribeAsyncContexts.erase(clientId);

switch (sub->m_state->serviceStatus)
{
case Subscription::State::ServiceStatus::Unsubscribing:
Expand All @@ -539,7 +563,7 @@ void Connection::UnsubscribeResponseHandler(_In_ const JsonValue& message) noexc
{
// Client has re-added the subscription while unsubscibe handshake was happening,
// so immediately begin subscribing.
SendSubscribeMessage(sub);
SendSubscribeMessage(sub, std::move(lock));
break;
}
default:
Expand All @@ -549,10 +573,10 @@ void Connection::UnsubscribeResponseHandler(_In_ const JsonValue& message) noexc
}
}

AsyncContext<Result<void>> asyncContext{ std::move(m_unsubscribeAsyncContexts[clientId]) };
m_unsubscribeAsyncContexts.erase(clientId);

lock.unlock();
if (lock)
{
lock.unlock();
}

asyncContext.Complete(ConvertRTAErrorCode(errorCode));
}
Expand Down Expand Up @@ -611,10 +635,12 @@ void Connection::ConnectCompleteHandler(WebsocketResult result) noexcept
m_connectTime = std::chrono::system_clock::now();

assert(m_activeSubs.empty());

List<JsonDocument> subMessages{};
for (auto& pair : m_subs)
{
assert(pair.second->m_state->serviceStatus == Subscription::State::ServiceStatus::Inactive);
SendSubscribeMessage(pair.second);
subMessages.push_back(AssembleSubscribeMessage(pair.second));
}

// RTA v2 has a lifetime of 2 hours. After 2 hours RTA service will disconnect the title. On some platforms
Expand All @@ -638,6 +664,13 @@ void Connection::ConnectCompleteHandler(WebsocketResult result) noexcept
},
CONNECTION_TIMEOUT_MS
);

lock.unlock();

for (auto& request : subMessages)
{
SendAssembledMessage(request);
}
}
else
{
Expand Down Expand Up @@ -672,7 +705,11 @@ void Connection::ConnectCompleteHandler(WebsocketResult result) noexcept
);
}

lock.unlock();
if (lock)
{
lock.unlock();
}

m_stateChangedHandler(m_state);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ class Connection : public std::enable_shared_from_this<Connection>
ResyncHandler resyncHandler
) noexcept;

JsonDocument AssembleSubscribeMessage(std::shared_ptr<Subscription> sub) const noexcept;

// RTA protocol implementation
HRESULT SendSubscribeMessage(
std::shared_ptr<Subscription> subscription
std::shared_ptr<Subscription> subscription,
std::unique_lock<std::mutex>&& lock
) const noexcept;

HRESULT SendUnsubscribeMessage(
std::shared_ptr<Subscription> subscription
std::shared_ptr<Subscription> subscription,
std::unique_lock<std::mutex>&& lock
) const noexcept;

HRESULT SendAssembledMessage(_In_ const JsonValue& message) const noexcept;

void SubscribeResponseHandler(_In_ const JsonValue& message) noexcept;
void UnsubscribeResponseHandler(_In_ const JsonValue& message) noexcept;
void EventHandler(_In_ const JsonValue& message) const noexcept;
Expand Down
8 changes: 6 additions & 2 deletions Source/Services/Stats/user_statistics_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ XblFunctionContext UserStatisticsService::AddStatisticChangedHandler(
{
for (auto& statPair : userPair.second)
{
statPair.second.subscription = MakeShared<StatisticChangeSubscription>(userPair.first, statPair.first.first, statPair.first.second, shared_from_this());
m_rtaManager->AddSubscription(m_user, statPair.second.subscription);
}
}
Expand All @@ -243,6 +244,7 @@ void UserStatisticsService::RemoveStatisticChangedHandler(
for (auto& statPair : userPair.second)
{
m_rtaManager->RemoveSubscription(m_user, statPair.second.subscription);
statPair.second.subscription.reset();
}
}
}
Expand All @@ -264,12 +266,13 @@ HRESULT UserStatisticsService::TrackStatistics(
auto iter{ userStats.find({ scid, statName }) };
if (iter == userStats.end())
{
auto sub{ MakeShared<StatisticChangeSubscription>(xuid, scid, statName, shared_from_this()) };
userStats[{scid, statName}] = SubscriptionHolder{ 1, sub };
userStats[{scid, statName}] = SubscriptionHolder{ 1, nullptr };

// If there are existing handlers, add the new subs to RTA manager
if (!m_statisticChangeHandlers.empty())
{
auto sub{ MakeShared<StatisticChangeSubscription>(xuid, scid, statName, shared_from_this()) };
userStats[{scid, statName}].subscription = sub;
RETURN_HR_IF_FAILED(m_rtaManager->AddSubscription(m_user, sub));
}
}
Expand Down Expand Up @@ -327,6 +330,7 @@ HRESULT UserStatisticsService::StopTrackingUsers(
if (!m_statisticChangeHandlers.empty())
{
RETURN_HR_IF_FAILED(m_rtaManager->RemoveSubscription(m_user, statPair.second.subscription));
statPair.second.subscription.reset();
}
}
}
Expand Down
Loading

0 comments on commit f2aa2b6

Please sign in to comment.