From 1fb5333dbe4c173eded669e3d0911b9e15ac0512 Mon Sep 17 00:00:00 2001 From: Zaid Ismail Date: Sat, 4 Nov 2023 00:51:00 +0200 Subject: [PATCH] [Code style] Changed hard-written system and app notification ID's to enum --- src/xenia/kernel/kernel_state.cc | 18 ++++++++++-------- src/xenia/kernel/kernel_state.h | 7 +++++++ src/xenia/kernel/xam/apps/xmp_app.cc | 13 ++++++++----- src/xenia/kernel/xam/apps/xmp_app.h | 9 +++++---- src/xenia/kernel/xam/xam_ui.cc | 16 ++++++++-------- src/xenia/kernel/xam/xam_user.cc | 4 ++-- 6 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/xenia/kernel/kernel_state.cc b/src/xenia/kernel/kernel_state.cc index c6f1853a3..b0d440aaa 100644 --- a/src/xenia/kernel/kernel_state.cc +++ b/src/xenia/kernel/kernel_state.cc @@ -657,17 +657,19 @@ void KernelState::RegisterNotifyListener(XNotifyListener* listener) { if (!has_notified_startup_ && listener->mask() & 0x00000001) { has_notified_startup_ = true; // XN_SYS_UI (on, off) - listener->EnqueueNotification(0x00000009, 1); - listener->EnqueueNotification(0x00000009, 0); + listener->EnqueueNotification(kXNotificationIDSystemUI, 1); + listener->EnqueueNotification(kXNotificationIDSystemUI, 0); // XN_SYS_SIGNINCHANGED x2 - listener->EnqueueNotification(0x0000000A, 1); - listener->EnqueueNotification(0x0000000A, 1); + listener->EnqueueNotification(kXNotificationIDSystemSignInChanged, 1); + listener->EnqueueNotification(kXNotificationIDSystemSignInChanged, 1); // XN_SYS_INPUTDEVICESCHANGED x2 - listener->EnqueueNotification(0x00000012, 0); - listener->EnqueueNotification(0x00000012, 0); + listener->EnqueueNotification(kXNotificationIDSystemSignInChanged, 0); + listener->EnqueueNotification(kXNotificationIDSystemSignInChanged, 0); // XN_SYS_INPUTDEVICECONFIGCHANGED x2 - listener->EnqueueNotification(0x00000013, 0); - listener->EnqueueNotification(0x00000013, 0); + listener->EnqueueNotification( + kXNotificationIDSystemInputDeviceConfigChanged, 0); + listener->EnqueueNotification( + kXNotificationIDSystemInputDeviceConfigChanged, 0); } } diff --git a/src/xenia/kernel/kernel_state.h b/src/xenia/kernel/kernel_state.h index c38c7910b..76dab02cb 100644 --- a/src/xenia/kernel/kernel_state.h +++ b/src/xenia/kernel/kernel_state.h @@ -239,6 +239,13 @@ class KernelState { friend class XObject; }; +enum : XNotificationID { + kXNotificationIDSystemUI = 0x00000009, + kXNotificationIDSystemSignInChanged = 0x0000000A, + kXNotificationIDSystemInputDevicesChanged = 0x00000012, + kXNotificationIDSystemInputDeviceConfigChanged = 0x00000013, +}; + } // namespace kernel } // namespace xe diff --git a/src/xenia/kernel/xam/apps/xmp_app.cc b/src/xenia/kernel/xam/apps/xmp_app.cc index 2f42c1a12..af6f01dbb 100644 --- a/src/xenia/kernel/xam/apps/xmp_app.cc +++ b/src/xenia/kernel/xam/apps/xmp_app.cc @@ -142,7 +142,8 @@ X_HRESULT XmpApp::XMPPlayTitlePlaylist(uint32_t playlist_handle, active_song_index_ = 0; state_ = State::kPlaying; OnStateChanged(); - kernel_state_->BroadcastNotification(kMsgPlaybackBehaviorChanged, 1); + kernel_state_-> + BroadcastNotification(kNotificationPlaybackBehaviorChanged, 1); return X_E_SUCCESS; } @@ -202,7 +203,7 @@ X_HRESULT XmpApp::XMPPrevious() { } void XmpApp::OnStateChanged() { - kernel_state_->BroadcastNotification(kMsgStateChanged, + kernel_state_->BroadcastNotification(kNotificationStateChanged, static_cast(state_)); } @@ -270,7 +271,8 @@ X_HRESULT XmpApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr, playback_mode_ = static_cast(uint32_t(args->playback_mode)); repeat_mode_ = static_cast(uint32_t(args->repeat_mode)); unknown_flags_ = args->flags; - kernel_state_->BroadcastNotification(kMsgPlaybackBehaviorChanged, 0); + kernel_state_-> + BroadcastNotification(kNotificationPlaybackBehaviorChanged, 0); return X_E_SUCCESS; } case 0x00070009: { @@ -405,8 +407,9 @@ X_HRESULT XmpApp::DispatchMessageSync(uint32_t message, uint32_t buffer_ptr, uint32_t(args->controller), uint32_t(args->playback_client)); playback_client_ = PlaybackClient(uint32_t(args->playback_client)); - kernel_state_->BroadcastNotification(kMsgPlaybackControllerChanged, - !args->playback_client); + kernel_state_->BroadcastNotification( + kNotificationPlaybackControllerChanged, + !args->playback_client); return X_E_SUCCESS; } case 0x0007001B: { diff --git a/src/xenia/kernel/xam/apps/xmp_app.h b/src/xenia/kernel/xam/apps/xmp_app.h index 6a365c2f2..7a90ca73c 100644 --- a/src/xenia/kernel/xam/apps/xmp_app.h +++ b/src/xenia/kernel/xam/apps/xmp_app.h @@ -46,6 +46,11 @@ class XmpApp : public App { // kNoRepeat = ?, kUnknown = 0, }; + enum : XNotificationID { + kNotificationStateChanged = 0x0A000001, + kNotificationPlaybackBehaviorChanged = 0x0A000002, + kNotificationPlaybackControllerChanged = 0x0A000003, + }; struct Song { enum class Format : uint32_t { kWma = 0, @@ -92,10 +97,6 @@ class XmpApp : public App { uint32_t buffer_length) override; private: - static const uint32_t kMsgStateChanged = 0x0A000001; - static const uint32_t kMsgPlaybackBehaviorChanged = 0x0A000002; - static const uint32_t kMsgPlaybackControllerChanged = 0x0A000003; - void OnStateChanged(); State state_; diff --git a/src/xenia/kernel/xam/xam_ui.cc b/src/xenia/kernel/xam/xam_ui.cc index be8e2c892..d30389eaa 100644 --- a/src/xenia/kernel/xam/xam_ui.cc +++ b/src/xenia/kernel/xam/xam_ui.cc @@ -71,7 +71,7 @@ X_RESULT xeXamDispatchDialog(T* dialog, uint32_t overlapped) { auto pre = []() { // Broadcast XN_SYS_UI = true - kernel_state()->BroadcastNotification(0x9, true); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, true); }; auto run = [dialog, close_callback]() -> X_RESULT { X_RESULT result; @@ -95,7 +95,7 @@ X_RESULT xeXamDispatchDialog(T* dialog, auto post = []() { xe::threading::Sleep(std::chrono::milliseconds(100)); // Broadcast XN_SYS_UI = false - kernel_state()->BroadcastNotification(0x9, false); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, false); }; if (!overlapped) { pre(); @@ -114,7 +114,7 @@ X_RESULT xeXamDispatchDialogEx( uint32_t overlapped) { auto pre = []() { // Broadcast XN_SYS_UI = true - kernel_state()->BroadcastNotification(0x9, true); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, true); }; auto run = [dialog, close_callback](uint32_t& extended_error, uint32_t& length) -> X_RESULT { @@ -139,7 +139,7 @@ X_RESULT xeXamDispatchDialogEx( auto post = []() { xe::threading::Sleep(std::chrono::milliseconds(100)); // Broadcast XN_SYS_UI = false - kernel_state()->BroadcastNotification(0x9, false); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, false); }; if (!overlapped) { pre(); @@ -158,12 +158,12 @@ X_RESULT xeXamDispatchHeadless(std::function run_callback, uint32_t overlapped) { auto pre = []() { // Broadcast XN_SYS_UI = true - kernel_state()->BroadcastNotification(0x9, true); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, true); }; auto post = []() { xe::threading::Sleep(std::chrono::milliseconds(100)); // Broadcast XN_SYS_UI = false - kernel_state()->BroadcastNotification(0x9, false); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, false); }; if (!overlapped) { pre(); @@ -182,12 +182,12 @@ X_RESULT xeXamDispatchHeadlessEx( uint32_t overlapped) { auto pre = []() { // Broadcast XN_SYS_UI = true - kernel_state()->BroadcastNotification(0x9, true); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, true); }; auto post = []() { xe::threading::Sleep(std::chrono::milliseconds(100)); // Broadcast XN_SYS_UI = false - kernel_state()->BroadcastNotification(0x9, false); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, false); }; if (!overlapped) { pre(); diff --git a/src/xenia/kernel/xam/xam_user.cc b/src/xenia/kernel/xam/xam_user.cc index f9ff58439..56146d003 100644 --- a/src/xenia/kernel/xam/xam_user.cc +++ b/src/xenia/kernel/xam/xam_user.cc @@ -521,10 +521,10 @@ dword_result_t XamShowSigninUI_entry(dword_t unk, dword_t unk_mask) { // To fix game modes that display a 4 profile signin UI (even if playing // alone): // XN_SYS_SIGNINCHANGED - kernel_state()->BroadcastNotification(0x0000000A, 1); + kernel_state()->BroadcastNotification(kXNotificationIDSystemSignInChanged, 1); // Games seem to sit and loop until we trigger this notification: // XN_SYS_UI (off) - kernel_state()->BroadcastNotification(0x00000009, 0); + kernel_state()->BroadcastNotification(kXNotificationIDSystemUI, 0); return X_ERROR_SUCCESS; } DECLARE_XAM_EXPORT1(XamShowSigninUI, kUserProfiles, kStub);