From f9245f6a7136371f162755258b4f4a3cb8b017ac Mon Sep 17 00:00:00 2001 From: Jason Sandlin Date: Fri, 19 May 2017 17:04:42 -0700 Subject: [PATCH] Adding xbox_live_context access for C++ Xbox Live Creators so they can call privacy, profile, and title storage service APIs (#161) --- Include/xsapi/services.h | 11 +++--- Include/xsapi/title_callable_ui.h | 34 ++++++++++--------- Include/xsapi/xbox_live_context.h | 22 ++++++------ .../UWP/Cpp/GameLogic/Game.cpp | 11 ++++++ .../UWP/Cpp/GameLogic/Game.h | 3 +- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/Include/xsapi/services.h b/Include/xsapi/services.h index d717ce52..ab3b5dcc 100644 --- a/Include/xsapi/services.h +++ b/Include/xsapi/services.h @@ -15,14 +15,14 @@ #include "xsapi/leaderboard.h" #include "xsapi/social_manager.h" #include "xsapi/stats_manager.h" - -#if !defined(XBOX_LIVE_CREATORS_SDK) #include "xsapi/http_call.h" #include "xsapi/xbox_live_context_settings.h" -#include "xsapi/events.h" #include "xsapi/title_storage.h" #include "xsapi/privacy.h" #include "xsapi/profile.h" + +#if !defined(XBOX_LIVE_CREATORS_SDK) +#include "xsapi/events.h" #include "xsapi/social.h" #include "xsapi/achievements.h" #include "xsapi/user_statistics.h" @@ -34,12 +34,13 @@ #include "xsapi/game_server_platform.h" #include "xsapi/contextual_search_service.h" #include "xsapi/marketplace.h" -#include "xsapi/title_callable_ui.h" #include "xsapi/multiplayer_manager.h" #include "xsapi/entertainment_profile.h" -#include "xsapi/xbox_live_context.h" #endif // !defined(XBOX_LIVE_CREATORS_SDK) +#include "xsapi/title_callable_ui.h" +#include "xsapi/xbox_live_context.h" + #ifdef U #undef U // clean up cpprest's global define in case it's used by app #endif diff --git a/Include/xsapi/title_callable_ui.h b/Include/xsapi/title_callable_ui.h index 43c77b38..a42c05d0 100644 --- a/Include/xsapi/title_callable_ui.h +++ b/Include/xsapi/title_callable_ui.h @@ -82,6 +82,7 @@ class title_callable_ui { public: #if UWP_API +#if !defined(XBOX_LIVE_CREATORS_SDK) /// /// Shows a picker UI that allows a person playing the game to select players /// from a presented list of other people. @@ -132,22 +133,6 @@ public: _In_opt_ Windows::System::User^ user = nullptr ); - /// - /// Shows UI displaying the profile card for a specified user. - /// - /// The Xbox User ID to show information about. - /// System user that identifies the user to show the UI on behalf of - /// - /// Returns a pplx::task<T> object that represents the state of the asynchronous operation. - /// The task completes when the UI is closed. - /// result.err() contains the error based on what happened in the case of an error. - /// - _XSAPIIMP static pplx::task> - show_profile_card_ui( - _In_ const string_t& targetXboxUserId, - _In_opt_ Windows::System::User^ user = nullptr - ); - /// /// Shows UI for adding or removing a specified person to or from the requesting user's friend list. /// @@ -179,6 +164,23 @@ public: _In_ uint32_t titleId, _In_opt_ Windows::System::User^ user = nullptr ); +#endif // !defined(XBOX_LIVE_CREATORS_SDK) + + /// + /// Shows UI displaying the profile card for a specified user. + /// + /// The Xbox User ID to show information about. + /// System user that identifies the user to show the UI on behalf of + /// + /// Returns a pplx::task<T> object that represents the state of the asynchronous operation. + /// The task completes when the UI is closed. + /// result.err() contains the error based on what happened in the case of an error. + /// + _XSAPIIMP static pplx::task> + show_profile_card_ui( + _In_ const string_t& targetXboxUserId, + _In_opt_ Windows::System::User^ user = nullptr + ); /// /// Checks if the current user has a specific privilege diff --git a/Include/xsapi/xbox_live_context.h b/Include/xsapi/xbox_live_context.h index 714484ab..4dd04b63 100644 --- a/Include/xsapi/xbox_live_context.h +++ b/Include/xsapi/xbox_live_context.h @@ -128,11 +128,6 @@ public: /// _XSAPIIMP std::shared_ptr application_config(); - /// - /// A service for managing leaderboards. - /// - _XSAPIIMP leaderboard::leaderboard_service& leaderboard_service(); - /// /// A service for storing data in the cloud. /// @@ -143,6 +138,17 @@ public: /// _XSAPIIMP social::profile_service& profile_service(); + /// + /// A service for managing privacy settings. + /// + _XSAPIIMP privacy::privacy_service& privacy_service(); + +#if !defined(XBOX_LIVE_CREATORS_SDK) + /// + /// A service for managing leaderboards. + /// + _XSAPIIMP leaderboard::leaderboard_service& leaderboard_service(); + /// /// A service for managing social networking links. /// @@ -153,11 +159,6 @@ public: /// _XSAPIIMP social::reputation_service& reputation_service(); - /// - /// A service for managing privacy settings. - /// - _XSAPIIMP privacy::privacy_service& privacy_service(); - /// /// A service for managing achievements. /// @@ -231,6 +232,7 @@ public: /// _XSAPIIMP entertainment_profile::entertainment_profile_list_service& entertainment_profile_list_service(); #endif // TV_API || UNIT_TEST_SERVICES +#endif // !defined(XBOX_LIVE_CREATORS_SDK) #if (TV_API | XBOX_UWP) && defined(XSAPI_CPPWINRT) _XSAPIIMP xbox_live_context( diff --git a/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.cpp b/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.cpp index 85604e9f..64389902 100644 --- a/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.cpp +++ b/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.cpp @@ -548,6 +548,17 @@ void Game::HandleSignInResult( switch (result.status()) { case xbox::services::system::sign_in_status::success: + m_xboxLiveContext = std::make_shared(m_user); + + // These can be accessed from xbox_live_context: + m_xboxLiveContext->application_config(); + m_xboxLiveContext->privacy_service(); + m_xboxLiveContext->profile_service(); + m_xboxLiveContext->title_storage_service(); + m_xboxLiveContext->settings(); + m_xboxLiveContext->user(); + m_xboxLiveContext->xbox_live_user_id(); + AddUserToSocialManager(m_user); Log(L"Sign in succeeded"); break; diff --git a/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.h b/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.h index 53ccf359..e097f12a 100644 --- a/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.h +++ b/Tests/CreatorsCppTestApp/UWP/Cpp/GameLogic/Game.h @@ -78,7 +78,8 @@ namespace Sample static std::mutex m_socialManagerLock; private: - std::shared_ptr m_deviceResources; + std::shared_ptr m_xboxLiveContext; + std::shared_ptr m_deviceResources; std::unique_ptr m_sceneRenderer; DX::StepTimer m_timer; bool bInitialized;