aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rwxr-xr-xsrc/core/CMakeLists.txt24
-rwxr-xr-xsrc/core/core.cpp109
-rwxr-xr-xsrc/core/hle/service/am/am.cpp15
-rwxr-xr-xsrc/core/hle/service/am/am_results.h1
-rwxr-xr-xsrc/core/hle/service/am/am_types.h7
-rwxr-xr-xsrc/core/hle/service/am/applet.cpp66
-rwxr-xr-xsrc/core/hle/service/am/applet.h33
-rwxr-xr-xsrc/core/hle/service/am/applet_data_broker.cpp18
-rwxr-xr-xsrc/core/hle/service/am/applet_data_broker.h14
-rwxr-xr-xsrc/core/hle/service/am/applet_manager.cpp124
-rwxr-xr-xsrc/core/hle/service/am/applet_manager.h33
-rwxr-xr-xsrc/core/hle/service/am/frontend/applets.cpp6
-rwxr-xr-xsrc/core/hle/service/am/hid_registration.cpp10
-rwxr-xr-xsrc/core/hle/service/am/hid_registration.h6
-rwxr-xr-xsrc/core/hle/service/am/service/all_system_applet_proxies_service.cpp16
-rwxr-xr-xsrc/core/hle/service/am/service/all_system_applet_proxies_service.h5
-rwxr-xr-xsrc/core/hle/service/am/service/applet_common_functions.cpp9
-rwxr-xr-xsrc/core/hle/service/am/service/applet_common_functions.h1
-rwxr-xr-xsrc/core/hle/service/am/service/application_accessor.cpp39
-rwxr-xr-xsrc/core/hle/service/am/service/application_accessor.h5
-rwxr-xr-xsrc/core/hle/service/am/service/application_creator.cpp49
-rwxr-xr-xsrc/core/hle/service/am/service/application_creator.h5
-rwxr-xr-xsrc/core/hle/service/am/service/application_functions.cpp3
-rwxr-xr-xsrc/core/hle/service/am/service/application_proxy.cpp11
-rwxr-xr-xsrc/core/hle/service/am/service/application_proxy.h4
-rwxr-xr-xsrc/core/hle/service/am/service/application_proxy_service.cpp12
-rwxr-xr-xsrc/core/hle/service/am/service/application_proxy_service.h5
-rwxr-xr-xsrc/core/hle/service/am/service/common_state_getter.cpp9
-rwxr-xr-xsrc/core/hle/service/am/service/home_menu_functions.cpp18
-rwxr-xr-xsrc/core/hle/service/am/service/home_menu_functions.h5
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_accessor.cpp16
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_accessor.h2
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_creator.cpp49
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_creator.h5
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_proxy.cpp14
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_proxy.h4
-rwxr-xr-xsrc/core/hle/service/am/service/library_applet_self_accessor.cpp3
-rwxr-xr-xsrc/core/hle/service/am/service/self_controller.cpp37
-rwxr-xr-xsrc/core/hle/service/am/service/system_applet_proxy.cpp16
-rwxr-xr-xsrc/core/hle/service/am/service/system_applet_proxy.h4
-rwxr-xr-xsrc/core/hle/service/am/service/window_controller.cpp19
-rwxr-xr-xsrc/core/hle/service/am/service/window_controller.h5
-rwxr-xr-xsrc/core/hle/service/hid/active_vibration_device_list.cpp53
-rwxr-xr-xsrc/core/hle/service/hid/active_vibration_device_list.h39
-rwxr-xr-xsrc/core/hle/service/hid/applet_resource.cpp34
-rwxr-xr-xsrc/core/hle/service/hid/applet_resource.h36
-rwxr-xr-xsrc/core/hle/service/hid/hid.cpp4
-rwxr-xr-xsrc/core/hle/service/hid/hid_server.cpp2609
-rwxr-xr-xsrc/core/hle/service/hid/hid_server.h352
49 files changed, 1542 insertions, 2421 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 74b38eae6..419c9e650 100755
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -401,16 +401,14 @@ add_library(core STATIC
401 hle/service/am/am_types.h 401 hle/service/am/am_types.h
402 hle/service/am/applet.cpp 402 hle/service/am/applet.cpp
403 hle/service/am/applet.h 403 hle/service/am/applet.h
404 hle/service/am/applet_manager.cpp
405 hle/service/am/applet_data_broker.cpp 404 hle/service/am/applet_data_broker.cpp
406 hle/service/am/applet_data_broker.h 405 hle/service/am/applet_data_broker.h
406 hle/service/am/applet_manager.cpp
407 hle/service/am/applet_manager.h 407 hle/service/am/applet_manager.h
408 hle/service/am/button_poller.cpp 408 hle/service/am/applet_message_queue.cpp
409 hle/service/am/button_poller.h 409 hle/service/am/applet_message_queue.h
410 hle/service/am/display_layer_manager.cpp 410 hle/service/am/display_layer_manager.cpp
411 hle/service/am/display_layer_manager.h 411 hle/service/am/display_layer_manager.h
412 hle/service/am/event_observer.cpp
413 hle/service/am/event_observer.h
414 hle/service/am/frontend/applet_cabinet.cpp 412 hle/service/am/frontend/applet_cabinet.cpp
415 hle/service/am/frontend/applet_cabinet.h 413 hle/service/am/frontend/applet_cabinet.h
416 hle/service/am/frontend/applet_controller.cpp 414 hle/service/am/frontend/applet_controller.cpp
@@ -436,12 +434,8 @@ add_library(core STATIC
436 hle/service/am/hid_registration.h 434 hle/service/am/hid_registration.h
437 hle/service/am/library_applet_storage.cpp 435 hle/service/am/library_applet_storage.cpp
438 hle/service/am/library_applet_storage.h 436 hle/service/am/library_applet_storage.h
439 hle/service/am/lifecycle_manager.cpp 437 hle/service/am/process.cpp
440 hle/service/am/lifecycle_manager.h 438 hle/service/am/process.h
441 hle/service/am/process_creation.cpp
442 hle/service/am/process_creation.h
443 hle/service/am/process_holder.cpp
444 hle/service/am/process_holder.h
445 hle/service/am/service/all_system_applet_proxies_service.cpp 439 hle/service/am/service/all_system_applet_proxies_service.cpp
446 hle/service/am/service/all_system_applet_proxies_service.h 440 hle/service/am/service/all_system_applet_proxies_service.h
447 hle/service/am/service/applet_common_functions.cpp 441 hle/service/am/service/applet_common_functions.cpp
@@ -492,8 +486,6 @@ add_library(core STATIC
492 hle/service/am/service/system_applet_proxy.h 486 hle/service/am/service/system_applet_proxy.h
493 hle/service/am/service/window_controller.cpp 487 hle/service/am/service/window_controller.cpp
494 hle/service/am/service/window_controller.h 488 hle/service/am/service/window_controller.h
495 hle/service/am/window_system.cpp
496 hle/service/am/window_system.h
497 hle/service/aoc/addon_content_manager.cpp 489 hle/service/aoc/addon_content_manager.cpp
498 hle/service/aoc/addon_content_manager.h 490 hle/service/aoc/addon_content_manager.h
499 hle/service/aoc/purchase_event_manager.cpp 491 hle/service/aoc/purchase_event_manager.cpp
@@ -676,6 +668,10 @@ add_library(core STATIC
676 hle/service/glue/time/worker.h 668 hle/service/glue/time/worker.h
677 hle/service/grc/grc.cpp 669 hle/service/grc/grc.cpp
678 hle/service/grc/grc.h 670 hle/service/grc/grc.h
671 hle/service/hid/active_vibration_device_list.cpp
672 hle/service/hid/active_vibration_device_list.h
673 hle/service/hid/applet_resource.cpp
674 hle/service/hid/applet_resource.h
679 hle/service/hid/hid.cpp 675 hle/service/hid/hid.cpp
680 hle/service/hid/hid.h 676 hle/service/hid/hid.h
681 hle/service/hid/hid_debug_server.cpp 677 hle/service/hid/hid_debug_server.cpp
@@ -922,8 +918,6 @@ add_library(core STATIC
922 hle/service/os/multi_wait_utils.h 918 hle/service/os/multi_wait_utils.h
923 hle/service/os/mutex.cpp 919 hle/service/os/mutex.cpp
924 hle/service/os/mutex.h 920 hle/service/os/mutex.h
925 hle/service/os/process.cpp
926 hle/service/os/process.h
927 hle/service/pcie/pcie.cpp 921 hle/service/pcie/pcie.cpp
928 hle/service/pcie/pcie.h 922 hle/service/pcie/pcie.h
929 hle/service/pctl/parental_control_service_factory.cpp 923 hle/service/pctl/parental_control_service_factory.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index a51d3447b..56f5dd67d 100755
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -3,6 +3,7 @@
3 3
4#include <array> 4#include <array>
5#include <atomic> 5#include <atomic>
6#include <exception>
6#include <memory> 7#include <memory>
7#include <utility> 8#include <utility>
8 9
@@ -19,6 +20,7 @@
19#include "core/cpu_manager.h" 20#include "core/cpu_manager.h"
20#include "core/debugger/debugger.h" 21#include "core/debugger/debugger.h"
21#include "core/device_memory.h" 22#include "core/device_memory.h"
23#include "core/file_sys/bis_factory.h"
22#include "core/file_sys/fs_filesystem.h" 24#include "core/file_sys/fs_filesystem.h"
23#include "core/file_sys/patch_manager.h" 25#include "core/file_sys/patch_manager.h"
24#include "core/file_sys/registered_cache.h" 26#include "core/file_sys/registered_cache.h"
@@ -36,7 +38,6 @@
36#include "core/hle/service/acc/profile_manager.h" 38#include "core/hle/service/acc/profile_manager.h"
37#include "core/hle/service/am/applet_manager.h" 39#include "core/hle/service/am/applet_manager.h"
38#include "core/hle/service/am/frontend/applets.h" 40#include "core/hle/service/am/frontend/applets.h"
39#include "core/hle/service/am/process_creation.h"
40#include "core/hle/service/apm/apm_controller.h" 41#include "core/hle/service/apm/apm_controller.h"
41#include "core/hle/service/filesystem/filesystem.h" 42#include "core/hle/service/filesystem/filesystem.h"
42#include "core/hle/service/glue/glue_manager.h" 43#include "core/hle/service/glue/glue_manager.h"
@@ -71,6 +72,30 @@ MICROPROFILE_DEFINE(ARM_CPU3, "ARM", "CPU 3", MP_RGB(255, 64, 64));
71 72
72namespace Core { 73namespace Core {
73 74
75namespace {
76
77FileSys::StorageId GetStorageIdForFrontendSlot(
78 std::optional<FileSys::ContentProviderUnionSlot> slot) {
79 if (!slot.has_value()) {
80 return FileSys::StorageId::None;
81 }
82
83 switch (*slot) {
84 case FileSys::ContentProviderUnionSlot::UserNAND:
85 return FileSys::StorageId::NandUser;
86 case FileSys::ContentProviderUnionSlot::SysNAND:
87 return FileSys::StorageId::NandSystem;
88 case FileSys::ContentProviderUnionSlot::SDMC:
89 return FileSys::StorageId::SdCard;
90 case FileSys::ContentProviderUnionSlot::FrontendManual:
91 return FileSys::StorageId::Host;
92 default:
93 return FileSys::StorageId::None;
94 }
95}
96
97} // Anonymous namespace
98
74FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, 99FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
75 const std::string& path) { 100 const std::string& path) {
76 // To account for split 00+01+etc files. 101 // To account for split 00+01+etc files.
@@ -272,6 +297,9 @@ struct System::Impl {
272 } 297 }
273 298
274 SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) { 299 SystemResultStatus SetupForApplicationProcess(System& system, Frontend::EmuWindow& emu_window) {
300 /// Reset all glue registrations
301 arp_manager.ResetAll();
302
275 telemetry_session = std::make_unique<Core::TelemetrySession>(); 303 telemetry_session = std::make_unique<Core::TelemetrySession>();
276 304
277 host1x_core = std::make_unique<Tegra::Host1x::Host1x>(system); 305 host1x_core = std::make_unique<Tegra::Host1x::Host1x>(system);
@@ -307,24 +335,8 @@ struct System::Impl {
307 SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window, 335 SystemResultStatus Load(System& system, Frontend::EmuWindow& emu_window,
308 const std::string& filepath, 336 const std::string& filepath,
309 Service::AM::FrontendAppletParameters& params) { 337 Service::AM::FrontendAppletParameters& params) {
310 InitializeKernel(system); 338 app_loader = Loader::GetLoader(system, GetGameFileFromPath(virtual_filesystem, filepath),
311 339 params.program_id, params.program_index);
312 const auto file = GetGameFileFromPath(virtual_filesystem, filepath);
313
314 // Create the application process
315 Loader::ResultStatus load_result{};
316 std::vector<u8> control;
317 auto process =
318 Service::AM::CreateApplicationProcess(control, app_loader, load_result, system, file,
319 params.program_id, params.program_index);
320
321 if (load_result != Loader::ResultStatus::Success) {
322 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
323 ShutdownMainProcess();
324
325 return static_cast<SystemResultStatus>(
326 static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
327 }
328 340
329 if (!app_loader) { 341 if (!app_loader) {
330 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath); 342 LOG_CRITICAL(Core, "Failed to obtain loader for {}!", filepath);
@@ -332,7 +344,7 @@ struct System::Impl {
332 } 344 }
333 345
334 if (app_loader->ReadProgramId(params.program_id) != Loader::ResultStatus::Success) { 346 if (app_loader->ReadProgramId(params.program_id) != Loader::ResultStatus::Success) {
335 LOG_ERROR(Core, "Failed to find program id for ROM!"); 347 LOG_ERROR(Core, "Failed to find title id for ROM!");
336 } 348 }
337 349
338 std::string name = "Unknown program"; 350 std::string name = "Unknown program";
@@ -340,10 +352,23 @@ struct System::Impl {
340 LOG_ERROR(Core, "Failed to read title for ROM!"); 352 LOG_ERROR(Core, "Failed to read title for ROM!");
341 } 353 }
342 354
343 LOG_INFO(Core, "Loading {} ({:016X}) ...", name, params.program_id); 355 LOG_INFO(Core, "Loading {} ({})", name, params.program_id);
344 356
345 // Make the process created be the application 357 InitializeKernel(system);
346 kernel.MakeApplicationProcess(process->GetHandle()); 358
359 // Create the application process.
360 auto main_process = Kernel::KProcess::Create(system.Kernel());
361 Kernel::KProcess::Register(system.Kernel(), main_process);
362 kernel.AppendNewProcess(main_process);
363 kernel.MakeApplicationProcess(main_process);
364 const auto [load_result, load_parameters] = app_loader->Load(*main_process, system);
365 if (load_result != Loader::ResultStatus::Success) {
366 LOG_CRITICAL(Core, "Failed to load ROM (Error {})!", load_result);
367 ShutdownMainProcess();
368
369 return static_cast<SystemResultStatus>(
370 static_cast<u32>(SystemResultStatus::ErrorLoader) + static_cast<u32>(load_result));
371 }
347 372
348 // Set up the rest of the system. 373 // Set up the rest of the system.
349 SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)}; 374 SystemResultStatus init_result{SetupForApplicationProcess(system, emu_window)};
@@ -354,6 +379,7 @@ struct System::Impl {
354 return init_result; 379 return init_result;
355 } 380 }
356 381
382 AddGlueRegistrationForProcess(*app_loader, *main_process);
357 telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider); 383 telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider);
358 384
359 // Initialize cheat engine 385 // Initialize cheat engine
@@ -362,7 +388,13 @@ struct System::Impl {
362 } 388 }
363 389
364 // Register with applet manager. 390 // Register with applet manager.
365 applet_manager.CreateAndInsertByFrontendAppletParameters(std::move(process), params); 391 applet_manager.CreateAndInsertByFrontendAppletParameters(main_process->GetProcessId(),
392 params);
393
394 // All threads are started, begin main process execution, now that we're in the clear.
395 main_process->Run(load_parameters->main_thread_priority,
396 load_parameters->main_thread_stack_size);
397 main_process->Close();
366 398
367 if (Settings::values.gamecard_inserted) { 399 if (Settings::values.gamecard_inserted) {
368 if (Settings::values.gamecard_current_game) { 400 if (Settings::values.gamecard_current_game) {
@@ -434,6 +466,7 @@ struct System::Impl {
434 kernel.SuspendEmulation(true); 466 kernel.SuspendEmulation(true);
435 kernel.CloseServices(); 467 kernel.CloseServices();
436 kernel.ShutdownCores(); 468 kernel.ShutdownCores();
469 applet_manager.Reset();
437 services.reset(); 470 services.reset();
438 service_manager.reset(); 471 service_manager.reset();
439 fs_controller.Reset(); 472 fs_controller.Reset();
@@ -459,9 +492,6 @@ struct System::Impl {
459 // Workarounds 492 // Workarounds
460 Settings::values.renderer_amdvlk_depth_bias_workaround = false; 493 Settings::values.renderer_amdvlk_depth_bias_workaround = false;
461 494
462 // Reset all glue registrations
463 arp_manager.ResetAll();
464
465 LOG_DEBUG(Core, "Shutdown OK"); 495 LOG_DEBUG(Core, "Shutdown OK");
466 } 496 }
467 497
@@ -479,6 +509,31 @@ struct System::Impl {
479 return app_loader->ReadTitle(out); 509 return app_loader->ReadTitle(out);
480 } 510 }
481 511
512 void AddGlueRegistrationForProcess(Loader::AppLoader& loader, Kernel::KProcess& process) {
513 std::vector<u8> nacp_data;
514 FileSys::NACP nacp;
515 if (loader.ReadControlData(nacp) == Loader::ResultStatus::Success) {
516 nacp_data = nacp.GetRawBytes();
517 } else {
518 nacp_data.resize(sizeof(FileSys::RawNACP));
519 }
520
521 Service::Glue::ApplicationLaunchProperty launch{};
522 launch.title_id = process.GetProgramId();
523
524 FileSys::PatchManager pm{launch.title_id, fs_controller, *content_provider};
525 launch.version = pm.GetGameVersion().value_or(0);
526
527 // TODO(DarkLordZach): When FSController/Game Card Support is added, if
528 // current_process_game_card use correct StorageId
529 launch.base_game_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry(
530 launch.title_id, FileSys::ContentRecordType::Program));
531 launch.update_storage_id = GetStorageIdForFrontendSlot(content_provider->GetSlotForEntry(
532 FileSys::GetUpdateTitleID(launch.title_id), FileSys::ContentRecordType::Program));
533
534 arp_manager.Register(launch.title_id, launch, std::move(nacp_data));
535 }
536
482 void SetStatus(SystemResultStatus new_status, const char* details = nullptr) { 537 void SetStatus(SystemResultStatus new_status, const char* details = nullptr) {
483 status = new_status; 538 status = new_status;
484 if (details) { 539 if (details) {
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 9ec5bb48c..df2e7abd7 100755
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -2,26 +2,19 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/hle/service/am/am.h" 4#include "core/hle/service/am/am.h"
5#include "core/hle/service/am/button_poller.h"
6#include "core/hle/service/am/event_observer.h"
7#include "core/hle/service/am/service/all_system_applet_proxies_service.h" 5#include "core/hle/service/am/service/all_system_applet_proxies_service.h"
8#include "core/hle/service/am/service/application_proxy_service.h" 6#include "core/hle/service/am/service/application_proxy_service.h"
9#include "core/hle/service/am/window_system.h"
10#include "core/hle/service/server_manager.h" 7#include "core/hle/service/server_manager.h"
11 8
12namespace Service::AM { 9namespace Service::AM {
13 10
14void LoopProcess(Core::System& system) { 11void LoopProcess(Core::System& system) {
15 WindowSystem window_system(system);
16 ButtonPoller button_poller(system, window_system);
17 EventObserver event_observer(system, window_system);
18
19 auto server_manager = std::make_unique<ServerManager>(system); 12 auto server_manager = std::make_unique<ServerManager>(system);
20 13
21 server_manager->RegisterNamedService( 14 server_manager->RegisterNamedService("appletAE",
22 "appletAE", std::make_shared<IAllSystemAppletProxiesService>(system, window_system)); 15 std::make_shared<IAllSystemAppletProxiesService>(system));
23 server_manager->RegisterNamedService( 16 server_manager->RegisterNamedService("appletOE",
24 "appletOE", std::make_shared<IApplicationProxyService>(system, window_system)); 17 std::make_shared<IApplicationProxyService>(system));
25 ServerManager::RunServer(std::move(server_manager)); 18 ServerManager::RunServer(std::move(server_manager));
26} 19}
27 20
diff --git a/src/core/hle/service/am/am_results.h b/src/core/hle/service/am/am_results.h
index 44846aa2e..a2afc9eec 100755
--- a/src/core/hle/service/am/am_results.h
+++ b/src/core/hle/service/am/am_results.h
@@ -9,7 +9,6 @@ namespace Service::AM {
9 9
10constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2}; 10constexpr Result ResultNoDataInChannel{ErrorModule::AM, 2};
11constexpr Result ResultNoMessages{ErrorModule::AM, 3}; 11constexpr Result ResultNoMessages{ErrorModule::AM, 3};
12constexpr Result ResultLibraryAppletTerminated{ErrorModule::AM, 22};
13constexpr Result ResultInvalidOffset{ErrorModule::AM, 503}; 12constexpr Result ResultInvalidOffset{ErrorModule::AM, 503};
14constexpr Result ResultInvalidStorageType{ErrorModule::AM, 511}; 13constexpr Result ResultInvalidStorageType{ErrorModule::AM, 511};
15constexpr Result ResultFatalSectionCountImbalance{ErrorModule::AM, 512}; 14constexpr Result ResultFatalSectionCountImbalance{ErrorModule::AM, 512};
diff --git a/src/core/hle/service/am/am_types.h b/src/core/hle/service/am/am_types.h
index eb9ad0ac5..a14defb40 100755
--- a/src/core/hle/service/am/am_types.h
+++ b/src/core/hle/service/am/am_types.h
@@ -61,6 +61,12 @@ enum class ScreenshotPermission : u32 {
61 Disable = 2, 61 Disable = 2,
62}; 62};
63 63
64struct FocusHandlingMode {
65 bool notify;
66 bool background;
67 bool suspend;
68};
69
64enum class IdleTimeDetectionExtension : u32 { 70enum class IdleTimeDetectionExtension : u32 {
65 Disabled = 0, 71 Disabled = 0,
66 Extended = 1, 72 Extended = 1,
@@ -233,6 +239,7 @@ struct ApplicationPlayStatistics {
233static_assert(sizeof(ApplicationPlayStatistics) == 0x18, 239static_assert(sizeof(ApplicationPlayStatistics) == 0x18,
234 "ApplicationPlayStatistics has incorrect size."); 240 "ApplicationPlayStatistics has incorrect size.");
235 241
242using AppletResourceUserId = u64;
236using ProgramId = u64; 243using ProgramId = u64;
237 244
238struct Applet; 245struct Applet;
diff --git a/src/core/hle/service/am/applet.cpp b/src/core/hle/service/am/applet.cpp
index 6847f250c..5b9056c12 100755
--- a/src/core/hle/service/am/applet.cpp
+++ b/src/core/hle/service/am/applet.cpp
@@ -1,71 +1,27 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/scope_exit.h"
5
4#include "core/core.h" 6#include "core/core.h"
7#include "core/hle/service/am/am_results.h"
5#include "core/hle/service/am/applet.h" 8#include "core/hle/service/am/applet.h"
6#include "core/hle/service/am/applet_manager.h" 9#include "core/hle/service/am/applet_manager.h"
7 10
8namespace Service::AM { 11namespace Service::AM {
9 12
10Applet::Applet(Core::System& system, std::unique_ptr<Process> process_, bool is_application) 13Applet::Applet(Core::System& system, std::unique_ptr<Process> process_)
11 : context(system, "Applet"), lifecycle_manager(system, context, is_application), 14 : context(system, "Applet"), message_queue(system), process(std::move(process_)),
12 process(std::move(process_)), hid_registration(system, *process), 15 hid_registration(system, *process), gpu_error_detected_event(context),
13 gpu_error_detected_event(context), friend_invitation_storage_channel_event(context), 16 friend_invitation_storage_channel_event(context), notification_storage_channel_event(context),
14 notification_storage_channel_event(context), health_warning_disappeared_system_event(context), 17 health_warning_disappeared_system_event(context), acquired_sleep_lock_event(context),
15 acquired_sleep_lock_event(context), pop_from_general_channel_event(context), 18 pop_from_general_channel_event(context), library_applet_launchable_event(context),
16 library_applet_launchable_event(context), accumulated_suspended_tick_changed_event(context), 19 accumulated_suspended_tick_changed_event(context), sleep_lock_event(context) {
17 sleep_lock_event(context), state_changed_event(context) {
18 20
19 aruid.pid = process->GetProcessId(); 21 aruid = process->GetProcessId();
20 program_id = process->GetProgramId(); 22 program_id = process->GetProgramId();
21} 23}
22 24
23Applet::~Applet() = default; 25Applet::~Applet() = default;
24 26
25void Applet::UpdateSuspensionStateLocked(bool force_message) {
26 // Remove any forced resumption.
27 lifecycle_manager.RemoveForceResumeIfPossible();
28
29 // Check if we're runnable.
30 const bool curr_activity_runnable = lifecycle_manager.IsRunnable();
31 const bool prev_activity_runnable = is_activity_runnable;
32 const bool was_changed = curr_activity_runnable != prev_activity_runnable;
33
34 if (was_changed) {
35 if (curr_activity_runnable) {
36 process->Suspend(false);
37 } else {
38 process->Suspend(true);
39 lifecycle_manager.RequestResumeNotification();
40 }
41
42 is_activity_runnable = curr_activity_runnable;
43 }
44
45 if (lifecycle_manager.GetForcedSuspend()) {
46 // TODO: why is this allowed?
47 return;
48 }
49
50 // Signal if the focus state was changed or the process state was changed.
51 if (lifecycle_manager.UpdateRequestedFocusState() || was_changed || force_message) {
52 lifecycle_manager.SignalSystemEventIfNeeded();
53 }
54}
55
56void Applet::SetInteractibleLocked(bool interactible) {
57 if (is_interactible == interactible) {
58 return;
59 }
60
61 is_interactible = interactible;
62
63 hid_registration.EnableAppletToGetInput(interactible && !lifecycle_manager.GetExitRequested());
64}
65
66void Applet::OnProcessTerminatedLocked() {
67 is_completed = true;
68 state_changed_event.Signal();
69}
70
71} // namespace Service::AM 27} // namespace Service::AM
diff --git a/src/core/hle/service/am/applet.h b/src/core/hle/service/am/applet.h
index 571904fab..ad602153e 100755
--- a/src/core/hle/service/am/applet.h
+++ b/src/core/hle/service/am/applet.h
@@ -3,28 +3,25 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <deque>
7#include <mutex> 6#include <mutex>
8 7
9#include "common/math_util.h" 8#include "common/math_util.h"
10#include "core/hle/service/apm/apm_controller.h" 9#include "core/hle/service/apm/apm_controller.h"
11#include "core/hle/service/caps/caps_types.h" 10#include "core/hle/service/caps/caps_types.h"
12#include "core/hle/service/cmif_types.h"
13#include "core/hle/service/kernel_helpers.h" 11#include "core/hle/service/kernel_helpers.h"
14#include "core/hle/service/os/event.h" 12#include "core/hle/service/os/event.h"
15#include "core/hle/service/os/process.h"
16#include "core/hle/service/service.h" 13#include "core/hle/service/service.h"
17 14
18#include "core/hle/service/am/am_types.h" 15#include "core/hle/service/am/am_types.h"
16#include "core/hle/service/am/applet_message_queue.h"
19#include "core/hle/service/am/display_layer_manager.h" 17#include "core/hle/service/am/display_layer_manager.h"
20#include "core/hle/service/am/hid_registration.h" 18#include "core/hle/service/am/hid_registration.h"
21#include "core/hle/service/am/lifecycle_manager.h" 19#include "core/hle/service/am/process.h"
22#include "core/hle/service/am/process_holder.h"
23 20
24namespace Service::AM { 21namespace Service::AM {
25 22
26struct Applet { 23struct Applet {
27 explicit Applet(Core::System& system, std::unique_ptr<Process> process_, bool is_application); 24 explicit Applet(Core::System& system, std::unique_ptr<Process> process_);
28 ~Applet(); 25 ~Applet();
29 26
30 // Lock 27 // Lock
@@ -33,13 +30,11 @@ struct Applet {
33 // Event creation helper 30 // Event creation helper
34 KernelHelpers::ServiceContext context; 31 KernelHelpers::ServiceContext context;
35 32
36 // Lifecycle manager 33 // Applet message queue
37 LifecycleManager lifecycle_manager; 34 AppletMessageQueue message_queue;
38 35
39 // Process 36 // Process
40 std::unique_ptr<Process> process; 37 std::unique_ptr<Process> process;
41 std::optional<ProcessHolder> process_holder;
42 bool is_process_running{};
43 38
44 // Creation state 39 // Creation state
45 AppletId applet_id{}; 40 AppletId applet_id{};
@@ -80,9 +75,11 @@ struct Applet {
80 bool game_play_recording_supported{}; 75 bool game_play_recording_supported{};
81 GamePlayRecordingState game_play_recording_state{GamePlayRecordingState::Disabled}; 76 GamePlayRecordingState game_play_recording_state{GamePlayRecordingState::Disabled};
82 bool jit_service_launched{}; 77 bool jit_service_launched{};
78 bool is_running{};
83 bool application_crash_report_enabled{}; 79 bool application_crash_report_enabled{};
84 80
85 // Common state 81 // Common state
82 FocusState focus_state{};
86 bool sleep_lock_enabled{}; 83 bool sleep_lock_enabled{};
87 bool vr_mode_enabled{}; 84 bool vr_mode_enabled{};
88 bool lcd_backlight_off_enabled{}; 85 bool lcd_backlight_off_enabled{};
@@ -96,12 +93,15 @@ struct Applet {
96 // Caller applet 93 // Caller applet
97 std::weak_ptr<Applet> caller_applet{}; 94 std::weak_ptr<Applet> caller_applet{};
98 std::shared_ptr<AppletDataBroker> caller_applet_broker{}; 95 std::shared_ptr<AppletDataBroker> caller_applet_broker{};
99 std::list<std::shared_ptr<Applet>> child_applets{};
100 bool is_completed{};
101 96
102 // Self state 97 // Self state
103 bool exit_locked{}; 98 bool exit_locked{};
104 s32 fatal_section_count{}; 99 s32 fatal_section_count{};
100 bool operation_mode_changed_notification_enabled{true};
101 bool performance_mode_changed_notification_enabled{true};
102 FocusHandlingMode focus_handling_mode{};
103 bool restart_message_enabled{};
104 bool out_of_focus_suspension_enabled{true};
105 Capture::AlbumImageOrientation album_image_orientation{}; 105 Capture::AlbumImageOrientation album_image_orientation{};
106 bool handles_request_to_display{}; 106 bool handles_request_to_display{};
107 ScreenshotPermission screenshot_permission{}; 107 ScreenshotPermission screenshot_permission{};
@@ -110,9 +110,6 @@ struct Applet {
110 u64 suspended_ticks{}; 110 u64 suspended_ticks{};
111 bool album_image_taken_notification_enabled{}; 111 bool album_image_taken_notification_enabled{};
112 bool record_volume_muted{}; 112 bool record_volume_muted{};
113 bool is_activity_runnable{};
114 bool is_interactible{true};
115 bool window_visible{true};
116 113
117 // Events 114 // Events
118 Event gpu_error_detected_event; 115 Event gpu_error_detected_event;
@@ -124,15 +121,9 @@ struct Applet {
124 Event library_applet_launchable_event; 121 Event library_applet_launchable_event;
125 Event accumulated_suspended_tick_changed_event; 122 Event accumulated_suspended_tick_changed_event;
126 Event sleep_lock_event; 123 Event sleep_lock_event;
127 Event state_changed_event;
128 124
129 // Frontend state 125 // Frontend state
130 std::shared_ptr<Frontend::FrontendApplet> frontend{}; 126 std::shared_ptr<Frontend::FrontendApplet> frontend{};
131
132 // Process state management
133 void UpdateSuspensionStateLocked(bool force_message);
134 void SetInteractibleLocked(bool interactible);
135 void OnProcessTerminatedLocked();
136}; 127};
137 128
138} // namespace Service::AM 129} // namespace Service::AM
diff --git a/src/core/hle/service/am/applet_data_broker.cpp b/src/core/hle/service/am/applet_data_broker.cpp
index fff78c5af..9057244a9 100755
--- a/src/core/hle/service/am/applet_data_broker.cpp
+++ b/src/core/hle/service/am/applet_data_broker.cpp
@@ -44,8 +44,24 @@ Kernel::KReadableEvent* AppletStorageChannel::GetEvent() {
44 44
45AppletDataBroker::AppletDataBroker(Core::System& system_) 45AppletDataBroker::AppletDataBroker(Core::System& system_)
46 : system(system_), context(system_, "AppletDataBroker"), in_data(context), 46 : system(system_), context(system_, "AppletDataBroker"), in_data(context),
47 interactive_in_data(context), out_data(context), interactive_out_data(context) {} 47 interactive_in_data(context), out_data(context), interactive_out_data(context),
48 state_changed_event(context), is_completed(false) {}
48 49
49AppletDataBroker::~AppletDataBroker() = default; 50AppletDataBroker::~AppletDataBroker() = default;
50 51
52void AppletDataBroker::SignalCompletion() {
53 {
54 std::scoped_lock lk{lock};
55
56 if (is_completed) {
57 return;
58 }
59
60 is_completed = true;
61 state_changed_event.Signal();
62 }
63
64 system.GetAppletManager().FocusStateChanged();
65}
66
51} // namespace Service::AM 67} // namespace Service::AM
diff --git a/src/core/hle/service/am/applet_data_broker.h b/src/core/hle/service/am/applet_data_broker.h
index 2718f608a..5a1d43c11 100755
--- a/src/core/hle/service/am/applet_data_broker.h
+++ b/src/core/hle/service/am/applet_data_broker.h
@@ -53,6 +53,16 @@ public:
53 return interactive_out_data; 53 return interactive_out_data;
54 } 54 }
55 55
56 Event& GetStateChangedEvent() {
57 return state_changed_event;
58 }
59
60 bool IsCompleted() const {
61 return is_completed;
62 }
63
64 void SignalCompletion();
65
56private: 66private:
57 Core::System& system; 67 Core::System& system;
58 KernelHelpers::ServiceContext context; 68 KernelHelpers::ServiceContext context;
@@ -61,6 +71,10 @@ private:
61 AppletStorageChannel interactive_in_data; 71 AppletStorageChannel interactive_in_data;
62 AppletStorageChannel out_data; 72 AppletStorageChannel out_data;
63 AppletStorageChannel interactive_out_data; 73 AppletStorageChannel interactive_out_data;
74 Event state_changed_event;
75
76 std::mutex lock;
77 bool is_completed;
64}; 78};
65 79
66} // namespace Service::AM 80} // namespace Service::AM
diff --git a/src/core/hle/service/am/applet_manager.cpp b/src/core/hle/service/am/applet_manager.cpp
index c6b7ec8bb..2e109181d 100755
--- a/src/core/hle/service/am/applet_manager.cpp
+++ b/src/core/hle/service/am/applet_manager.cpp
@@ -13,7 +13,6 @@
13#include "core/hle/service/am/frontend/applet_mii_edit_types.h" 13#include "core/hle/service/am/frontend/applet_mii_edit_types.h"
14#include "core/hle/service/am/frontend/applet_software_keyboard_types.h" 14#include "core/hle/service/am/frontend/applet_software_keyboard_types.h"
15#include "core/hle/service/am/service/storage.h" 15#include "core/hle/service/am/service/storage.h"
16#include "core/hle/service/am/window_system.h"
17#include "hid_core/hid_types.h" 16#include "hid_core/hid_types.h"
18 17
19namespace Service::AM { 18namespace Service::AM {
@@ -226,46 +225,49 @@ void PushInShowSoftwareKeyboard(Core::System& system, AppletStorageChannel& chan
226} // namespace 225} // namespace
227 226
228AppletManager::AppletManager(Core::System& system) : m_system(system) {} 227AppletManager::AppletManager(Core::System& system) : m_system(system) {}
229AppletManager::~AppletManager() = default; 228AppletManager::~AppletManager() {
230 229 this->Reset();
231void AppletManager::CreateAndInsertByFrontendAppletParameters(
232 std::unique_ptr<Process> process, const FrontendAppletParameters& params) {
233 {
234 std::scoped_lock lk{m_lock};
235 m_pending_process = std::move(process);
236 m_pending_parameters = params;
237 }
238 m_cv.notify_all();
239} 230}
240 231
241void AppletManager::RequestExit() { 232void AppletManager::InsertApplet(std::shared_ptr<Applet> applet) {
242 std::scoped_lock lk{m_lock}; 233 std::scoped_lock lk{m_lock};
243 if (m_window_system) {
244 m_window_system->OnExitRequested();
245 }
246}
247 234
248void AppletManager::OperationModeChanged() { 235 m_applets.emplace(applet->aruid, std::move(applet));
249 std::scoped_lock lk{m_lock};
250 if (m_window_system) {
251 m_window_system->OnOperationModeChanged();
252 }
253} 236}
254 237
255void AppletManager::SetWindowSystem(WindowSystem* window_system) { 238void AppletManager::TerminateAndRemoveApplet(AppletResourceUserId aruid) {
256 std::unique_lock lk{m_lock}; 239 std::shared_ptr<Applet> applet;
240 bool should_stop = false;
241 {
242 std::scoped_lock lk{m_lock};
257 243
258 m_window_system = window_system; 244 const auto it = m_applets.find(aruid);
259 if (!m_window_system) { 245 if (it == m_applets.end()) {
260 return; 246 return;
247 }
248
249 applet = it->second;
250 m_applets.erase(it);
251
252 should_stop = m_applets.empty();
261 } 253 }
262 254
263 m_cv.wait(lk, [&] { return m_pending_process != nullptr; }); 255 // Terminate process.
256 applet->process->Terminate();
257
258 // If there were no applets left, stop emulation.
259 if (should_stop) {
260 m_system.Exit();
261 }
262}
264 263
265 const auto& params = m_pending_parameters; 264void AppletManager::CreateAndInsertByFrontendAppletParameters(
266 auto applet = std::make_shared<Applet>(m_system, std::move(m_pending_process), 265 AppletResourceUserId aruid, const FrontendAppletParameters& params) {
267 params.applet_id == AppletId::Application); 266 // TODO: this should be run inside AM so that the events will have a parent process
267 // TODO: have am create the guest process
268 auto applet = std::make_shared<Applet>(m_system, std::make_unique<Process>(m_system));
268 269
270 applet->aruid = aruid;
269 applet->program_id = params.program_id; 271 applet->program_id = params.program_id;
270 applet->applet_id = params.applet_id; 272 applet->applet_id = params.applet_id;
271 applet->type = params.applet_type; 273 applet->type = params.applet_type;
@@ -320,19 +322,59 @@ void AppletManager::SetWindowSystem(WindowSystem* window_system) {
320 } 322 }
321 323
322 // Applet was started by frontend, so it is foreground. 324 // Applet was started by frontend, so it is foreground.
323 applet->lifecycle_manager.SetFocusState(FocusState::InFocus); 325 applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground);
324 326 applet->message_queue.PushMessage(AppletMessage::FocusStateChanged);
325 if (applet->applet_id == AppletId::QLaunch) { 327 applet->focus_state = FocusState::InFocus;
326 applet->lifecycle_manager.SetFocusHandlingMode(false); 328
327 applet->lifecycle_manager.SetOutOfFocusSuspendingEnabled(false); 329 this->InsertApplet(std::move(applet));
328 m_window_system->TrackApplet(applet, false); 330}
329 m_window_system->RequestHomeMenuToGetForeground(); 331
330 } else { 332std::shared_ptr<Applet> AppletManager::GetByAppletResourceUserId(AppletResourceUserId aruid) const {
331 m_window_system->TrackApplet(applet, true); 333 std::scoped_lock lk{m_lock};
332 m_window_system->RequestApplicationToGetForeground(); 334
335 if (const auto it = m_applets.find(aruid); it != m_applets.end()) {
336 return it->second;
337 }
338
339 return {};
340}
341
342void AppletManager::Reset() {
343 std::scoped_lock lk{m_lock};
344
345 m_applets.clear();
346}
347
348void AppletManager::RequestExit() {
349 std::scoped_lock lk{m_lock};
350
351 for (const auto& [aruid, applet] : m_applets) {
352 applet->message_queue.RequestExit();
333 } 353 }
354}
355
356void AppletManager::RequestResume() {
357 std::scoped_lock lk{m_lock};
334 358
335 applet->process->Run(); 359 for (const auto& [aruid, applet] : m_applets) {
360 applet->message_queue.RequestResume();
361 }
362}
363
364void AppletManager::OperationModeChanged() {
365 std::scoped_lock lk{m_lock};
366
367 for (const auto& [aruid, applet] : m_applets) {
368 applet->message_queue.OperationModeChanged();
369 }
370}
371
372void AppletManager::FocusStateChanged() {
373 std::scoped_lock lk{m_lock};
374
375 for (const auto& [aruid, applet] : m_applets) {
376 applet->message_queue.FocusStateChanged();
377 }
336} 378}
337 379
338} // namespace Service::AM 380} // namespace Service::AM
diff --git a/src/core/hle/service/am/applet_manager.h b/src/core/hle/service/am/applet_manager.h
index fbdc77140..4875de309 100755
--- a/src/core/hle/service/am/applet_manager.h
+++ b/src/core/hle/service/am/applet_manager.h
@@ -3,23 +3,17 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <condition_variable> 6#include <map>
7#include <mutex> 7#include <mutex>
8 8
9#include "core/hle/service/am/am_types.h" 9#include "core/hle/service/am/applet.h"
10 10
11namespace Core { 11namespace Core {
12class System; 12class System;
13} 13}
14 14
15namespace Service {
16class Process;
17}
18
19namespace Service::AM { 15namespace Service::AM {
20 16
21class WindowSystem;
22
23enum class LaunchType { 17enum class LaunchType {
24 FrontendInitiated, 18 FrontendInitiated,
25 ApplicationInitiated, 19 ApplicationInitiated,
@@ -39,24 +33,27 @@ public:
39 explicit AppletManager(Core::System& system); 33 explicit AppletManager(Core::System& system);
40 ~AppletManager(); 34 ~AppletManager();
41 35
42 void CreateAndInsertByFrontendAppletParameters(std::unique_ptr<Process> process, 36 void InsertApplet(std::shared_ptr<Applet> applet);
37 void TerminateAndRemoveApplet(AppletResourceUserId aruid);
38
39 void CreateAndInsertByFrontendAppletParameters(AppletResourceUserId aruid,
43 const FrontendAppletParameters& params); 40 const FrontendAppletParameters& params);
41 std::shared_ptr<Applet> GetByAppletResourceUserId(AppletResourceUserId aruid) const;
42
43 void Reset();
44
44 void RequestExit(); 45 void RequestExit();
46 void RequestResume();
45 void OperationModeChanged(); 47 void OperationModeChanged();
46 48 void FocusStateChanged();
47public:
48 void SetWindowSystem(WindowSystem* window_system);
49 49
50private: 50private:
51 Core::System& m_system; 51 Core::System& m_system;
52 52
53 std::mutex m_lock; 53 mutable std::mutex m_lock{};
54 std::condition_variable m_cv; 54 std::map<AppletResourceUserId, std::shared_ptr<Applet>> m_applets{};
55
56 WindowSystem* m_window_system{};
57 55
58 FrontendAppletParameters m_pending_parameters{}; 56 // AudioController state goes here
59 std::unique_ptr<Process> m_pending_process{};
60}; 57};
61 58
62} // namespace Service::AM 59} // namespace Service::AM
diff --git a/src/core/hle/service/am/frontend/applets.cpp b/src/core/hle/service/am/frontend/applets.cpp
index cdd431857..e662c6cd6 100755
--- a/src/core/hle/service/am/frontend/applets.cpp
+++ b/src/core/hle/service/am/frontend/applets.cpp
@@ -69,11 +69,7 @@ void FrontendApplet::PushInteractiveOutData(std::shared_ptr<IStorage> storage) {
69} 69}
70 70
71void FrontendApplet::Exit() { 71void FrontendApplet::Exit() {
72 auto applet_ = applet.lock(); 72 applet.lock()->caller_applet_broker->SignalCompletion();
73
74 std::scoped_lock lk{applet_->lock};
75 applet_->is_completed = true;
76 applet_->state_changed_event.Signal();
77} 73}
78 74
79FrontendAppletSet::FrontendAppletSet() = default; 75FrontendAppletSet::FrontendAppletSet() = default;
diff --git a/src/core/hle/service/am/hid_registration.cpp b/src/core/hle/service/am/hid_registration.cpp
index ea4bd8f45..8ed49bac1 100755
--- a/src/core/hle/service/am/hid_registration.cpp
+++ b/src/core/hle/service/am/hid_registration.cpp
@@ -3,28 +3,24 @@
3 3
4#include "core/core.h" 4#include "core/core.h"
5#include "core/hle/service/am/hid_registration.h" 5#include "core/hle/service/am/hid_registration.h"
6#include "core/hle/service/am/process.h"
6#include "core/hle/service/hid/hid_server.h" 7#include "core/hle/service/hid/hid_server.h"
7#include "core/hle/service/os/process.h"
8#include "core/hle/service/sm/sm.h" 8#include "core/hle/service/sm/sm.h"
9#include "hid_core/resource_manager.h" 9#include "hid_core/resource_manager.h"
10 10
11namespace Service::AM { 11namespace Service::AM {
12 12
13HidRegistration::HidRegistration(Core::System& system, Process& process) : m_process(process) { 13HidRegistration::HidRegistration(Core::System& system, Process& process) : m_process(process) {
14 m_hid_server = system.ServiceManager().GetService<HID::IHidServer>("hid", true); 14 m_hid_server = system.ServiceManager().GetService<HID::IHidServer>("hid");
15 15
16 if (m_process.IsInitialized()) { 16 if (m_process.IsInitialized()) {
17 m_hid_server->GetResourceManager()->RegisterAppletResourceUserId(m_process.GetProcessId(), 17 m_hid_server->GetResourceManager()->RegisterAppletResourceUserId(m_process.GetProcessId(),
18 true); 18 true);
19 m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(),
20 true);
21 } 19 }
22} 20}
23 21
24HidRegistration::~HidRegistration() { 22HidRegistration::~HidRegistration() {
25 if (m_process.IsInitialized()) { 23 if (m_process.IsInitialized()) {
26 m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(),
27 false);
28 m_hid_server->GetResourceManager()->UnregisterAppletResourceUserId( 24 m_hid_server->GetResourceManager()->UnregisterAppletResourceUserId(
29 m_process.GetProcessId()); 25 m_process.GetProcessId());
30 } 26 }
@@ -32,8 +28,6 @@ HidRegistration::~HidRegistration() {
32 28
33void HidRegistration::EnableAppletToGetInput(bool enable) { 29void HidRegistration::EnableAppletToGetInput(bool enable) {
34 if (m_process.IsInitialized()) { 30 if (m_process.IsInitialized()) {
35 m_hid_server->GetResourceManager()->SetAruidValidForVibration(m_process.GetProcessId(),
36 enable);
37 m_hid_server->GetResourceManager()->EnableInput(m_process.GetProcessId(), enable); 31 m_hid_server->GetResourceManager()->EnableInput(m_process.GetProcessId(), enable);
38 } 32 }
39} 33}
diff --git a/src/core/hle/service/am/hid_registration.h b/src/core/hle/service/am/hid_registration.h
index 54f42af18..67cd84961 100755
--- a/src/core/hle/service/am/hid_registration.h
+++ b/src/core/hle/service/am/hid_registration.h
@@ -13,12 +13,10 @@ namespace Service::HID {
13class IHidServer; 13class IHidServer;
14} 14}
15 15
16namespace Service {
17class Process;
18}
19
20namespace Service::AM { 16namespace Service::AM {
21 17
18class Process;
19
22class HidRegistration { 20class HidRegistration {
23public: 21public:
24 explicit HidRegistration(Core::System& system, Process& process); 22 explicit HidRegistration(Core::System& system, Process& process);
diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp
index bc9c86c55..21747783a 100755
--- a/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp
+++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.cpp
@@ -6,14 +6,12 @@
6#include "core/hle/service/am/service/all_system_applet_proxies_service.h" 6#include "core/hle/service/am/service/all_system_applet_proxies_service.h"
7#include "core/hle/service/am/service/library_applet_proxy.h" 7#include "core/hle/service/am/service/library_applet_proxy.h"
8#include "core/hle/service/am/service/system_applet_proxy.h" 8#include "core/hle/service/am/service/system_applet_proxy.h"
9#include "core/hle/service/am/window_system.h"
10#include "core/hle/service/cmif_serialization.h" 9#include "core/hle/service/cmif_serialization.h"
11 10
12namespace Service::AM { 11namespace Service::AM {
13 12
14IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_, 13IAllSystemAppletProxiesService::IAllSystemAppletProxiesService(Core::System& system_)
15 WindowSystem& window_system) 14 : ServiceFramework{system_, "appletAE"} {
16 : ServiceFramework{system_, "appletAE"}, m_window_system{window_system} {
17 // clang-format off 15 // clang-format off
18 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
19 {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"}, 17 {100, D<&IAllSystemAppletProxiesService::OpenSystemAppletProxy>, "OpenSystemAppletProxy"},
@@ -38,8 +36,8 @@ Result IAllSystemAppletProxiesService::OpenSystemAppletProxy(
38 LOG_DEBUG(Service_AM, "called"); 36 LOG_DEBUG(Service_AM, "called");
39 37
40 if (const auto applet = this->GetAppletFromProcessId(pid); applet) { 38 if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
41 *out_system_applet_proxy = std::make_shared<ISystemAppletProxy>( 39 *out_system_applet_proxy =
42 system, applet, process_handle.Get(), m_window_system); 40 std::make_shared<ISystemAppletProxy>(system, applet, process_handle.Get());
43 R_SUCCEED(); 41 R_SUCCEED();
44 } else { 42 } else {
45 UNIMPLEMENTED(); 43 UNIMPLEMENTED();
@@ -54,8 +52,8 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxy(
54 LOG_DEBUG(Service_AM, "called"); 52 LOG_DEBUG(Service_AM, "called");
55 53
56 if (const auto applet = this->GetAppletFromProcessId(pid); applet) { 54 if (const auto applet = this->GetAppletFromProcessId(pid); applet) {
57 *out_library_applet_proxy = std::make_shared<ILibraryAppletProxy>( 55 *out_library_applet_proxy =
58 system, applet, process_handle.Get(), m_window_system); 56 std::make_shared<ILibraryAppletProxy>(system, applet, process_handle.Get());
59 R_SUCCEED(); 57 R_SUCCEED();
60 } else { 58 } else {
61 UNIMPLEMENTED(); 59 UNIMPLEMENTED();
@@ -75,7 +73,7 @@ Result IAllSystemAppletProxiesService::OpenLibraryAppletProxyOld(
75 73
76std::shared_ptr<Applet> IAllSystemAppletProxiesService::GetAppletFromProcessId( 74std::shared_ptr<Applet> IAllSystemAppletProxiesService::GetAppletFromProcessId(
77 ProcessId process_id) { 75 ProcessId process_id) {
78 return m_window_system.GetByAppletResourceUserId(process_id.pid); 76 return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid);
79} 77}
80 78
81} // namespace Service::AM 79} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/all_system_applet_proxies_service.h b/src/core/hle/service/am/service/all_system_applet_proxies_service.h
index e3e79dc4f..0e2dcb86d 100755
--- a/src/core/hle/service/am/service/all_system_applet_proxies_service.h
+++ b/src/core/hle/service/am/service/all_system_applet_proxies_service.h
@@ -14,12 +14,11 @@ struct Applet;
14struct AppletAttribute; 14struct AppletAttribute;
15class ILibraryAppletProxy; 15class ILibraryAppletProxy;
16class ISystemAppletProxy; 16class ISystemAppletProxy;
17class WindowSystem;
18 17
19class IAllSystemAppletProxiesService final 18class IAllSystemAppletProxiesService final
20 : public ServiceFramework<IAllSystemAppletProxiesService> { 19 : public ServiceFramework<IAllSystemAppletProxiesService> {
21public: 20public:
22 explicit IAllSystemAppletProxiesService(Core::System& system_, WindowSystem& window_system); 21 explicit IAllSystemAppletProxiesService(Core::System& system_);
23 ~IAllSystemAppletProxiesService() override; 22 ~IAllSystemAppletProxiesService() override;
24 23
25private: 24private:
@@ -36,8 +35,6 @@ private:
36 35
37private: 36private:
38 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); 37 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
39
40 WindowSystem& m_window_system;
41}; 38};
42 39
43} // namespace AM 40} // namespace AM
diff --git a/src/core/hle/service/am/service/applet_common_functions.cpp b/src/core/hle/service/am/service/applet_common_functions.cpp
index a051000af..0f29ab285 100755
--- a/src/core/hle/service/am/service/applet_common_functions.cpp
+++ b/src/core/hle/service/am/service/applet_common_functions.cpp
@@ -19,7 +19,7 @@ IAppletCommonFunctions::IAppletCommonFunctions(Core::System& system_,
19 {21, nullptr, "TryPopFromAppletBoundChannel"}, 19 {21, nullptr, "TryPopFromAppletBoundChannel"},
20 {40, nullptr, "GetDisplayLogicalResolution"}, 20 {40, nullptr, "GetDisplayLogicalResolution"},
21 {42, nullptr, "SetDisplayMagnification"}, 21 {42, nullptr, "SetDisplayMagnification"},
22 {50, D<&IAppletCommonFunctions::SetHomeButtonDoubleClickEnabled>, "SetHomeButtonDoubleClickEnabled"}, 22 {50, nullptr, "SetHomeButtonDoubleClickEnabled"},
23 {51, D<&IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled>, "GetHomeButtonDoubleClickEnabled"}, 23 {51, D<&IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled>, "GetHomeButtonDoubleClickEnabled"},
24 {52, nullptr, "IsHomeButtonShortPressedBlocked"}, 24 {52, nullptr, "IsHomeButtonShortPressedBlocked"},
25 {60, nullptr, "IsVrModeCurtainRequired"}, 25 {60, nullptr, "IsVrModeCurtainRequired"},
@@ -40,13 +40,6 @@ IAppletCommonFunctions::IAppletCommonFunctions(Core::System& system_,
40 40
41IAppletCommonFunctions::~IAppletCommonFunctions() = default; 41IAppletCommonFunctions::~IAppletCommonFunctions() = default;
42 42
43Result IAppletCommonFunctions::SetHomeButtonDoubleClickEnabled(
44 bool home_button_double_click_enabled) {
45 LOG_WARNING(Service_AM, "(STUBBED) called, home_button_double_click_enabled={}",
46 home_button_double_click_enabled);
47 R_SUCCEED();
48}
49
50Result IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled( 43Result IAppletCommonFunctions::GetHomeButtonDoubleClickEnabled(
51 Out<bool> out_home_button_double_click_enabled) { 44 Out<bool> out_home_button_double_click_enabled) {
52 LOG_WARNING(Service_AM, "(STUBBED) called"); 45 LOG_WARNING(Service_AM, "(STUBBED) called");
diff --git a/src/core/hle/service/am/service/applet_common_functions.h b/src/core/hle/service/am/service/applet_common_functions.h
index 376f85acf..4424fc83d 100755
--- a/src/core/hle/service/am/service/applet_common_functions.h
+++ b/src/core/hle/service/am/service/applet_common_functions.h
@@ -16,7 +16,6 @@ public:
16 ~IAppletCommonFunctions() override; 16 ~IAppletCommonFunctions() override;
17 17
18private: 18private:
19 Result SetHomeButtonDoubleClickEnabled(bool home_button_double_click_enabled);
20 Result GetHomeButtonDoubleClickEnabled(Out<bool> out_home_button_double_click_enabled); 19 Result GetHomeButtonDoubleClickEnabled(Out<bool> out_home_button_double_click_enabled);
21 Result SetCpuBoostRequestPriority(s32 priority); 20 Result SetCpuBoostRequestPriority(s32 priority);
22 Result GetCurrentApplicationId(Out<u64> out_application_id); 21 Result GetCurrentApplicationId(Out<u64> out_application_id);
diff --git a/src/core/hle/service/am/service/application_accessor.cpp b/src/core/hle/service/am/service/application_accessor.cpp
index 986abc716..6e7d110e8 100755
--- a/src/core/hle/service/am/service/application_accessor.cpp
+++ b/src/core/hle/service/am/service/application_accessor.cpp
@@ -9,16 +9,12 @@
9#include "core/hle/service/am/service/application_accessor.h" 9#include "core/hle/service/am/service/application_accessor.h"
10#include "core/hle/service/am/service/library_applet_accessor.h" 10#include "core/hle/service/am/service/library_applet_accessor.h"
11#include "core/hle/service/am/service/storage.h" 11#include "core/hle/service/am/service/storage.h"
12#include "core/hle/service/am/window_system.h"
13#include "core/hle/service/cmif_serialization.h" 12#include "core/hle/service/cmif_serialization.h"
14#include "core/hle/service/glue/glue_manager.h"
15 13
16namespace Service::AM { 14namespace Service::AM {
17 15
18IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet, 16IApplicationAccessor::IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet)
19 WindowSystem& window_system) 17 : ServiceFramework{system_, "IApplicationAccessor"}, m_applet(std::move(applet)) {
20 : ServiceFramework{system_, "IApplicationAccessor"}, m_window_system(window_system),
21 m_applet(std::move(applet)) {
22 // clang-format off 18 // clang-format off
23 static const FunctionInfo functions[] = { 19 static const FunctionInfo functions[] = {
24 {0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"}, 20 {0, D<&IApplicationAccessor::GetAppletStateChangedEvent>, "GetAppletStateChangedEvent"},
@@ -63,15 +59,7 @@ Result IApplicationAccessor::Start() {
63 59
64Result IApplicationAccessor::RequestExit() { 60Result IApplicationAccessor::RequestExit() {
65 LOG_INFO(Service_AM, "called"); 61 LOG_INFO(Service_AM, "called");
66 62 m_applet->message_queue.RequestExit();
67 std::scoped_lock lk{m_applet->lock};
68 if (m_applet->exit_locked) {
69 m_applet->lifecycle_manager.RequestExit();
70 m_applet->UpdateSuspensionStateLocked(true);
71 } else {
72 m_applet->process->Terminate();
73 }
74
75 R_SUCCEED(); 63 R_SUCCEED();
76} 64}
77 65
@@ -83,14 +71,13 @@ Result IApplicationAccessor::Terminate() {
83 71
84Result IApplicationAccessor::GetResult() { 72Result IApplicationAccessor::GetResult() {
85 LOG_INFO(Service_AM, "called"); 73 LOG_INFO(Service_AM, "called");
86 std::scoped_lock lk{m_applet->lock}; 74 R_SUCCEED();
87 R_RETURN(m_applet->terminate_result);
88} 75}
89 76
90Result IApplicationAccessor::GetAppletStateChangedEvent( 77Result IApplicationAccessor::GetAppletStateChangedEvent(
91 OutCopyHandle<Kernel::KReadableEvent> out_event) { 78 OutCopyHandle<Kernel::KReadableEvent> out_event) {
92 LOG_INFO(Service_AM, "called"); 79 LOG_INFO(Service_AM, "called");
93 *out_event = m_applet->state_changed_event.GetHandle(); 80 *out_event = m_applet->caller_applet_broker->GetStateChangedEvent().GetHandle();
94 R_SUCCEED(); 81 R_SUCCEED();
95} 82}
96 83
@@ -109,15 +96,8 @@ Result IApplicationAccessor::PushLaunchParameter(LaunchParameterKind kind,
109 96
110Result IApplicationAccessor::GetApplicationControlProperty( 97Result IApplicationAccessor::GetApplicationControlProperty(
111 OutBuffer<BufferAttr_HipcMapAlias> out_control_property) { 98 OutBuffer<BufferAttr_HipcMapAlias> out_control_property) {
112 LOG_INFO(Service_AM, "called"); 99 LOG_WARNING(Service_AM, "(STUBBED) called");
113 100 R_THROW(ResultUnknown);
114 std::vector<u8> nacp;
115 R_TRY(system.GetARPManager().GetControlProperty(&nacp, m_applet->program_id));
116
117 std::memcpy(out_control_property.data(), nacp.data(),
118 std::min(out_control_property.size(), nacp.size()));
119
120 R_SUCCEED();
121} 101}
122 102
123Result IApplicationAccessor::SetUsers(bool enable, 103Result IApplicationAccessor::SetUsers(bool enable,
@@ -134,9 +114,8 @@ Result IApplicationAccessor::GetCurrentLibraryApplet(
134} 114}
135 115
136Result IApplicationAccessor::RequestForApplicationToGetForeground() { 116Result IApplicationAccessor::RequestForApplicationToGetForeground() {
137 LOG_INFO(Service_AM, "called"); 117 LOG_WARNING(Service_AM, "(STUBBED) called");
138 m_window_system.RequestApplicationToGetForeground(); 118 R_THROW(ResultUnknown);
139 R_SUCCEED();
140} 119}
141 120
142Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out<bool> out_is_available) { 121Result IApplicationAccessor::CheckRightsEnvironmentAvailable(Out<bool> out_is_available) {
diff --git a/src/core/hle/service/am/service/application_accessor.h b/src/core/hle/service/am/service/application_accessor.h
index b9797bcc0..39a9b2153 100755
--- a/src/core/hle/service/am/service/application_accessor.h
+++ b/src/core/hle/service/am/service/application_accessor.h
@@ -13,12 +13,10 @@ namespace Service::AM {
13struct Applet; 13struct Applet;
14class ILibraryAppletAccessor; 14class ILibraryAppletAccessor;
15class IStorage; 15class IStorage;
16class WindowSystem;
17 16
18class IApplicationAccessor final : public ServiceFramework<IApplicationAccessor> { 17class IApplicationAccessor final : public ServiceFramework<IApplicationAccessor> {
19public: 18public:
20 explicit IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet, 19 explicit IApplicationAccessor(Core::System& system_, std::shared_ptr<Applet> applet);
21 WindowSystem& window_system);
22 ~IApplicationAccessor() override; 20 ~IApplicationAccessor() override;
23 21
24private: 22private:
@@ -36,7 +34,6 @@ private:
36 Result GetNsRightsEnvironmentHandle(Out<u64> out_handle); 34 Result GetNsRightsEnvironmentHandle(Out<u64> out_handle);
37 Result ReportApplicationExitTimeout(); 35 Result ReportApplicationExitTimeout();
38 36
39 WindowSystem& m_window_system;
40 const std::shared_ptr<Applet> m_applet; 37 const std::shared_ptr<Applet> m_applet;
41}; 38};
42 39
diff --git a/src/core/hle/service/am/service/application_creator.cpp b/src/core/hle/service/am/service/application_creator.cpp
index 8994f1914..568bb0122 100755
--- a/src/core/hle/service/am/service/application_creator.cpp
+++ b/src/core/hle/service/am/service/application_creator.cpp
@@ -1,57 +1,17 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/file_sys/nca_metadata.h"
5#include "core/file_sys/registered_cache.h"
6#include "core/hle/service/am/am_types.h" 4#include "core/hle/service/am/am_types.h"
7#include "core/hle/service/am/applet.h" 5#include "core/hle/service/am/applet.h"
8#include "core/hle/service/am/applet_manager.h" 6#include "core/hle/service/am/applet_manager.h"
9#include "core/hle/service/am/process_creation.h"
10#include "core/hle/service/am/service/application_accessor.h" 7#include "core/hle/service/am/service/application_accessor.h"
11#include "core/hle/service/am/service/application_creator.h" 8#include "core/hle/service/am/service/application_creator.h"
12#include "core/hle/service/am/window_system.h"
13#include "core/hle/service/cmif_serialization.h" 9#include "core/hle/service/cmif_serialization.h"
14#include "core/loader/loader.h"
15 10
16namespace Service::AM { 11namespace Service::AM {
17 12
18namespace { 13IApplicationCreator::IApplicationCreator(Core::System& system_)
19 14 : ServiceFramework{system_, "IApplicationCreator"} {
20Result CreateGuestApplication(SharedPointer<IApplicationAccessor>* out_application_accessor,
21 Core::System& system, WindowSystem& window_system, u64 program_id) {
22 FileSys::VirtualFile nca_raw{};
23
24 // Get the program NCA from storage.
25 auto& storage = system.GetContentProviderUnion();
26 nca_raw = storage.GetEntryRaw(program_id, FileSys::ContentRecordType::Program);
27
28 // Ensure we retrieved a program NCA.
29 R_UNLESS(nca_raw != nullptr, ResultUnknown);
30
31 std::vector<u8> control;
32 std::unique_ptr<Loader::AppLoader> loader;
33 Loader::ResultStatus result;
34 auto process =
35 CreateApplicationProcess(control, loader, result, system, nca_raw, program_id, 0);
36 R_UNLESS(process != nullptr, ResultUnknown);
37
38 const auto applet = std::make_shared<Applet>(system, std::move(process), true);
39 applet->program_id = program_id;
40 applet->applet_id = AppletId::Application;
41 applet->type = AppletType::Application;
42 applet->library_applet_mode = LibraryAppletMode::AllForeground;
43
44 window_system.TrackApplet(applet, true);
45
46 *out_application_accessor =
47 std::make_shared<IApplicationAccessor>(system, applet, window_system);
48 R_SUCCEED();
49}
50
51} // namespace
52
53IApplicationCreator::IApplicationCreator(Core::System& system_, WindowSystem& window_system)
54 : ServiceFramework{system_, "IApplicationCreator"}, m_window_system{window_system} {
55 // clang-format off 15 // clang-format off
56 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
57 {0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"}, 17 {0, D<&IApplicationCreator::CreateApplication>, "CreateApplication"},
@@ -68,9 +28,8 @@ IApplicationCreator::~IApplicationCreator() = default;
68 28
69Result IApplicationCreator::CreateApplication( 29Result IApplicationCreator::CreateApplication(
70 Out<SharedPointer<IApplicationAccessor>> out_application_accessor, u64 application_id) { 30 Out<SharedPointer<IApplicationAccessor>> out_application_accessor, u64 application_id) {
71 LOG_INFO(Service_NS, "called, application_id={:016X}", application_id); 31 LOG_ERROR(Service_NS, "called, application_id={:x}", application_id);
72 R_RETURN( 32 R_THROW(ResultUnknown);
73 CreateGuestApplication(out_application_accessor, system, m_window_system, application_id));
74} 33}
75 34
76} // namespace Service::AM 35} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/application_creator.h b/src/core/hle/service/am/service/application_creator.h
index 287745af8..9f939ebf6 100755
--- a/src/core/hle/service/am/service/application_creator.h
+++ b/src/core/hle/service/am/service/application_creator.h
@@ -10,17 +10,14 @@ namespace Service::AM {
10 10
11class IApplicationAccessor; 11class IApplicationAccessor;
12struct Applet; 12struct Applet;
13class WindowSystem;
14 13
15class IApplicationCreator final : public ServiceFramework<IApplicationCreator> { 14class IApplicationCreator final : public ServiceFramework<IApplicationCreator> {
16public: 15public:
17 explicit IApplicationCreator(Core::System& system_, WindowSystem& window_system); 16 explicit IApplicationCreator(Core::System& system_);
18 ~IApplicationCreator() override; 17 ~IApplicationCreator() override;
19 18
20private: 19private:
21 Result CreateApplication(Out<SharedPointer<IApplicationAccessor>>, u64 application_id); 20 Result CreateApplication(Out<SharedPointer<IApplicationAccessor>>, u64 application_id);
22
23 WindowSystem& m_window_system;
24}; 21};
25 22
26} // namespace Service::AM 23} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp
index 3bab5ac5f..bfccb6b09 100755
--- a/src/core/hle/service/am/service/application_functions.cpp
+++ b/src/core/hle/service/am/service/application_functions.cpp
@@ -181,8 +181,7 @@ Result IApplicationFunctions::GetDesiredLanguage(Out<u64> out_language_code) {
181} 181}
182 182
183Result IApplicationFunctions::SetTerminateResult(Result terminate_result) { 183Result IApplicationFunctions::SetTerminateResult(Result terminate_result) {
184 LOG_INFO(Service_AM, "(STUBBED) called, result={:#x} ({:04}-{:04})", 184 LOG_INFO(Service_AM, "(STUBBED) called, result={:#x} ({}-{})", terminate_result.GetInnerValue(),
185 terminate_result.GetInnerValue(),
186 static_cast<u32>(terminate_result.GetModule()) + 2000, 185 static_cast<u32>(terminate_result.GetModule()) + 2000,
187 terminate_result.GetDescription()); 186 terminate_result.GetDescription());
188 187
diff --git a/src/core/hle/service/am/service/application_proxy.cpp b/src/core/hle/service/am/service/application_proxy.cpp
index 6e1328fee..19d6a3b89 100755
--- a/src/core/hle/service/am/service/application_proxy.cpp
+++ b/src/core/hle/service/am/service/application_proxy.cpp
@@ -17,9 +17,9 @@
17namespace Service::AM { 17namespace Service::AM {
18 18
19IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, 19IApplicationProxy::IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
20 Kernel::KProcess* process, WindowSystem& window_system) 20 Kernel::KProcess* process)
21 : ServiceFramework{system_, "IApplicationProxy"}, 21 : ServiceFramework{system_, "IApplicationProxy"}, m_process{process}, m_applet{
22 m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { 22 std::move(applet)} {
23 // clang-format off 23 // clang-format off
24 static const FunctionInfo functions[] = { 24 static const FunctionInfo functions[] = {
25 {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 25 {0, D<&IApplicationProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -70,7 +70,7 @@ Result IApplicationProxy::GetDebugFunctions(
70Result IApplicationProxy::GetWindowController( 70Result IApplicationProxy::GetWindowController(
71 Out<SharedPointer<IWindowController>> out_window_controller) { 71 Out<SharedPointer<IWindowController>> out_window_controller) {
72 LOG_DEBUG(Service_AM, "called"); 72 LOG_DEBUG(Service_AM, "called");
73 *out_window_controller = std::make_shared<IWindowController>(system, m_applet, m_window_system); 73 *out_window_controller = std::make_shared<IWindowController>(system, m_applet);
74 R_SUCCEED(); 74 R_SUCCEED();
75} 75}
76 76
@@ -91,8 +91,7 @@ Result IApplicationProxy::GetCommonStateGetter(
91Result IApplicationProxy::GetLibraryAppletCreator( 91Result IApplicationProxy::GetLibraryAppletCreator(
92 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) { 92 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) {
93 LOG_DEBUG(Service_AM, "called"); 93 LOG_DEBUG(Service_AM, "called");
94 *out_library_applet_creator = 94 *out_library_applet_creator = std::make_shared<ILibraryAppletCreator>(system, m_applet);
95 std::make_shared<ILibraryAppletCreator>(system, m_applet, m_window_system);
96 R_SUCCEED(); 95 R_SUCCEED();
97} 96}
98 97
diff --git a/src/core/hle/service/am/service/application_proxy.h b/src/core/hle/service/am/service/application_proxy.h
index 8c62459c4..6da350df7 100755
--- a/src/core/hle/service/am/service/application_proxy.h
+++ b/src/core/hle/service/am/service/application_proxy.h
@@ -18,12 +18,11 @@ class ILibraryAppletCreator;
18class IProcessWindingController; 18class IProcessWindingController;
19class ISelfController; 19class ISelfController;
20class IWindowController; 20class IWindowController;
21class WindowSystem;
22 21
23class IApplicationProxy final : public ServiceFramework<IApplicationProxy> { 22class IApplicationProxy final : public ServiceFramework<IApplicationProxy> {
24public: 23public:
25 explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet, 24 explicit IApplicationProxy(Core::System& system_, std::shared_ptr<Applet> applet,
26 Kernel::KProcess* process, WindowSystem& window_system); 25 Kernel::KProcess* process);
27 ~IApplicationProxy(); 26 ~IApplicationProxy();
28 27
29private: 28private:
@@ -41,7 +40,6 @@ private:
41 Out<SharedPointer<IApplicationFunctions>> out_application_functions); 40 Out<SharedPointer<IApplicationFunctions>> out_application_functions);
42 41
43private: 42private:
44 WindowSystem& m_window_system;
45 Kernel::KProcess* const m_process; 43 Kernel::KProcess* const m_process;
46 const std::shared_ptr<Applet> m_applet; 44 const std::shared_ptr<Applet> m_applet;
47}; 45};
diff --git a/src/core/hle/service/am/service/application_proxy_service.cpp b/src/core/hle/service/am/service/application_proxy_service.cpp
index b7d7b3c2d..fd66e77b9 100755
--- a/src/core/hle/service/am/service/application_proxy_service.cpp
+++ b/src/core/hle/service/am/service/application_proxy_service.cpp
@@ -6,14 +6,12 @@
6#include "core/hle/service/am/applet_manager.h" 6#include "core/hle/service/am/applet_manager.h"
7#include "core/hle/service/am/service/application_proxy.h" 7#include "core/hle/service/am/service/application_proxy.h"
8#include "core/hle/service/am/service/application_proxy_service.h" 8#include "core/hle/service/am/service/application_proxy_service.h"
9#include "core/hle/service/am/window_system.h"
10#include "core/hle/service/cmif_serialization.h" 9#include "core/hle/service/cmif_serialization.h"
11 10
12namespace Service::AM { 11namespace Service::AM {
13 12
14IApplicationProxyService::IApplicationProxyService(Core::System& system_, 13IApplicationProxyService::IApplicationProxyService(Core::System& system_)
15 WindowSystem& window_system) 14 : ServiceFramework{system_, "appletOE"} {
16 : ServiceFramework{system_, "appletOE"}, m_window_system{window_system} {
17 static const FunctionInfo functions[] = { 15 static const FunctionInfo functions[] = {
18 {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"}, 16 {0, D<&IApplicationProxyService::OpenApplicationProxy>, "OpenApplicationProxy"},
19 }; 17 };
@@ -28,8 +26,8 @@ Result IApplicationProxyService::OpenApplicationProxy(
28 LOG_DEBUG(Service_AM, "called"); 26 LOG_DEBUG(Service_AM, "called");
29 27
30 if (const auto applet = this->GetAppletFromProcessId(pid)) { 28 if (const auto applet = this->GetAppletFromProcessId(pid)) {
31 *out_application_proxy = std::make_shared<IApplicationProxy>( 29 *out_application_proxy =
32 system, applet, process_handle.Get(), m_window_system); 30 std::make_shared<IApplicationProxy>(system, applet, process_handle.Get());
33 R_SUCCEED(); 31 R_SUCCEED();
34 } else { 32 } else {
35 UNIMPLEMENTED(); 33 UNIMPLEMENTED();
@@ -38,7 +36,7 @@ Result IApplicationProxyService::OpenApplicationProxy(
38} 36}
39 37
40std::shared_ptr<Applet> IApplicationProxyService::GetAppletFromProcessId(ProcessId process_id) { 38std::shared_ptr<Applet> IApplicationProxyService::GetAppletFromProcessId(ProcessId process_id) {
41 return m_window_system.GetByAppletResourceUserId(process_id.pid); 39 return system.GetAppletManager().GetByAppletResourceUserId(process_id.pid);
42} 40}
43 41
44} // namespace Service::AM 42} // namespace Service::AM
diff --git a/src/core/hle/service/am/service/application_proxy_service.h b/src/core/hle/service/am/service/application_proxy_service.h
index e5f4ea345..8efafa31a 100755
--- a/src/core/hle/service/am/service/application_proxy_service.h
+++ b/src/core/hle/service/am/service/application_proxy_service.h
@@ -12,11 +12,10 @@ namespace AM {
12 12
13struct Applet; 13struct Applet;
14class IApplicationProxy; 14class IApplicationProxy;
15class WindowSystem;
16 15
17class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> { 16class IApplicationProxyService final : public ServiceFramework<IApplicationProxyService> {
18public: 17public:
19 explicit IApplicationProxyService(Core::System& system_, WindowSystem& window_system); 18 explicit IApplicationProxyService(Core::System& system_);
20 ~IApplicationProxyService() override; 19 ~IApplicationProxyService() override;
21 20
22private: 21private:
@@ -25,8 +24,6 @@ private:
25 24
26private: 25private:
27 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid); 26 std::shared_ptr<Applet> GetAppletFromProcessId(ProcessId pid);
28
29 WindowSystem& m_window_system;
30}; 27};
31 28
32} // namespace AM 29} // namespace AM
diff --git a/src/core/hle/service/am/service/common_state_getter.cpp b/src/core/hle/service/am/service/common_state_getter.cpp
index f523bcd9e..a32855ffa 100755
--- a/src/core/hle/service/am/service/common_state_getter.cpp
+++ b/src/core/hle/service/am/service/common_state_getter.cpp
@@ -80,14 +80,15 @@ ICommonStateGetter::~ICommonStateGetter() = default;
80 80
81Result ICommonStateGetter::GetEventHandle(OutCopyHandle<Kernel::KReadableEvent> out_event) { 81Result ICommonStateGetter::GetEventHandle(OutCopyHandle<Kernel::KReadableEvent> out_event) {
82 LOG_DEBUG(Service_AM, "called"); 82 LOG_DEBUG(Service_AM, "called");
83 *out_event = m_applet->lifecycle_manager.GetSystemEvent().GetHandle(); 83 *out_event = &m_applet->message_queue.GetMessageReceiveEvent();
84 R_SUCCEED(); 84 R_SUCCEED();
85} 85}
86 86
87Result ICommonStateGetter::ReceiveMessage(Out<AppletMessage> out_applet_message) { 87Result ICommonStateGetter::ReceiveMessage(Out<AppletMessage> out_applet_message) {
88 LOG_DEBUG(Service_AM, "called"); 88 LOG_DEBUG(Service_AM, "called");
89 89
90 if (!m_applet->lifecycle_manager.PopMessage(out_applet_message)) { 90 *out_applet_message = m_applet->message_queue.PopMessage();
91 if (*out_applet_message == AppletMessage::None) {
91 LOG_ERROR(Service_AM, "Tried to pop message but none was available!"); 92 LOG_ERROR(Service_AM, "Tried to pop message but none was available!");
92 R_THROW(AM::ResultNoMessages); 93 R_THROW(AM::ResultNoMessages);
93 } 94 }
@@ -99,7 +100,7 @@ Result ICommonStateGetter::GetCurrentFocusState(Out<FocusState> out_focus_state)
99 LOG_DEBUG(Service_AM, "called"); 100 LOG_DEBUG(Service_AM, "called");
100 101
101 std::scoped_lock lk{m_applet->lock}; 102 std::scoped_lock lk{m_applet->lock};
102 *out_focus_state = m_applet->lifecycle_manager.GetAndClearFocusState(); 103 *out_focus_state = m_applet->focus_state;
103 104
104 R_SUCCEED(); 105 R_SUCCEED();
105} 106}
@@ -136,7 +137,7 @@ Result ICommonStateGetter::GetWriterLockAccessorEx(
136Result ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent( 137Result ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent(
137 OutCopyHandle<Kernel::KReadableEvent> out_event) { 138 OutCopyHandle<Kernel::KReadableEvent> out_event) {
138 LOG_DEBUG(Service_AM, "called"); 139 LOG_DEBUG(Service_AM, "called");
139 *out_event = m_applet->lifecycle_manager.GetOperationModeChangedSystemEvent().GetHandle(); 140 *out_event = &m_applet->message_queue.GetOperationModeChangedEvent();
140 R_SUCCEED(); 141 R_SUCCEED();
141} 142}
142 143
diff --git a/src/core/hle/service/am/service/home_menu_functions.cpp b/src/core/hle/service/am/service/home_menu_functions.cpp
index 25f78beb5..0c4d24b58 100755
--- a/src/core/hle/service/am/service/home_menu_functions.cpp
+++ b/src/core/hle/service/am/service/home_menu_functions.cpp
@@ -4,16 +4,13 @@
4#include "core/hle/result.h" 4#include "core/hle/result.h"
5#include "core/hle/service/am/applet_manager.h" 5#include "core/hle/service/am/applet_manager.h"
6#include "core/hle/service/am/service/home_menu_functions.h" 6#include "core/hle/service/am/service/home_menu_functions.h"
7#include "core/hle/service/am/window_system.h"
8#include "core/hle/service/cmif_serialization.h" 7#include "core/hle/service/cmif_serialization.h"
9 8
10namespace Service::AM { 9namespace Service::AM {
11 10
12IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr<Applet> applet, 11IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr<Applet> applet)
13 WindowSystem& window_system) 12 : ServiceFramework{system_, "IHomeMenuFunctions"}, m_applet{std::move(applet)},
14 : ServiceFramework{system_, "IHomeMenuFunctions"}, m_window_system{window_system}, 13 m_context{system, "IHomeMenuFunctions"}, m_pop_from_general_channel_event{m_context} {
15 m_applet{std::move(applet)}, m_context{system, "IHomeMenuFunctions"},
16 m_pop_from_general_channel_event{m_context} {
17 // clang-format off 14 // clang-format off
18 static const FunctionInfo functions[] = { 15 static const FunctionInfo functions[] = {
19 {10, D<&IHomeMenuFunctions::RequestToGetForeground>, "RequestToGetForeground"}, 16 {10, D<&IHomeMenuFunctions::RequestToGetForeground>, "RequestToGetForeground"},
@@ -40,20 +37,17 @@ IHomeMenuFunctions::IHomeMenuFunctions(Core::System& system_, std::shared_ptr<Ap
40IHomeMenuFunctions::~IHomeMenuFunctions() = default; 37IHomeMenuFunctions::~IHomeMenuFunctions() = default;
41 38
42Result IHomeMenuFunctions::RequestToGetForeground() { 39Result IHomeMenuFunctions::RequestToGetForeground() {
43 LOG_INFO(Service_AM, "called"); 40 LOG_WARNING(Service_AM, "(STUBBED) called");
44 m_window_system.RequestHomeMenuToGetForeground();
45 R_SUCCEED(); 41 R_SUCCEED();
46} 42}
47 43
48Result IHomeMenuFunctions::LockForeground() { 44Result IHomeMenuFunctions::LockForeground() {
49 LOG_INFO(Service_AM, "called"); 45 LOG_WARNING(Service_AM, "(STUBBED) called");
50 m_window_system.RequestLockHomeMenuIntoForeground();
51 R_SUCCEED(); 46 R_SUCCEED();
52} 47}
53 48
54Result IHomeMenuFunctions::UnlockForeground() { 49Result IHomeMenuFunctions::UnlockForeground() {
55 LOG_INFO(Service_AM, "called"); 50 LOG_WARNING(Service_AM, "(STUBBED) called");
56 m_window_system.RequestUnlockHomeMenuIntoForeground();
57 R_SUCCEED(); 51 R_SUCCEED();
58} 52}
59 53
diff --git a/src/core/hle/service/am/service/home_menu_functions.h b/src/core/hle/service/am/service/home_menu_functions.h
index f56094aa9..caf6fbaab 100755
--- a/src/core/hle/service/am/service/home_menu_functions.h
+++ b/src/core/hle/service/am/service/home_menu_functions.h
@@ -11,12 +11,10 @@
11namespace Service::AM { 11namespace Service::AM {
12 12
13struct Applet; 13struct Applet;
14class WindowSystem;
15 14
16class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> { 15class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
17public: 16public:
18 explicit IHomeMenuFunctions(Core::System& system_, std::shared_ptr<Applet> applet, 17 explicit IHomeMenuFunctions(Core::System& system_, std::shared_ptr<Applet> applet);
19 WindowSystem& window_system);
20 ~IHomeMenuFunctions() override; 18 ~IHomeMenuFunctions() override;
21 19
22private: 20private:
@@ -28,7 +26,6 @@ private:
28 Result IsForceTerminateApplicationDisabledForDebug( 26 Result IsForceTerminateApplicationDisabledForDebug(
29 Out<bool> out_is_force_terminate_application_disabled_for_debug); 27 Out<bool> out_is_force_terminate_application_disabled_for_debug);
30 28
31 WindowSystem& m_window_system;
32 const std::shared_ptr<Applet> m_applet; 29 const std::shared_ptr<Applet> m_applet;
33 KernelHelpers::ServiceContext m_context; 30 KernelHelpers::ServiceContext m_context;
34 Event m_pop_from_general_channel_event; 31 Event m_pop_from_general_channel_event;
diff --git a/src/core/hle/service/am/service/library_applet_accessor.cpp b/src/core/hle/service/am/service/library_applet_accessor.cpp
index cda8c3eb8..0c2426d4b 100755
--- a/src/core/hle/service/am/service/library_applet_accessor.cpp
+++ b/src/core/hle/service/am/service/library_applet_accessor.cpp
@@ -47,21 +47,20 @@ ILibraryAppletAccessor::~ILibraryAppletAccessor() = default;
47Result ILibraryAppletAccessor::GetAppletStateChangedEvent( 47Result ILibraryAppletAccessor::GetAppletStateChangedEvent(
48 OutCopyHandle<Kernel::KReadableEvent> out_event) { 48 OutCopyHandle<Kernel::KReadableEvent> out_event) {
49 LOG_DEBUG(Service_AM, "called"); 49 LOG_DEBUG(Service_AM, "called");
50 *out_event = m_applet->state_changed_event.GetHandle(); 50 *out_event = m_broker->GetStateChangedEvent().GetHandle();
51 R_SUCCEED(); 51 R_SUCCEED();
52} 52}
53 53
54Result ILibraryAppletAccessor::IsCompleted(Out<bool> out_is_completed) { 54Result ILibraryAppletAccessor::IsCompleted(Out<bool> out_is_completed) {
55 LOG_DEBUG(Service_AM, "called"); 55 LOG_DEBUG(Service_AM, "called");
56 std::scoped_lock lk{m_applet->lock}; 56 *out_is_completed = m_broker->IsCompleted();
57 *out_is_completed = m_applet->is_completed;
58 R_SUCCEED(); 57 R_SUCCEED();
59} 58}
60 59
61Result ILibraryAppletAccessor::GetResult() { 60Result ILibraryAppletAccessor::GetResult(Out<Result> out_result) {
62 LOG_DEBUG(Service_AM, "called"); 61 LOG_DEBUG(Service_AM, "called");
63 std::scoped_lock lk{m_applet->lock}; 62 *out_result = m_applet->terminate_result;
64 R_RETURN(m_applet->terminate_result); 63 R_SUCCEED();
65} 64}
66 65
67Result ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero() { 66Result ILibraryAppletAccessor::PresetLibraryAppletGpuTimeSliceZero() {
@@ -78,10 +77,7 @@ Result ILibraryAppletAccessor::Start() {
78 77
79Result ILibraryAppletAccessor::RequestExit() { 78Result ILibraryAppletAccessor::RequestExit() {
80 LOG_DEBUG(Service_AM, "called"); 79 LOG_DEBUG(Service_AM, "called");
81 { 80 m_applet->message_queue.RequestExit();
82 std::scoped_lock lk{m_applet->lock};
83 m_applet->lifecycle_manager.RequestExit();
84 }
85 FrontendRequestExit(); 81 FrontendRequestExit();
86 R_SUCCEED(); 82 R_SUCCEED();
87} 83}
diff --git a/src/core/hle/service/am/service/library_applet_accessor.h b/src/core/hle/service/am/service/library_applet_accessor.h
index 36712821a..97d3b6c8a 100755
--- a/src/core/hle/service/am/service/library_applet_accessor.h
+++ b/src/core/hle/service/am/service/library_applet_accessor.h
@@ -21,7 +21,7 @@ public:
21private: 21private:
22 Result GetAppletStateChangedEvent(OutCopyHandle<Kernel::KReadableEvent> out_event); 22 Result GetAppletStateChangedEvent(OutCopyHandle<Kernel::KReadableEvent> out_event);
23 Result IsCompleted(Out<bool> out_is_completed); 23 Result IsCompleted(Out<bool> out_is_completed);
24 Result GetResult(); 24 Result GetResult(Out<Result> out_result);
25 Result PresetLibraryAppletGpuTimeSliceZero(); 25 Result PresetLibraryAppletGpuTimeSliceZero();
26 Result Start(); 26 Result Start();
27 Result RequestExit(); 27 Result RequestExit();
diff --git a/src/core/hle/service/am/service/library_applet_creator.cpp b/src/core/hle/service/am/service/library_applet_creator.cpp
index 3ffb03bc9..c97358d81 100755
--- a/src/core/hle/service/am/service/library_applet_creator.cpp
+++ b/src/core/hle/service/am/service/library_applet_creator.cpp
@@ -7,11 +7,9 @@
7#include "core/hle/service/am/applet_manager.h" 7#include "core/hle/service/am/applet_manager.h"
8#include "core/hle/service/am/frontend/applets.h" 8#include "core/hle/service/am/frontend/applets.h"
9#include "core/hle/service/am/library_applet_storage.h" 9#include "core/hle/service/am/library_applet_storage.h"
10#include "core/hle/service/am/process_creation.h"
11#include "core/hle/service/am/service/library_applet_accessor.h" 10#include "core/hle/service/am/service/library_applet_accessor.h"
12#include "core/hle/service/am/service/library_applet_creator.h" 11#include "core/hle/service/am/service/library_applet_creator.h"
13#include "core/hle/service/am/service/storage.h" 12#include "core/hle/service/am/service/storage.h"
14#include "core/hle/service/am/window_system.h"
15#include "core/hle/service/cmif_serialization.h" 13#include "core/hle/service/cmif_serialization.h"
16#include "core/hle/service/sm/sm.h" 14#include "core/hle/service/sm/sm.h"
17 15
@@ -95,7 +93,6 @@ AppletProgramId AppletIdToProgramId(AppletId applet_id) {
95} 93}
96 94
97std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system, 95std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system,
98 WindowSystem& window_system,
99 std::shared_ptr<Applet> caller_applet, 96 std::shared_ptr<Applet> caller_applet,
100 AppletId applet_id, 97 AppletId applet_id,
101 LibraryAppletMode mode) { 98 LibraryAppletMode mode) {
@@ -113,38 +110,53 @@ std::shared_ptr<ILibraryAppletAccessor> CreateGuestApplet(Core::System& system,
113 Firmware1700 = 17, 110 Firmware1700 = 17,
114 }; 111 };
115 112
116 auto process = CreateProcess(system, program_id, Firmware1400, Firmware1700); 113 auto process = std::make_unique<Process>(system);
117 if (!process) { 114 if (!process->Initialize(program_id, Firmware1400, Firmware1700)) {
118 // Couldn't initialize the guest process 115 // Couldn't initialize the guest process
119 return {}; 116 return {};
120 } 117 }
121 118
122 const auto applet = std::make_shared<Applet>(system, std::move(process), false); 119 const auto applet = std::make_shared<Applet>(system, std::move(process));
123 applet->program_id = program_id; 120 applet->program_id = program_id;
124 applet->applet_id = applet_id; 121 applet->applet_id = applet_id;
125 applet->type = AppletType::LibraryApplet; 122 applet->type = AppletType::LibraryApplet;
126 applet->library_applet_mode = mode; 123 applet->library_applet_mode = mode;
127 applet->window_visible = mode != LibraryAppletMode::AllForegroundInitiallyHidden; 124
125 // Set focus state
126 switch (mode) {
127 case LibraryAppletMode::AllForeground:
128 case LibraryAppletMode::NoUi:
129 case LibraryAppletMode::PartialForeground:
130 case LibraryAppletMode::PartialForegroundIndirectDisplay:
131 applet->hid_registration.EnableAppletToGetInput(true);
132 applet->focus_state = FocusState::InFocus;
133 applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground);
134 break;
135 case LibraryAppletMode::AllForegroundInitiallyHidden:
136 applet->hid_registration.EnableAppletToGetInput(false);
137 applet->focus_state = FocusState::NotInFocus;
138 applet->display_layer_manager.SetWindowVisibility(false);
139 applet->message_queue.PushMessage(AppletMessage::ChangeIntoBackground);
140 break;
141 }
128 142
129 auto broker = std::make_shared<AppletDataBroker>(system); 143 auto broker = std::make_shared<AppletDataBroker>(system);
130 applet->caller_applet = caller_applet; 144 applet->caller_applet = caller_applet;
131 applet->caller_applet_broker = broker; 145 applet->caller_applet_broker = broker;
132 caller_applet->child_applets.push_back(applet);
133 146
134 window_system.TrackApplet(applet, false); 147 system.GetAppletManager().InsertApplet(applet);
135 148
136 return std::make_shared<ILibraryAppletAccessor>(system, broker, applet); 149 return std::make_shared<ILibraryAppletAccessor>(system, broker, applet);
137} 150}
138 151
139std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& system, 152std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& system,
140 WindowSystem& window_system,
141 std::shared_ptr<Applet> caller_applet, 153 std::shared_ptr<Applet> caller_applet,
142 AppletId applet_id, 154 AppletId applet_id,
143 LibraryAppletMode mode) { 155 LibraryAppletMode mode) {
144 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id)); 156 const auto program_id = static_cast<u64>(AppletIdToProgramId(applet_id));
145 157
146 auto process = std::make_unique<Process>(system); 158 auto process = std::make_unique<Process>(system);
147 auto applet = std::make_shared<Applet>(system, std::move(process), false); 159 auto applet = std::make_shared<Applet>(system, std::move(process));
148 applet->program_id = program_id; 160 applet->program_id = program_id;
149 applet->applet_id = applet_id; 161 applet->applet_id = applet_id;
150 applet->type = AppletType::LibraryApplet; 162 applet->type = AppletType::LibraryApplet;
@@ -154,19 +166,14 @@ std::shared_ptr<ILibraryAppletAccessor> CreateFrontendApplet(Core::System& syste
154 applet->caller_applet = caller_applet; 166 applet->caller_applet = caller_applet;
155 applet->caller_applet_broker = storage; 167 applet->caller_applet_broker = storage;
156 applet->frontend = system.GetFrontendAppletHolder().GetApplet(applet, applet_id, mode); 168 applet->frontend = system.GetFrontendAppletHolder().GetApplet(applet, applet_id, mode);
157 caller_applet->child_applets.push_back(applet);
158
159 window_system.TrackApplet(applet, false);
160 169
161 return std::make_shared<ILibraryAppletAccessor>(system, storage, applet); 170 return std::make_shared<ILibraryAppletAccessor>(system, storage, applet);
162} 171}
163 172
164} // namespace 173} // namespace
165 174
166ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_, std::shared_ptr<Applet> applet, 175ILibraryAppletCreator::ILibraryAppletCreator(Core::System& system_, std::shared_ptr<Applet> applet)
167 WindowSystem& window_system) 176 : ServiceFramework{system_, "ILibraryAppletCreator"}, m_applet{std::move(applet)} {
168 : ServiceFramework{system_, "ILibraryAppletCreator"},
169 m_window_system{window_system}, m_applet{std::move(applet)} {
170 static const FunctionInfo functions[] = { 177 static const FunctionInfo functions[] = {
171 {0, D<&ILibraryAppletCreator::CreateLibraryApplet>, "CreateLibraryApplet"}, 178 {0, D<&ILibraryAppletCreator::CreateLibraryApplet>, "CreateLibraryApplet"},
172 {1, nullptr, "TerminateAllLibraryApplets"}, 179 {1, nullptr, "TerminateAllLibraryApplets"},
@@ -188,12 +195,10 @@ Result ILibraryAppletCreator::CreateLibraryApplet(
188 195
189 std::shared_ptr<ILibraryAppletAccessor> library_applet; 196 std::shared_ptr<ILibraryAppletAccessor> library_applet;
190 if (ShouldCreateGuestApplet(applet_id)) { 197 if (ShouldCreateGuestApplet(applet_id)) {
191 library_applet = 198 library_applet = CreateGuestApplet(system, m_applet, applet_id, library_applet_mode);
192 CreateGuestApplet(system, m_window_system, m_applet, applet_id, library_applet_mode);
193 } 199 }
194 if (!library_applet) { 200 if (!library_applet) {
195 library_applet = 201 library_applet = CreateFrontendApplet(system, m_applet, applet_id, library_applet_mode);
196 CreateFrontendApplet(system, m_window_system, m_applet, applet_id, library_applet_mode);
197 } 202 }
198 if (!library_applet) { 203 if (!library_applet) {
199 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id); 204 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", applet_id);
diff --git a/src/core/hle/service/am/service/library_applet_creator.h b/src/core/hle/service/am/service/library_applet_creator.h
index a10a76982..fe6d40eb3 100755
--- a/src/core/hle/service/am/service/library_applet_creator.h
+++ b/src/core/hle/service/am/service/library_applet_creator.h
@@ -12,12 +12,10 @@ namespace Service::AM {
12struct Applet; 12struct Applet;
13class ILibraryAppletAccessor; 13class ILibraryAppletAccessor;
14class IStorage; 14class IStorage;
15class WindowSystem;
16 15
17class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> { 16class ILibraryAppletCreator final : public ServiceFramework<ILibraryAppletCreator> {
18public: 17public:
19 explicit ILibraryAppletCreator(Core::System& system_, std::shared_ptr<Applet> applet, 18 explicit ILibraryAppletCreator(Core::System& system_, std::shared_ptr<Applet> applet);
20 WindowSystem& window_system);
21 ~ILibraryAppletCreator() override; 19 ~ILibraryAppletCreator() override;
22 20
23private: 21private:
@@ -31,7 +29,6 @@ private:
31 Result CreateHandleStorage(Out<SharedPointer<IStorage>> out_storage, s64 size, 29 Result CreateHandleStorage(Out<SharedPointer<IStorage>> out_storage, s64 size,
32 InCopyHandle<Kernel::KTransferMemory> transfer_memory_handle); 30 InCopyHandle<Kernel::KTransferMemory> transfer_memory_handle);
33 31
34 WindowSystem& m_window_system;
35 const std::shared_ptr<Applet> m_applet; 32 const std::shared_ptr<Applet> m_applet;
36}; 33};
37 34
diff --git a/src/core/hle/service/am/service/library_applet_proxy.cpp b/src/core/hle/service/am/service/library_applet_proxy.cpp
index f9cfb82a9..58e709347 100755
--- a/src/core/hle/service/am/service/library_applet_proxy.cpp
+++ b/src/core/hle/service/am/service/library_applet_proxy.cpp
@@ -19,9 +19,9 @@
19namespace Service::AM { 19namespace Service::AM {
20 20
21ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 21ILibraryAppletProxy::ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
22 Kernel::KProcess* process, WindowSystem& window_system) 22 Kernel::KProcess* process)
23 : ServiceFramework{system_, "ILibraryAppletProxy"}, 23 : ServiceFramework{system_, "ILibraryAppletProxy"}, m_process{process}, m_applet{
24 m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { 24 std::move(applet)} {
25 // clang-format off 25 // clang-format off
26 static const FunctionInfo functions[] = { 26 static const FunctionInfo functions[] = {
27 {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 27 {0, D<&ILibraryAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -75,7 +75,7 @@ Result ILibraryAppletProxy::GetDebugFunctions(
75Result ILibraryAppletProxy::GetWindowController( 75Result ILibraryAppletProxy::GetWindowController(
76 Out<SharedPointer<IWindowController>> out_window_controller) { 76 Out<SharedPointer<IWindowController>> out_window_controller) {
77 LOG_DEBUG(Service_AM, "called"); 77 LOG_DEBUG(Service_AM, "called");
78 *out_window_controller = std::make_shared<IWindowController>(system, m_applet, m_window_system); 78 *out_window_controller = std::make_shared<IWindowController>(system, m_applet);
79 R_SUCCEED(); 79 R_SUCCEED();
80} 80}
81 81
@@ -96,8 +96,7 @@ Result ILibraryAppletProxy::GetCommonStateGetter(
96Result ILibraryAppletProxy::GetLibraryAppletCreator( 96Result ILibraryAppletProxy::GetLibraryAppletCreator(
97 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) { 97 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) {
98 LOG_DEBUG(Service_AM, "called"); 98 LOG_DEBUG(Service_AM, "called");
99 *out_library_applet_creator = 99 *out_library_applet_creator = std::make_shared<ILibraryAppletCreator>(system, m_applet);
100 std::make_shared<ILibraryAppletCreator>(system, m_applet, m_window_system);
101 R_SUCCEED(); 100 R_SUCCEED();
102} 101}
103 102
@@ -119,8 +118,7 @@ Result ILibraryAppletProxy::GetAppletCommonFunctions(
119Result ILibraryAppletProxy::GetHomeMenuFunctions( 118Result ILibraryAppletProxy::GetHomeMenuFunctions(
120 Out<SharedPointer<IHomeMenuFunctions>> out_home_menu_functions) { 119 Out<SharedPointer<IHomeMenuFunctions>> out_home_menu_functions) {
121 LOG_DEBUG(Service_AM, "called"); 120 LOG_DEBUG(Service_AM, "called");
122 *out_home_menu_functions = 121 *out_home_menu_functions = std::make_shared<IHomeMenuFunctions>(system, m_applet);
123 std::make_shared<IHomeMenuFunctions>(system, m_applet, m_window_system);
124 R_SUCCEED(); 122 R_SUCCEED();
125} 123}
126 124
diff --git a/src/core/hle/service/am/service/library_applet_proxy.h b/src/core/hle/service/am/service/library_applet_proxy.h
index 792d58582..7d0714b85 100755
--- a/src/core/hle/service/am/service/library_applet_proxy.h
+++ b/src/core/hle/service/am/service/library_applet_proxy.h
@@ -21,12 +21,11 @@ class ILibraryAppletSelfAccessor;
21class IProcessWindingController; 21class IProcessWindingController;
22class ISelfController; 22class ISelfController;
23class IWindowController; 23class IWindowController;
24class WindowSystem;
25 24
26class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> { 25class ILibraryAppletProxy final : public ServiceFramework<ILibraryAppletProxy> {
27public: 26public:
28 explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 27 explicit ILibraryAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
29 Kernel::KProcess* process, WindowSystem& window_system); 28 Kernel::KProcess* process);
30 ~ILibraryAppletProxy(); 29 ~ILibraryAppletProxy();
31 30
32private: 31private:
@@ -48,7 +47,6 @@ private:
48 Result GetGlobalStateController( 47 Result GetGlobalStateController(
49 Out<SharedPointer<IGlobalStateController>> out_global_state_controller); 48 Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
50 49
51 WindowSystem& m_window_system;
52 Kernel::KProcess* const m_process; 50 Kernel::KProcess* const m_process;
53 const std::shared_ptr<Applet> m_applet; 51 const std::shared_ptr<Applet> m_applet;
54}; 52};
diff --git a/src/core/hle/service/am/service/library_applet_self_accessor.cpp b/src/core/hle/service/am/service/library_applet_self_accessor.cpp
index 3fe36b899..330eb26f0 100755
--- a/src/core/hle/service/am/service/library_applet_self_accessor.cpp
+++ b/src/core/hle/service/am/service/library_applet_self_accessor.cpp
@@ -176,7 +176,8 @@ Result ILibraryAppletSelfAccessor::GetMainAppletStorageId(Out<FileSys::StorageId
176 176
177Result ILibraryAppletSelfAccessor::ExitProcessAndReturn() { 177Result ILibraryAppletSelfAccessor::ExitProcessAndReturn() {
178 LOG_INFO(Service_AM, "called"); 178 LOG_INFO(Service_AM, "called");
179 m_applet->process->Terminate(); 179 system.GetAppletManager().TerminateAndRemoveApplet(m_applet->aruid);
180 m_broker->SignalCompletion();
180 R_SUCCEED(); 181 R_SUCCEED();
181} 182}
182 183
diff --git a/src/core/hle/service/am/service/self_controller.cpp b/src/core/hle/service/am/service/self_controller.cpp
index 1db02b88f..06314407c 100755
--- a/src/core/hle/service/am/service/self_controller.cpp
+++ b/src/core/hle/service/am/service/self_controller.cpp
@@ -86,7 +86,8 @@ ISelfController::~ISelfController() {
86Result ISelfController::Exit() { 86Result ISelfController::Exit() {
87 LOG_DEBUG(Service_AM, "called"); 87 LOG_DEBUG(Service_AM, "called");
88 88
89 m_applet->process->Terminate(); 89 // TODO
90 system.Exit();
90 91
91 R_SUCCEED(); 92 R_SUCCEED();
92} 93}
@@ -94,16 +95,7 @@ Result ISelfController::Exit() {
94Result ISelfController::LockExit() { 95Result ISelfController::LockExit() {
95 LOG_DEBUG(Service_AM, "called"); 96 LOG_DEBUG(Service_AM, "called");
96 97
97 std::scoped_lock lk{m_applet->lock}; 98 system.SetExitLocked(true);
98
99 if (m_applet->lifecycle_manager.GetExitRequested()) {
100 // With exit already requested, ignore and terminate immediately.
101 m_applet->process->Terminate();
102 } else {
103 // Otherwise, set exit lock state.
104 m_applet->exit_locked = true;
105 system.SetExitLocked(true);
106 }
107 99
108 R_SUCCEED(); 100 R_SUCCEED();
109} 101}
@@ -111,13 +103,10 @@ Result ISelfController::LockExit() {
111Result ISelfController::UnlockExit() { 103Result ISelfController::UnlockExit() {
112 LOG_DEBUG(Service_AM, "called"); 104 LOG_DEBUG(Service_AM, "called");
113 105
114 std::scoped_lock lk{m_applet->lock};
115
116 m_applet->exit_locked = false;
117 system.SetExitLocked(false); 106 system.SetExitLocked(false);
118 107
119 if (m_applet->lifecycle_manager.GetExitRequested()) { 108 if (system.GetExitRequested()) {
120 m_applet->process->Terminate(); 109 system.Exit();
121 } 110 }
122 111
123 R_SUCCEED(); 112 R_SUCCEED();
@@ -166,7 +155,7 @@ Result ISelfController::SetOperationModeChangedNotification(bool enabled) {
166 LOG_INFO(Service_AM, "called, enabled={}", enabled); 155 LOG_INFO(Service_AM, "called, enabled={}", enabled);
167 156
168 std::scoped_lock lk{m_applet->lock}; 157 std::scoped_lock lk{m_applet->lock};
169 m_applet->lifecycle_manager.SetOperationModeChangedNotificationEnabled(enabled); 158 m_applet->operation_mode_changed_notification_enabled = enabled;
170 159
171 R_SUCCEED(); 160 R_SUCCEED();
172} 161}
@@ -175,18 +164,17 @@ Result ISelfController::SetPerformanceModeChangedNotification(bool enabled) {
175 LOG_INFO(Service_AM, "called, enabled={}", enabled); 164 LOG_INFO(Service_AM, "called, enabled={}", enabled);
176 165
177 std::scoped_lock lk{m_applet->lock}; 166 std::scoped_lock lk{m_applet->lock};
178 m_applet->lifecycle_manager.SetPerformanceModeChangedNotificationEnabled(enabled); 167 m_applet->performance_mode_changed_notification_enabled = enabled;
179 168
180 R_SUCCEED(); 169 R_SUCCEED();
181} 170}
182 171
183Result ISelfController::SetFocusHandlingMode(bool notify, bool background, bool suspend) { 172Result ISelfController::SetFocusHandlingMode(bool notify, bool background, bool suspend) {
184 LOG_INFO(Service_AM, "called, notify={} background={} suspend={}", notify, background, suspend); 173 LOG_WARNING(Service_AM, "(STUBBED) called, notify={} background={} suspend={}", notify,
174 background, suspend);
185 175
186 std::scoped_lock lk{m_applet->lock}; 176 std::scoped_lock lk{m_applet->lock};
187 m_applet->lifecycle_manager.SetFocusStateChangedNotificationEnabled(notify); 177 m_applet->focus_handling_mode = {notify, background, suspend};
188 m_applet->lifecycle_manager.SetFocusHandlingMode(suspend);
189 m_applet->UpdateSuspensionStateLocked(true);
190 178
191 R_SUCCEED(); 179 R_SUCCEED();
192} 180}
@@ -195,7 +183,7 @@ Result ISelfController::SetRestartMessageEnabled(bool enabled) {
195 LOG_INFO(Service_AM, "called, enabled={}", enabled); 183 LOG_INFO(Service_AM, "called, enabled={}", enabled);
196 184
197 std::scoped_lock lk{m_applet->lock}; 185 std::scoped_lock lk{m_applet->lock};
198 m_applet->lifecycle_manager.SetResumeNotificationEnabled(enabled); 186 m_applet->restart_message_enabled = enabled;
199 187
200 R_SUCCEED(); 188 R_SUCCEED();
201} 189}
@@ -214,8 +202,7 @@ Result ISelfController::SetOutOfFocusSuspendingEnabled(bool enabled) {
214 LOG_INFO(Service_AM, "called, enabled={}", enabled); 202 LOG_INFO(Service_AM, "called, enabled={}", enabled);
215 203
216 std::scoped_lock lk{m_applet->lock}; 204 std::scoped_lock lk{m_applet->lock};
217 m_applet->lifecycle_manager.SetOutOfFocusSuspendingEnabled(enabled); 205 m_applet->out_of_focus_suspension_enabled = enabled;
218 m_applet->UpdateSuspensionStateLocked(false);
219 206
220 R_SUCCEED(); 207 R_SUCCEED();
221} 208}
diff --git a/src/core/hle/service/am/service/system_applet_proxy.cpp b/src/core/hle/service/am/service/system_applet_proxy.cpp
index c435288a2..d1871ef9b 100755
--- a/src/core/hle/service/am/service/system_applet_proxy.cpp
+++ b/src/core/hle/service/am/service/system_applet_proxy.cpp
@@ -19,9 +19,9 @@
19namespace Service::AM { 19namespace Service::AM {
20 20
21ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet, 21ISystemAppletProxy::ISystemAppletProxy(Core::System& system_, std::shared_ptr<Applet> applet,
22 Kernel::KProcess* process, WindowSystem& window_system) 22 Kernel::KProcess* process)
23 : ServiceFramework{system_, "ISystemAppletProxy"}, 23 : ServiceFramework{system_, "ISystemAppletProxy"}, m_process{process}, m_applet{
24 m_window_system{window_system}, m_process{process}, m_applet{std::move(applet)} { 24 std::move(applet)} {
25 // clang-format off 25 // clang-format off
26 static const FunctionInfo functions[] = { 26 static const FunctionInfo functions[] = {
27 {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"}, 27 {0, D<&ISystemAppletProxy::GetCommonStateGetter>, "GetCommonStateGetter"},
@@ -75,7 +75,7 @@ Result ISystemAppletProxy::GetDebugFunctions(
75Result ISystemAppletProxy::GetWindowController( 75Result ISystemAppletProxy::GetWindowController(
76 Out<SharedPointer<IWindowController>> out_window_controller) { 76 Out<SharedPointer<IWindowController>> out_window_controller) {
77 LOG_DEBUG(Service_AM, "called"); 77 LOG_DEBUG(Service_AM, "called");
78 *out_window_controller = std::make_shared<IWindowController>(system, m_applet, m_window_system); 78 *out_window_controller = std::make_shared<IWindowController>(system, m_applet);
79 R_SUCCEED(); 79 R_SUCCEED();
80} 80}
81 81
@@ -96,15 +96,14 @@ Result ISystemAppletProxy::GetCommonStateGetter(
96Result ISystemAppletProxy::GetLibraryAppletCreator( 96Result ISystemAppletProxy::GetLibraryAppletCreator(
97 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) { 97 Out<SharedPointer<ILibraryAppletCreator>> out_library_applet_creator) {
98 LOG_DEBUG(Service_AM, "called"); 98 LOG_DEBUG(Service_AM, "called");
99 *out_library_applet_creator = 99 *out_library_applet_creator = std::make_shared<ILibraryAppletCreator>(system, m_applet);
100 std::make_shared<ILibraryAppletCreator>(system, m_applet, m_window_system);
101 R_SUCCEED(); 100 R_SUCCEED();
102} 101}
103 102
104Result ISystemAppletProxy::GetApplicationCreator( 103Result ISystemAppletProxy::GetApplicationCreator(
105 Out<SharedPointer<IApplicationCreator>> out_application_creator) { 104 Out<SharedPointer<IApplicationCreator>> out_application_creator) {
106 LOG_DEBUG(Service_AM, "called"); 105 LOG_DEBUG(Service_AM, "called");
107 *out_application_creator = std::make_shared<IApplicationCreator>(system, m_window_system); 106 *out_application_creator = std::make_shared<IApplicationCreator>(system);
108 R_SUCCEED(); 107 R_SUCCEED();
109} 108}
110 109
@@ -118,8 +117,7 @@ Result ISystemAppletProxy::GetAppletCommonFunctions(
118Result ISystemAppletProxy::GetHomeMenuFunctions( 117Result ISystemAppletProxy::GetHomeMenuFunctions(
119 Out<SharedPointer<IHomeMenuFunctions>> out_home_menu_functions) { 118 Out<SharedPointer<IHomeMenuFunctions>> out_home_menu_functions) {
120 LOG_DEBUG(Service_AM, "called"); 119 LOG_DEBUG(Service_AM, "called");
121 *out_home_menu_functions = 120 *out_home_menu_functions = std::make_shared<IHomeMenuFunctions>(system, m_applet);
122 std::make_shared<IHomeMenuFunctions>(system, m_applet, m_window_system);
123 R_SUCCEED(); 121 R_SUCCEED();
124} 122}
125 123
diff --git a/src/core/hle/service/am/service/system_applet_proxy.h b/src/core/hle/service/am/service/system_applet_proxy.h
index 217d9dc8c..67cd50e03 100755
--- a/src/core/hle/service/am/service/system_applet_proxy.h
+++ b/src/core/hle/service/am/service/system_applet_proxy.h
@@ -21,12 +21,11 @@ class ILibraryAppletCreator;
21class IProcessWindingController; 21class IProcessWindingController;
22class ISelfController; 22class ISelfController;
23class IWindowController; 23class IWindowController;
24class WindowSystem;
25 24
26class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> { 25class ISystemAppletProxy final : public ServiceFramework<ISystemAppletProxy> {
27public: 26public:
28 explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet, 27 explicit ISystemAppletProxy(Core::System& system, std::shared_ptr<Applet> applet,
29 Kernel::KProcess* process, WindowSystem& window_system); 28 Kernel::KProcess* process);
30 ~ISystemAppletProxy(); 29 ~ISystemAppletProxy();
31 30
32private: 31private:
@@ -47,7 +46,6 @@ private:
47 Result GetGlobalStateController( 46 Result GetGlobalStateController(
48 Out<SharedPointer<IGlobalStateController>> out_global_state_controller); 47 Out<SharedPointer<IGlobalStateController>> out_global_state_controller);
49 48
50 WindowSystem& m_window_system;
51 Kernel::KProcess* const m_process; 49 Kernel::KProcess* const m_process;
52 const std::shared_ptr<Applet> m_applet; 50 const std::shared_ptr<Applet> m_applet;
53}; 51};
diff --git a/src/core/hle/service/am/service/window_controller.cpp b/src/core/hle/service/am/service/window_controller.cpp
index 54396affb..99a4f50a2 100755
--- a/src/core/hle/service/am/service/window_controller.cpp
+++ b/src/core/hle/service/am/service/window_controller.cpp
@@ -4,15 +4,12 @@
4#include "core/hle/service/am/applet.h" 4#include "core/hle/service/am/applet.h"
5#include "core/hle/service/am/applet_manager.h" 5#include "core/hle/service/am/applet_manager.h"
6#include "core/hle/service/am/service/window_controller.h" 6#include "core/hle/service/am/service/window_controller.h"
7#include "core/hle/service/am/window_system.h"
8#include "core/hle/service/cmif_serialization.h" 7#include "core/hle/service/cmif_serialization.h"
9 8
10namespace Service::AM { 9namespace Service::AM {
11 10
12IWindowController::IWindowController(Core::System& system_, std::shared_ptr<Applet> applet, 11IWindowController::IWindowController(Core::System& system_, std::shared_ptr<Applet> applet)
13 WindowSystem& window_system) 12 : ServiceFramework{system_, "IWindowController"}, m_applet{std::move(applet)} {
14 : ServiceFramework{system_, "IWindowController"},
15 m_window_system{window_system}, m_applet{std::move(applet)} {
16 // clang-format off 13 // clang-format off
17 static const FunctionInfo functions[] = { 14 static const FunctionInfo functions[] = {
18 {0, nullptr, "CreateWindow"}, 15 {0, nullptr, "CreateWindow"},
@@ -66,9 +63,17 @@ Result IWindowController::RejectToChangeIntoBackground() {
66} 63}
67 64
68Result IWindowController::SetAppletWindowVisibility(bool visible) { 65Result IWindowController::SetAppletWindowVisibility(bool visible) {
69 LOG_INFO(Service_AM, "called"); 66 m_applet->display_layer_manager.SetWindowVisibility(visible);
67 m_applet->hid_registration.EnableAppletToGetInput(visible);
68
69 if (visible) {
70 m_applet->message_queue.PushMessage(AppletMessage::ChangeIntoForeground);
71 m_applet->focus_state = FocusState::InFocus;
72 } else {
73 m_applet->focus_state = FocusState::NotInFocus;
74 }
70 75
71 m_window_system.RequestAppletVisibilityState(*m_applet, visible); 76 m_applet->message_queue.PushMessage(AppletMessage::FocusStateChanged);
72 77
73 R_SUCCEED(); 78 R_SUCCEED();
74} 79}
diff --git a/src/core/hle/service/am/service/window_controller.h b/src/core/hle/service/am/service/window_controller.h
index a784dd4a4..bfbad9bcc 100755
--- a/src/core/hle/service/am/service/window_controller.h
+++ b/src/core/hle/service/am/service/window_controller.h
@@ -9,12 +9,10 @@
9namespace Service::AM { 9namespace Service::AM {
10 10
11struct Applet; 11struct Applet;
12class WindowSystem;
13 12
14class IWindowController final : public ServiceFramework<IWindowController> { 13class IWindowController final : public ServiceFramework<IWindowController> {
15public: 14public:
16 explicit IWindowController(Core::System& system_, std::shared_ptr<Applet> applet, 15 explicit IWindowController(Core::System& system_, std::shared_ptr<Applet> applet);
17 WindowSystem& window_system);
18 ~IWindowController() override; 16 ~IWindowController() override;
19 17
20private: 18private:
@@ -26,7 +24,6 @@ private:
26 Result SetAppletWindowVisibility(bool visible); 24 Result SetAppletWindowVisibility(bool visible);
27 Result SetAppletGpuTimeSlice(s64 time_slice); 25 Result SetAppletGpuTimeSlice(s64 time_slice);
28 26
29 WindowSystem& m_window_system;
30 const std::shared_ptr<Applet> m_applet; 27 const std::shared_ptr<Applet> m_applet;
31}; 28};
32 29
diff --git a/src/core/hle/service/hid/active_vibration_device_list.cpp b/src/core/hle/service/hid/active_vibration_device_list.cpp
new file mode 100755
index 000000000..c440f8382
--- /dev/null
+++ b/src/core/hle/service/hid/active_vibration_device_list.cpp
@@ -0,0 +1,53 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "common/logging/log.h"
5#include "core/hle/service/cmif_serialization.h"
6#include "core/hle/service/hid/active_vibration_device_list.h"
7#include "hid_core/hid_result.h"
8#include "hid_core/hid_util.h"
9#include "hid_core/resource_manager.h"
10#include "hid_core/resources/vibration/vibration_device.h"
11
12namespace Service::HID {
13
14IActiveVibrationDeviceList::IActiveVibrationDeviceList(Core::System& system_,
15 std::shared_ptr<ResourceManager> resource)
16 : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) {
17 // clang-format off
18 static const FunctionInfo functions[] = {
19 {0, C<&IActiveVibrationDeviceList::ActivateVibrationDevice>, "ActivateVibrationDevice"},
20 };
21 // clang-format on
22
23 RegisterHandlers(functions);
24}
25
26IActiveVibrationDeviceList::~IActiveVibrationDeviceList() = default;
27
28Result IActiveVibrationDeviceList::ActivateVibrationDevice(
29 Core::HID::VibrationDeviceHandle vibration_device_handle) {
30 LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}",
31 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
32 vibration_device_handle.device_index);
33
34 std::scoped_lock lock{mutex};
35
36 R_TRY(IsVibrationHandleValid(vibration_device_handle));
37
38 for (std::size_t i = 0; i < list_size; i++) {
39 if (vibration_device_handle.device_index == vibration_device_list[i].device_index &&
40 vibration_device_handle.npad_id == vibration_device_list[i].npad_id &&
41 vibration_device_handle.npad_type == vibration_device_list[i].npad_type) {
42 R_SUCCEED();
43 }
44 }
45
46 R_UNLESS(list_size < MaxVibrationDevicesHandles, ResultVibrationDeviceIndexOutOfRange);
47 R_TRY(resource_manager->GetVibrationDevice(vibration_device_handle)->Activate());
48
49 vibration_device_list[list_size++] = vibration_device_handle;
50 R_SUCCEED();
51}
52
53} // namespace Service::HID
diff --git a/src/core/hle/service/hid/active_vibration_device_list.h b/src/core/hle/service/hid/active_vibration_device_list.h
new file mode 100755
index 000000000..beaa44d97
--- /dev/null
+++ b/src/core/hle/service/hid/active_vibration_device_list.h
@@ -0,0 +1,39 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#pragma once
5
6#include <array>
7#include <memory>
8#include <mutex>
9
10#include "core/hle/service/cmif_types.h"
11#include "core/hle/service/service.h"
12#include "hid_core/hid_types.h"
13
14namespace Core {
15class System;
16}
17
18namespace Service::HID {
19class ResourceManager;
20
21class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> {
22public:
23 explicit IActiveVibrationDeviceList(Core::System& system_,
24 std::shared_ptr<ResourceManager> resource);
25 ~IActiveVibrationDeviceList() override;
26
27private:
28 static constexpr std::size_t MaxVibrationDevicesHandles{0x100};
29
30 Result ActivateVibrationDevice(Core::HID::VibrationDeviceHandle vibration_device_handle);
31
32 mutable std::mutex mutex;
33 std::size_t list_size{};
34 std::array<Core::HID::VibrationDeviceHandle, MaxVibrationDevicesHandles>
35 vibration_device_list{};
36 std::shared_ptr<ResourceManager> resource_manager;
37};
38
39} // namespace Service::HID
diff --git a/src/core/hle/service/hid/applet_resource.cpp b/src/core/hle/service/hid/applet_resource.cpp
new file mode 100755
index 000000000..4814d7ad5
--- /dev/null
+++ b/src/core/hle/service/hid/applet_resource.cpp
@@ -0,0 +1,34 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "common/logging/log.h"
5#include "core/hle/kernel/k_shared_memory.h"
6#include "core/hle/service/cmif_serialization.h"
7#include "core/hle/service/hid/applet_resource.h"
8#include "hid_core/resource_manager.h"
9
10namespace Service::HID {
11
12IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
13 u64 applet_resource_user_id)
14 : ServiceFramework{system_, "IAppletResource"}, aruid{applet_resource_user_id},
15 resource_manager{resource} {
16 static const FunctionInfo functions[] = {
17 {0, C<&IAppletResource::GetSharedMemoryHandle>, "GetSharedMemoryHandle"},
18 };
19 RegisterHandlers(functions);
20}
21
22IAppletResource::~IAppletResource() {
23 resource_manager->FreeAppletResourceId(aruid);
24}
25
26Result IAppletResource::GetSharedMemoryHandle(
27 OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle) {
28 const auto result = resource_manager->GetSharedMemoryHandle(out_shared_memory_handle, aruid);
29
30 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid, result.raw);
31 R_RETURN(result);
32}
33
34} // namespace Service::HID
diff --git a/src/core/hle/service/hid/applet_resource.h b/src/core/hle/service/hid/applet_resource.h
new file mode 100755
index 000000000..d1e7db9b1
--- /dev/null
+++ b/src/core/hle/service/hid/applet_resource.h
@@ -0,0 +1,36 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#pragma once
5
6#include <memory>
7
8#include "common/common_types.h"
9#include "core/hle/service/cmif_types.h"
10#include "core/hle/service/service.h"
11
12namespace Core {
13class System;
14}
15
16namespace Kernel {
17class KSharedMemory;
18}
19
20namespace Service::HID {
21class ResourceManager;
22
23class IAppletResource final : public ServiceFramework<IAppletResource> {
24public:
25 explicit IAppletResource(Core::System& system_, std::shared_ptr<ResourceManager> resource,
26 u64 applet_resource_user_id);
27 ~IAppletResource() override;
28
29private:
30 Result GetSharedMemoryHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle);
31
32 u64 aruid{};
33 std::shared_ptr<ResourceManager> resource_manager;
34};
35
36} // namespace Service::HID
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index e6a5a0250..4a2e2c56c 100755
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -23,7 +23,11 @@ void LoopProcess(Core::System& system) {
23 std::shared_ptr<ResourceManager> resource_manager = 23 std::shared_ptr<ResourceManager> resource_manager =
24 std::make_shared<ResourceManager>(system, firmware_settings); 24 std::make_shared<ResourceManager>(system, firmware_settings);
25 25
26 // TODO: Remove this hack when am is emulated properly.
26 resource_manager->Initialize(); 27 resource_manager->Initialize();
28 resource_manager->RegisterAppletResourceUserId(system.ApplicationProcess()->GetProcessId(),
29 true);
30 resource_manager->SetAruidValidForVibration(system.ApplicationProcess()->GetProcessId(), true);
27 31
28 server_manager->RegisterNamedService( 32 server_manager->RegisterNamedService(
29 "hid", std::make_shared<IHidServer>(system, resource_manager, firmware_settings)); 33 "hid", std::make_shared<IHidServer>(system, resource_manager, firmware_settings));
diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp
index 3603d8ccf..926a3bfe9 100755
--- a/src/core/hle/service/hid/hid_server.cpp
+++ b/src/core/hle/service/hid/hid_server.cpp
@@ -2,6 +2,7 @@
2// SPDX-License-Identifier: GPL-3.0-or-later 2// SPDX-License-Identifier: GPL-3.0-or-later
3 3
4#include <array> 4#include <array>
5
5#include "common/common_types.h" 6#include "common/common_types.h"
6#include "common/logging/log.h" 7#include "common/logging/log.h"
7#include "common/settings.h" 8#include "common/settings.h"
@@ -9,6 +10,8 @@
9#include "core/hle/kernel/k_transfer_memory.h" 10#include "core/hle/kernel/k_transfer_memory.h"
10#include "core/hle/kernel/kernel.h" 11#include "core/hle/kernel/kernel.h"
11#include "core/hle/service/cmif_serialization.h" 12#include "core/hle/service/cmif_serialization.h"
13#include "core/hle/service/hid/active_vibration_device_list.h"
14#include "core/hle/service/hid/applet_resource.h"
12#include "core/hle/service/hid/hid_server.h" 15#include "core/hle/service/hid/hid_server.h"
13#include "core/hle/service/ipc_helpers.h" 16#include "core/hle/service/ipc_helpers.h"
14#include "core/memory.h" 17#include "core/memory.h"
@@ -36,168 +39,107 @@
36 39
37namespace Service::HID { 40namespace Service::HID {
38 41
39class IActiveVibrationDeviceList final : public ServiceFramework<IActiveVibrationDeviceList> {
40public:
41 explicit IActiveVibrationDeviceList(Core::System& system_,
42 std::shared_ptr<ResourceManager> resource)
43 : ServiceFramework{system_, "IActiveVibrationDeviceList"}, resource_manager(resource) {
44 // clang-format off
45 static const FunctionInfo functions[] = {
46 {0, &IActiveVibrationDeviceList::ActivateVibrationDevice, "ActivateVibrationDevice"},
47 };
48 // clang-format on
49
50 RegisterHandlers(functions);
51 }
52
53private:
54 void ActivateVibrationDevice(HLERequestContext& ctx) {
55 IPC::RequestParser rp{ctx};
56 const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()};
57
58 LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}",
59 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
60 vibration_device_handle.device_index);
61
62 const auto result = ActivateVibrationDeviceImpl(vibration_device_handle);
63
64 IPC::ResponseBuilder rb{ctx, 2};
65 rb.Push(result);
66 }
67
68 Result ActivateVibrationDeviceImpl(const Core::HID::VibrationDeviceHandle& handle) {
69 std::scoped_lock lock{mutex};
70
71 const Result is_valid = IsVibrationHandleValid(handle);
72 if (is_valid.IsError()) {
73 return is_valid;
74 }
75
76 for (std::size_t i = 0; i < list_size; i++) {
77 if (handle.device_index == vibration_device_list[i].device_index &&
78 handle.npad_id == vibration_device_list[i].npad_id &&
79 handle.npad_type == vibration_device_list[i].npad_type) {
80 return ResultSuccess;
81 }
82 }
83 if (list_size == vibration_device_list.size()) {
84 return ResultVibrationDeviceIndexOutOfRange;
85 }
86 const Result result = resource_manager->GetVibrationDevice(handle)->Activate();
87 if (result.IsError()) {
88 return result;
89 }
90 vibration_device_list[list_size++] = handle;
91 return ResultSuccess;
92 }
93
94 mutable std::mutex mutex;
95 std::size_t list_size{};
96 std::array<Core::HID::VibrationDeviceHandle, 0x100> vibration_device_list{};
97 std::shared_ptr<ResourceManager> resource_manager;
98};
99
100IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, 42IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> resource,
101 std::shared_ptr<HidFirmwareSettings> settings) 43 std::shared_ptr<HidFirmwareSettings> settings)
102 : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { 44 : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} {
103 // clang-format off 45 // clang-format off
104 static const FunctionInfo functions[] = { 46 static const FunctionInfo functions[] = {
105 {0, &IHidServer::CreateAppletResource, "CreateAppletResource"}, 47 {0, C<&IHidServer::CreateAppletResource>, "CreateAppletResource"},
106 {1, &IHidServer::ActivateDebugPad, "ActivateDebugPad"}, 48 {1, C<&IHidServer::ActivateDebugPad>, "ActivateDebugPad"},
107 {11, &IHidServer::ActivateTouchScreen, "ActivateTouchScreen"}, 49 {11, C<&IHidServer::ActivateTouchScreen>, "ActivateTouchScreen"},
108 {21, &IHidServer::ActivateMouse, "ActivateMouse"}, 50 {21, C<&IHidServer::ActivateMouse>, "ActivateMouse"},
109 {26, nullptr, "ActivateDebugMouse"}, 51 {26, nullptr, "ActivateDebugMouse"},
110 {31, &IHidServer::ActivateKeyboard, "ActivateKeyboard"}, 52 {31, C<&IHidServer::ActivateKeyboard>, "ActivateKeyboard"},
111 {32, &IHidServer::SendKeyboardLockKeyEvent, "SendKeyboardLockKeyEvent"}, 53 {32, C<&IHidServer::SendKeyboardLockKeyEvent>, "SendKeyboardLockKeyEvent"},
112 {40, &IHidServer::AcquireXpadIdEventHandle, "AcquireXpadIdEventHandle"}, 54 {40, C<&IHidServer::AcquireXpadIdEventHandle>, "AcquireXpadIdEventHandle"},
113 {41, &IHidServer::ReleaseXpadIdEventHandle, "ReleaseXpadIdEventHandle"}, 55 {41, C<&IHidServer::ReleaseXpadIdEventHandle>, "ReleaseXpadIdEventHandle"},
114 {51, &IHidServer::ActivateXpad, "ActivateXpad"}, 56 {51, C<&IHidServer::ActivateXpad>, "ActivateXpad"},
115 {55, &IHidServer::GetXpadIds, "GetXpadIds"}, 57 {55, C<&IHidServer::GetXpadIds>, "GetXpadIds"},
116 {56, &IHidServer::ActivateJoyXpad, "ActivateJoyXpad"}, 58 {56, C<&IHidServer::ActivateJoyXpad>, "ActivateJoyXpad"},
117 {58, &IHidServer::GetJoyXpadLifoHandle, "GetJoyXpadLifoHandle"}, 59 {58, C<&IHidServer::GetJoyXpadLifoHandle>, "GetJoyXpadLifoHandle"},
118 {59, &IHidServer::GetJoyXpadIds, "GetJoyXpadIds"}, 60 {59, C<&IHidServer::GetJoyXpadIds>, "GetJoyXpadIds"},
119 {60, &IHidServer::ActivateSixAxisSensor, "ActivateSixAxisSensor"}, 61 {60, C<&IHidServer::ActivateSixAxisSensor>, "ActivateSixAxisSensor"},
120 {61, &IHidServer::DeactivateSixAxisSensor, "DeactivateSixAxisSensor"}, 62 {61, C<&IHidServer::DeactivateSixAxisSensor>, "DeactivateSixAxisSensor"},
121 {62, &IHidServer::GetSixAxisSensorLifoHandle, "GetSixAxisSensorLifoHandle"}, 63 {62, C<&IHidServer::GetSixAxisSensorLifoHandle>, "GetSixAxisSensorLifoHandle"},
122 {63, &IHidServer::ActivateJoySixAxisSensor, "ActivateJoySixAxisSensor"}, 64 {63, C<&IHidServer::ActivateJoySixAxisSensor>, "ActivateJoySixAxisSensor"},
123 {64, &IHidServer::DeactivateJoySixAxisSensor, "DeactivateJoySixAxisSensor"}, 65 {64, C<&IHidServer::DeactivateJoySixAxisSensor>, "DeactivateJoySixAxisSensor"},
124 {65, &IHidServer::GetJoySixAxisSensorLifoHandle, "GetJoySixAxisSensorLifoHandle"}, 66 {65, C<&IHidServer::GetJoySixAxisSensorLifoHandle>, "GetJoySixAxisSensorLifoHandle"},
125 {66, &IHidServer::StartSixAxisSensor, "StartSixAxisSensor"}, 67 {66, C<&IHidServer::StartSixAxisSensor>, "StartSixAxisSensor"},
126 {67, &IHidServer::StopSixAxisSensor, "StopSixAxisSensor"}, 68 {67, C<&IHidServer::StopSixAxisSensor>, "StopSixAxisSensor"},
127 {68, &IHidServer::IsSixAxisSensorFusionEnabled, "IsSixAxisSensorFusionEnabled"}, 69 {68, C<&IHidServer::IsSixAxisSensorFusionEnabled>, "IsSixAxisSensorFusionEnabled"},
128 {69, &IHidServer::EnableSixAxisSensorFusion, "EnableSixAxisSensorFusion"}, 70 {69, C<&IHidServer::EnableSixAxisSensorFusion>, "EnableSixAxisSensorFusion"},
129 {70, &IHidServer::SetSixAxisSensorFusionParameters, "SetSixAxisSensorFusionParameters"}, 71 {70, C<&IHidServer::SetSixAxisSensorFusionParameters>, "SetSixAxisSensorFusionParameters"},
130 {71, &IHidServer::GetSixAxisSensorFusionParameters, "GetSixAxisSensorFusionParameters"}, 72 {71, C<&IHidServer::GetSixAxisSensorFusionParameters>, "GetSixAxisSensorFusionParameters"},
131 {72, &IHidServer::ResetSixAxisSensorFusionParameters, "ResetSixAxisSensorFusionParameters"}, 73 {72, C<&IHidServer::ResetSixAxisSensorFusionParameters>, "ResetSixAxisSensorFusionParameters"},
132 {73, nullptr, "SetAccelerometerParameters"}, 74 {73, nullptr, "SetAccelerometerParameters"},
133 {74, nullptr, "GetAccelerometerParameters"}, 75 {74, nullptr, "GetAccelerometerParameters"},
134 {75, nullptr, "ResetAccelerometerParameters"}, 76 {75, nullptr, "ResetAccelerometerParameters"},
135 {76, nullptr, "SetAccelerometerPlayMode"}, 77 {76, nullptr, "SetAccelerometerPlayMode"},
136 {77, nullptr, "GetAccelerometerPlayMode"}, 78 {77, nullptr, "GetAccelerometerPlayMode"},
137 {78, nullptr, "ResetAccelerometerPlayMode"}, 79 {78, nullptr, "ResetAccelerometerPlayMode"},
138 {79, &IHidServer::SetGyroscopeZeroDriftMode, "SetGyroscopeZeroDriftMode"}, 80 {79, C<&IHidServer::SetGyroscopeZeroDriftMode>, "SetGyroscopeZeroDriftMode"},
139 {80, &IHidServer::GetGyroscopeZeroDriftMode, "GetGyroscopeZeroDriftMode"}, 81 {80, C<&IHidServer::GetGyroscopeZeroDriftMode>, "GetGyroscopeZeroDriftMode"},
140 {81, &IHidServer::ResetGyroscopeZeroDriftMode, "ResetGyroscopeZeroDriftMode"}, 82 {81, C<&IHidServer::ResetGyroscopeZeroDriftMode>, "ResetGyroscopeZeroDriftMode"},
141 {82, &IHidServer::IsSixAxisSensorAtRest, "IsSixAxisSensorAtRest"}, 83 {82, C<&IHidServer::IsSixAxisSensorAtRest>, "IsSixAxisSensorAtRest"},
142 {83, &IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor, "IsFirmwareUpdateAvailableForSixAxisSensor"}, 84 {83, C<&IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor>, "IsFirmwareUpdateAvailableForSixAxisSensor"},
143 {84, &IHidServer::EnableSixAxisSensorUnalteredPassthrough, "EnableSixAxisSensorUnalteredPassthrough"}, 85 {84, C<&IHidServer::EnableSixAxisSensorUnalteredPassthrough>, "EnableSixAxisSensorUnalteredPassthrough"},
144 {85, &IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled, "IsSixAxisSensorUnalteredPassthroughEnabled"}, 86 {85, C<&IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled>, "IsSixAxisSensorUnalteredPassthroughEnabled"},
145 {86, nullptr, "StoreSixAxisSensorCalibrationParameter"}, 87 {86, nullptr, "StoreSixAxisSensorCalibrationParameter"},
146 {87, &IHidServer::LoadSixAxisSensorCalibrationParameter, "LoadSixAxisSensorCalibrationParameter"}, 88 {87, C<&IHidServer::LoadSixAxisSensorCalibrationParameter>, "LoadSixAxisSensorCalibrationParameter"},
147 {88, &IHidServer::GetSixAxisSensorIcInformation, "GetSixAxisSensorIcInformation"}, 89 {88, C<&IHidServer::GetSixAxisSensorIcInformation>, "GetSixAxisSensorIcInformation"},
148 {89, &IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned, "ResetIsSixAxisSensorDeviceNewlyAssigned"}, 90 {89, C<&IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned>, "ResetIsSixAxisSensorDeviceNewlyAssigned"},
149 {91, &IHidServer::ActivateGesture, "ActivateGesture"}, 91 {91, C<&IHidServer::ActivateGesture>, "ActivateGesture"},
150 {100, &IHidServer::SetSupportedNpadStyleSet, "SetSupportedNpadStyleSet"}, 92 {100, C<&IHidServer::SetSupportedNpadStyleSet>, "SetSupportedNpadStyleSet"},
151 {101, &IHidServer::GetSupportedNpadStyleSet, "GetSupportedNpadStyleSet"}, 93 {101, C<&IHidServer::GetSupportedNpadStyleSet>, "GetSupportedNpadStyleSet"},
152 {102, &IHidServer::SetSupportedNpadIdType, "SetSupportedNpadIdType"}, 94 {102, C<&IHidServer::SetSupportedNpadIdType>, "SetSupportedNpadIdType"},
153 {103, &IHidServer::ActivateNpad, "ActivateNpad"}, 95 {103, C<&IHidServer::ActivateNpad>, "ActivateNpad"},
154 {104, &IHidServer::DeactivateNpad, "DeactivateNpad"}, 96 {104, C<&IHidServer::DeactivateNpad>, "DeactivateNpad"},
155 {106, &IHidServer::AcquireNpadStyleSetUpdateEventHandle, "AcquireNpadStyleSetUpdateEventHandle"}, 97 {106, C<&IHidServer::AcquireNpadStyleSetUpdateEventHandle>, "AcquireNpadStyleSetUpdateEventHandle"},
156 {107, &IHidServer::DisconnectNpad, "DisconnectNpad"}, 98 {107, C<&IHidServer::DisconnectNpad>, "DisconnectNpad"},
157 {108, C<&IHidServer::GetPlayerLedPattern>, "GetPlayerLedPattern"}, 99 {108, C<&IHidServer::GetPlayerLedPattern>, "GetPlayerLedPattern"},
158 {109, &IHidServer::ActivateNpadWithRevision, "ActivateNpadWithRevision"}, 100 {109, C<&IHidServer::ActivateNpadWithRevision>, "ActivateNpadWithRevision"},
159 {120, &IHidServer::SetNpadJoyHoldType, "SetNpadJoyHoldType"}, 101 {120, C<&IHidServer::SetNpadJoyHoldType>, "SetNpadJoyHoldType"},
160 {121, &IHidServer::GetNpadJoyHoldType, "GetNpadJoyHoldType"}, 102 {121, C<&IHidServer::GetNpadJoyHoldType>, "GetNpadJoyHoldType"},
161 {122, &IHidServer::SetNpadJoyAssignmentModeSingleByDefault, "SetNpadJoyAssignmentModeSingleByDefault"}, 103 {122, C<&IHidServer::SetNpadJoyAssignmentModeSingleByDefault>, "SetNpadJoyAssignmentModeSingleByDefault"},
162 {123, &IHidServer::SetNpadJoyAssignmentModeSingle, "SetNpadJoyAssignmentModeSingle"}, 104 {123, C<&IHidServer::SetNpadJoyAssignmentModeSingle>, "SetNpadJoyAssignmentModeSingle"},
163 {124, &IHidServer::SetNpadJoyAssignmentModeDual, "SetNpadJoyAssignmentModeDual"}, 105 {124, C<&IHidServer::SetNpadJoyAssignmentModeDual>, "SetNpadJoyAssignmentModeDual"},
164 {125, &IHidServer::MergeSingleJoyAsDualJoy, "MergeSingleJoyAsDualJoy"}, 106 {125, C<&IHidServer::MergeSingleJoyAsDualJoy>, "MergeSingleJoyAsDualJoy"},
165 {126, &IHidServer::StartLrAssignmentMode, "StartLrAssignmentMode"}, 107 {126, C<&IHidServer::StartLrAssignmentMode>, "StartLrAssignmentMode"},
166 {127, &IHidServer::StopLrAssignmentMode, "StopLrAssignmentMode"}, 108 {127, C<&IHidServer::StopLrAssignmentMode>, "StopLrAssignmentMode"},
167 {128, &IHidServer::SetNpadHandheldActivationMode, "SetNpadHandheldActivationMode"}, 109 {128, C<&IHidServer::SetNpadHandheldActivationMode>, "SetNpadHandheldActivationMode"},
168 {129, &IHidServer::GetNpadHandheldActivationMode, "GetNpadHandheldActivationMode"}, 110 {129, C<&IHidServer::GetNpadHandheldActivationMode>, "GetNpadHandheldActivationMode"},
169 {130, &IHidServer::SwapNpadAssignment, "SwapNpadAssignment"}, 111 {130, C<&IHidServer::SwapNpadAssignment>, "SwapNpadAssignment"},
170 {131, &IHidServer::IsUnintendedHomeButtonInputProtectionEnabled, "IsUnintendedHomeButtonInputProtectionEnabled"}, 112 {131, C<&IHidServer::IsUnintendedHomeButtonInputProtectionEnabled>, "IsUnintendedHomeButtonInputProtectionEnabled"},
171 {132, &IHidServer::EnableUnintendedHomeButtonInputProtection, "EnableUnintendedHomeButtonInputProtection"}, 113 {132, C<&IHidServer::EnableUnintendedHomeButtonInputProtection>, "EnableUnintendedHomeButtonInputProtection"},
172 {133, &IHidServer::SetNpadJoyAssignmentModeSingleWithDestination, "SetNpadJoyAssignmentModeSingleWithDestination"}, 114 {133, C<&IHidServer::SetNpadJoyAssignmentModeSingleWithDestination>, "SetNpadJoyAssignmentModeSingleWithDestination"},
173 {134, &IHidServer::SetNpadAnalogStickUseCenterClamp, "SetNpadAnalogStickUseCenterClamp"}, 115 {134, C<&IHidServer::SetNpadAnalogStickUseCenterClamp>, "SetNpadAnalogStickUseCenterClamp"},
174 {135, &IHidServer::SetNpadCaptureButtonAssignment, "SetNpadCaptureButtonAssignment"}, 116 {135, C<&IHidServer::SetNpadCaptureButtonAssignment>, "SetNpadCaptureButtonAssignment"},
175 {136, &IHidServer::ClearNpadCaptureButtonAssignment, "ClearNpadCaptureButtonAssignment"}, 117 {136, C<&IHidServer::ClearNpadCaptureButtonAssignment>, "ClearNpadCaptureButtonAssignment"},
176 {200, &IHidServer::GetVibrationDeviceInfo, "GetVibrationDeviceInfo"}, 118 {200, C<&IHidServer::GetVibrationDeviceInfo>, "GetVibrationDeviceInfo"},
177 {201, &IHidServer::SendVibrationValue, "SendVibrationValue"}, 119 {201, C<&IHidServer::SendVibrationValue>, "SendVibrationValue"},
178 {202, &IHidServer::GetActualVibrationValue, "GetActualVibrationValue"}, 120 {202, C<&IHidServer::GetActualVibrationValue>, "GetActualVibrationValue"},
179 {203, &IHidServer::CreateActiveVibrationDeviceList, "CreateActiveVibrationDeviceList"}, 121 {203, C<&IHidServer::CreateActiveVibrationDeviceList>, "CreateActiveVibrationDeviceList"},
180 {204, &IHidServer::PermitVibration, "PermitVibration"}, 122 {204, C<&IHidServer::PermitVibration>, "PermitVibration"},
181 {205, &IHidServer::IsVibrationPermitted, "IsVibrationPermitted"}, 123 {205, C<&IHidServer::IsVibrationPermitted>, "IsVibrationPermitted"},
182 {206, &IHidServer::SendVibrationValues, "SendVibrationValues"}, 124 {206, C<&IHidServer::SendVibrationValues>, "SendVibrationValues"},
183 {207, &IHidServer::SendVibrationGcErmCommand, "SendVibrationGcErmCommand"}, 125 {207, C<&IHidServer::SendVibrationGcErmCommand>, "SendVibrationGcErmCommand"},
184 {208, &IHidServer::GetActualVibrationGcErmCommand, "GetActualVibrationGcErmCommand"}, 126 {208, C<&IHidServer::GetActualVibrationGcErmCommand>, "GetActualVibrationGcErmCommand"},
185 {209, &IHidServer::BeginPermitVibrationSession, "BeginPermitVibrationSession"}, 127 {209, C<&IHidServer::BeginPermitVibrationSession>, "BeginPermitVibrationSession"},
186 {210, &IHidServer::EndPermitVibrationSession, "EndPermitVibrationSession"}, 128 {210, C<&IHidServer::EndPermitVibrationSession>, "EndPermitVibrationSession"},
187 {211, &IHidServer::IsVibrationDeviceMounted, "IsVibrationDeviceMounted"}, 129 {211, C<&IHidServer::IsVibrationDeviceMounted>, "IsVibrationDeviceMounted"},
188 {212, &IHidServer::SendVibrationValueInBool, "SendVibrationValueInBool"}, 130 {212, C<&IHidServer::SendVibrationValueInBool>, "SendVibrationValueInBool"},
189 {300, &IHidServer::ActivateConsoleSixAxisSensor, "ActivateConsoleSixAxisSensor"}, 131 {300, C<&IHidServer::ActivateConsoleSixAxisSensor>, "ActivateConsoleSixAxisSensor"},
190 {301, &IHidServer::StartConsoleSixAxisSensor, "StartConsoleSixAxisSensor"}, 132 {301, C<&IHidServer::StartConsoleSixAxisSensor>, "StartConsoleSixAxisSensor"},
191 {302, &IHidServer::StopConsoleSixAxisSensor, "StopConsoleSixAxisSensor"}, 133 {302, C<&IHidServer::StopConsoleSixAxisSensor>, "StopConsoleSixAxisSensor"},
192 {303, &IHidServer::ActivateSevenSixAxisSensor, "ActivateSevenSixAxisSensor"}, 134 {303, C<&IHidServer::ActivateSevenSixAxisSensor>, "ActivateSevenSixAxisSensor"},
193 {304, &IHidServer::StartSevenSixAxisSensor, "StartSevenSixAxisSensor"}, 135 {304, C<&IHidServer::StartSevenSixAxisSensor>, "StartSevenSixAxisSensor"},
194 {305, &IHidServer::StopSevenSixAxisSensor, "StopSevenSixAxisSensor"}, 136 {305, C<&IHidServer::StopSevenSixAxisSensor>, "StopSevenSixAxisSensor"},
195 {306, &IHidServer::InitializeSevenSixAxisSensor, "InitializeSevenSixAxisSensor"}, 137 {306, C<&IHidServer::InitializeSevenSixAxisSensor>, "InitializeSevenSixAxisSensor"},
196 {307, &IHidServer::FinalizeSevenSixAxisSensor, "FinalizeSevenSixAxisSensor"}, 138 {307, C<&IHidServer::FinalizeSevenSixAxisSensor>, "FinalizeSevenSixAxisSensor"},
197 {308, nullptr, "SetSevenSixAxisSensorFusionStrength"}, 139 {308, nullptr, "SetSevenSixAxisSensorFusionStrength"},
198 {309, nullptr, "GetSevenSixAxisSensorFusionStrength"}, 140 {309, nullptr, "GetSevenSixAxisSensorFusionStrength"},
199 {310, &IHidServer::ResetSevenSixAxisSensorTimestamp, "ResetSevenSixAxisSensorTimestamp"}, 141 {310, C<&IHidServer::ResetSevenSixAxisSensorTimestamp>, "ResetSevenSixAxisSensorTimestamp"},
200 {400, &IHidServer::IsUsbFullKeyControllerEnabled, "IsUsbFullKeyControllerEnabled"}, 142 {400, C<&IHidServer::IsUsbFullKeyControllerEnabled>, "IsUsbFullKeyControllerEnabled"},
201 {401, nullptr, "EnableUsbFullKeyController"}, 143 {401, nullptr, "EnableUsbFullKeyController"},
202 {402, nullptr, "IsUsbFullKeyControllerConnected"}, 144 {402, nullptr, "IsUsbFullKeyControllerConnected"},
203 {403, nullptr, "HasBattery"}, 145 {403, nullptr, "HasBattery"},
@@ -206,41 +148,41 @@ IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> r
206 {406, nullptr, "GetNpadLeftRightInterfaceType"}, 148 {406, nullptr, "GetNpadLeftRightInterfaceType"},
207 {407, nullptr, "GetNpadOfHighestBatteryLevel"}, 149 {407, nullptr, "GetNpadOfHighestBatteryLevel"},
208 {408, nullptr, "GetNpadOfHighestBatteryLevelForJoyRight"}, 150 {408, nullptr, "GetNpadOfHighestBatteryLevelForJoyRight"},
209 {500, &IHidServer::GetPalmaConnectionHandle, "GetPalmaConnectionHandle"}, 151 {500, C<&IHidServer::GetPalmaConnectionHandle>, "GetPalmaConnectionHandle"},
210 {501, &IHidServer::InitializePalma, "InitializePalma"}, 152 {501, C<&IHidServer::InitializePalma>, "InitializePalma"},
211 {502, &IHidServer::AcquirePalmaOperationCompleteEvent, "AcquirePalmaOperationCompleteEvent"}, 153 {502, C<&IHidServer::AcquirePalmaOperationCompleteEvent>, "AcquirePalmaOperationCompleteEvent"},
212 {503, &IHidServer::GetPalmaOperationInfo, "GetPalmaOperationInfo"}, 154 {503, C<&IHidServer::GetPalmaOperationInfo>, "GetPalmaOperationInfo"},
213 {504, &IHidServer::PlayPalmaActivity, "PlayPalmaActivity"}, 155 {504, C<&IHidServer::PlayPalmaActivity>, "PlayPalmaActivity"},
214 {505, &IHidServer::SetPalmaFrModeType, "SetPalmaFrModeType"}, 156 {505, C<&IHidServer::SetPalmaFrModeType>, "SetPalmaFrModeType"},
215 {506, &IHidServer::ReadPalmaStep, "ReadPalmaStep"}, 157 {506, C<&IHidServer::ReadPalmaStep>, "ReadPalmaStep"},
216 {507, &IHidServer::EnablePalmaStep, "EnablePalmaStep"}, 158 {507, C<&IHidServer::EnablePalmaStep>, "EnablePalmaStep"},
217 {508, &IHidServer::ResetPalmaStep, "ResetPalmaStep"}, 159 {508, C<&IHidServer::ResetPalmaStep>, "ResetPalmaStep"},
218 {509, &IHidServer::ReadPalmaApplicationSection, "ReadPalmaApplicationSection"}, 160 {509, C<&IHidServer::ReadPalmaApplicationSection>, "ReadPalmaApplicationSection"},
219 {510, &IHidServer::WritePalmaApplicationSection, "WritePalmaApplicationSection"}, 161 {510, C<&IHidServer::WritePalmaApplicationSection>, "WritePalmaApplicationSection"},
220 {511, &IHidServer::ReadPalmaUniqueCode, "ReadPalmaUniqueCode"}, 162 {511, C<&IHidServer::ReadPalmaUniqueCode>, "ReadPalmaUniqueCode"},
221 {512, &IHidServer::SetPalmaUniqueCodeInvalid, "SetPalmaUniqueCodeInvalid"}, 163 {512, C<&IHidServer::SetPalmaUniqueCodeInvalid>, "SetPalmaUniqueCodeInvalid"},
222 {513, &IHidServer::WritePalmaActivityEntry, "WritePalmaActivityEntry"}, 164 {513, C<&IHidServer::WritePalmaActivityEntry>, "WritePalmaActivityEntry"},
223 {514, &IHidServer::WritePalmaRgbLedPatternEntry, "WritePalmaRgbLedPatternEntry"}, 165 {514, C<&IHidServer::WritePalmaRgbLedPatternEntry>, "WritePalmaRgbLedPatternEntry"},
224 {515, &IHidServer::WritePalmaWaveEntry, "WritePalmaWaveEntry"}, 166 {515, C<&IHidServer::WritePalmaWaveEntry>, "WritePalmaWaveEntry"},
225 {516, &IHidServer::SetPalmaDataBaseIdentificationVersion, "SetPalmaDataBaseIdentificationVersion"}, 167 {516, C<&IHidServer::SetPalmaDataBaseIdentificationVersion>, "SetPalmaDataBaseIdentificationVersion"},
226 {517, &IHidServer::GetPalmaDataBaseIdentificationVersion, "GetPalmaDataBaseIdentificationVersion"}, 168 {517, C<&IHidServer::GetPalmaDataBaseIdentificationVersion>, "GetPalmaDataBaseIdentificationVersion"},
227 {518, &IHidServer::SuspendPalmaFeature, "SuspendPalmaFeature"}, 169 {518, C<&IHidServer::SuspendPalmaFeature>, "SuspendPalmaFeature"},
228 {519, &IHidServer::GetPalmaOperationResult, "GetPalmaOperationResult"}, 170 {519, C<&IHidServer::GetPalmaOperationResult>, "GetPalmaOperationResult"},
229 {520, &IHidServer::ReadPalmaPlayLog, "ReadPalmaPlayLog"}, 171 {520, C<&IHidServer::ReadPalmaPlayLog>, "ReadPalmaPlayLog"},
230 {521, &IHidServer::ResetPalmaPlayLog, "ResetPalmaPlayLog"}, 172 {521, C<&IHidServer::ResetPalmaPlayLog>, "ResetPalmaPlayLog"},
231 {522, &IHidServer::SetIsPalmaAllConnectable, "SetIsPalmaAllConnectable"}, 173 {522, C<&IHidServer::SetIsPalmaAllConnectable>, "SetIsPalmaAllConnectable"},
232 {523, &IHidServer::SetIsPalmaPairedConnectable, "SetIsPalmaPairedConnectable"}, 174 {523, C<&IHidServer::SetIsPalmaPairedConnectable>, "SetIsPalmaPairedConnectable"},
233 {524, &IHidServer::PairPalma, "PairPalma"}, 175 {524, C<&IHidServer::PairPalma>, "PairPalma"},
234 {525, &IHidServer::SetPalmaBoostMode, "SetPalmaBoostMode"}, 176 {525, C<&IHidServer::SetPalmaBoostMode>, "SetPalmaBoostMode"},
235 {526, &IHidServer::CancelWritePalmaWaveEntry, "CancelWritePalmaWaveEntry"}, 177 {526, C<&IHidServer::CancelWritePalmaWaveEntry>, "CancelWritePalmaWaveEntry"},
236 {527, &IHidServer::EnablePalmaBoostMode, "EnablePalmaBoostMode"}, 178 {527, C<&IHidServer::EnablePalmaBoostMode>, "EnablePalmaBoostMode"},
237 {528, &IHidServer::GetPalmaBluetoothAddress, "GetPalmaBluetoothAddress"}, 179 {528, C<&IHidServer::GetPalmaBluetoothAddress>, "GetPalmaBluetoothAddress"},
238 {529, &IHidServer::SetDisallowedPalmaConnection, "SetDisallowedPalmaConnection"}, 180 {529, C<&IHidServer::SetDisallowedPalmaConnection>, "SetDisallowedPalmaConnection"},
239 {1000, &IHidServer::SetNpadCommunicationMode, "SetNpadCommunicationMode"}, 181 {1000, C<&IHidServer::SetNpadCommunicationMode>, "SetNpadCommunicationMode"},
240 {1001, &IHidServer::GetNpadCommunicationMode, "GetNpadCommunicationMode"}, 182 {1001, C<&IHidServer::GetNpadCommunicationMode>, "GetNpadCommunicationMode"},
241 {1002, &IHidServer::SetTouchScreenConfiguration, "SetTouchScreenConfiguration"}, 183 {1002, C<&IHidServer::SetTouchScreenConfiguration>, "SetTouchScreenConfiguration"},
242 {1003, &IHidServer::IsFirmwareUpdateNeededForNotification, "IsFirmwareUpdateNeededForNotification"}, 184 {1003, C<&IHidServer::IsFirmwareUpdateNeededForNotification>, "IsFirmwareUpdateNeededForNotification"},
243 {1004, &IHidServer::SetTouchScreenResolution, "SetTouchScreenResolution"}, 185 {1004, C<&IHidServer::SetTouchScreenResolution>, "SetTouchScreenResolution"},
244 {2000, nullptr, "ActivateDigitizer"}, 186 {2000, nullptr, "ActivateDigitizer"},
245 }; 187 };
246 // clang-format on 188 // clang-format on
@@ -250,890 +192,455 @@ IHidServer::IHidServer(Core::System& system_, std::shared_ptr<ResourceManager> r
250 192
251IHidServer::~IHidServer() = default; 193IHidServer::~IHidServer() = default;
252 194
253void IHidServer::CreateAppletResource(HLERequestContext& ctx) { 195Result IHidServer::CreateAppletResource(OutInterface<IAppletResource> out_applet_resource,
254 IPC::RequestParser rp{ctx}; 196 ClientAppletResourceUserId aruid) {
255 const auto applet_resource_user_id{rp.Pop<u64>()}; 197 const auto result = GetResourceManager()->CreateAppletResource(aruid.pid);
256
257 Result result = GetResourceManager()->CreateAppletResource(applet_resource_user_id);
258 198
259 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", 199 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, result=0x{:X}", aruid.pid,
260 applet_resource_user_id, result.raw); 200 result.raw);
261 201
262 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 202 *out_applet_resource = std::make_shared<IAppletResource>(system, resource_manager, aruid.pid);
263 rb.Push(result); 203 R_SUCCEED();
264 rb.PushIpcInterface<IAppletResource>(system, resource_manager, applet_resource_user_id);
265} 204}
266 205
267void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { 206Result IHidServer::ActivateDebugPad(ClientAppletResourceUserId aruid) {
268 IPC::RequestParser rp{ctx}; 207 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
269 const auto applet_resource_user_id{rp.Pop<u64>()};
270
271 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
272
273 Result result = ResultSuccess;
274 auto debug_pad = GetResourceManager()->GetDebugPad();
275 208
276 if (!firmware_settings->IsDeviceManaged()) { 209 if (!firmware_settings->IsDeviceManaged()) {
277 result = debug_pad->Activate(); 210 R_TRY(GetResourceManager()->GetDebugPad()->Activate());
278 }
279
280 if (result.IsSuccess()) {
281 result = debug_pad->Activate(applet_resource_user_id);
282 } 211 }
283 212
284 IPC::ResponseBuilder rb{ctx, 2}; 213 R_RETURN(GetResourceManager()->GetDebugPad()->Activate(aruid.pid));
285 rb.Push(result);
286} 214}
287 215
288void IHidServer::ActivateTouchScreen(HLERequestContext& ctx) { 216Result IHidServer::ActivateTouchScreen(ClientAppletResourceUserId aruid) {
289 IPC::RequestParser rp{ctx}; 217 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
290 const auto applet_resource_user_id{rp.Pop<u64>()};
291
292 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
293
294 Result result = ResultSuccess;
295 auto touch_screen = GetResourceManager()->GetTouchScreen();
296 218
297 if (!firmware_settings->IsDeviceManaged()) { 219 if (!firmware_settings->IsDeviceManaged()) {
298 result = touch_screen->Activate(); 220 R_TRY(GetResourceManager()->GetTouchScreen()->Activate());
299 }
300
301 if (result.IsSuccess()) {
302 result = touch_screen->Activate(applet_resource_user_id);
303 } 221 }
304 222
305 IPC::ResponseBuilder rb{ctx, 2}; 223 R_RETURN(GetResourceManager()->GetTouchScreen()->Activate(aruid.pid));
306 rb.Push(result);
307} 224}
308 225
309void IHidServer::ActivateMouse(HLERequestContext& ctx) { 226Result IHidServer::ActivateMouse(ClientAppletResourceUserId aruid) {
310 IPC::RequestParser rp{ctx}; 227 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
311 const auto applet_resource_user_id{rp.Pop<u64>()};
312
313 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
314
315 Result result = ResultSuccess;
316 auto mouse = GetResourceManager()->GetMouse();
317 228
318 if (!firmware_settings->IsDeviceManaged()) { 229 if (!firmware_settings->IsDeviceManaged()) {
319 result = mouse->Activate(); 230 R_TRY(GetResourceManager()->GetMouse()->Activate());
320 }
321
322 if (result.IsSuccess()) {
323 result = mouse->Activate(applet_resource_user_id);
324 } 231 }
325 232
326 IPC::ResponseBuilder rb{ctx, 2}; 233 R_RETURN(GetResourceManager()->GetMouse()->Activate(aruid.pid));
327 rb.Push(result);
328} 234}
329 235
330void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { 236Result IHidServer::ActivateKeyboard(ClientAppletResourceUserId aruid) {
331 IPC::RequestParser rp{ctx}; 237 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
332 const auto applet_resource_user_id{rp.Pop<u64>()};
333
334 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
335
336 Result result = ResultSuccess;
337 auto keyboard = GetResourceManager()->GetKeyboard();
338 238
339 if (!firmware_settings->IsDeviceManaged()) { 239 if (!firmware_settings->IsDeviceManaged()) {
340 result = keyboard->Activate(); 240 R_TRY(GetResourceManager()->GetKeyboard()->Activate());
341 } 241 }
342 242
343 if (result.IsSuccess()) { 243 R_RETURN(GetResourceManager()->GetKeyboard()->Activate(aruid.pid));
344 result = keyboard->Activate(applet_resource_user_id);
345 }
346
347 IPC::ResponseBuilder rb{ctx, 2};
348 rb.Push(result);
349} 244}
350 245
351void IHidServer::SendKeyboardLockKeyEvent(HLERequestContext& ctx) { 246Result IHidServer::SendKeyboardLockKeyEvent(u32 flags) {
352 IPC::RequestParser rp{ctx};
353 const auto flags{rp.Pop<u32>()};
354
355 LOG_WARNING(Service_HID, "(STUBBED) called. flags={}", flags); 247 LOG_WARNING(Service_HID, "(STUBBED) called. flags={}", flags);
356 248 R_SUCCEED();
357 IPC::ResponseBuilder rb{ctx, 2};
358 rb.Push(ResultSuccess);
359} 249}
360 250
361void IHidServer::AcquireXpadIdEventHandle(HLERequestContext& ctx) { 251Result IHidServer::AcquireXpadIdEventHandle(OutCopyHandle<Kernel::KReadableEvent> out_event,
362 IPC::RequestParser rp{ctx}; 252 ClientAppletResourceUserId aruid) {
363 const auto applet_resource_user_id{rp.Pop<u64>()}; 253 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
364
365 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
366 254
367 // This function has been stubbed since 10.0.0+ 255 // This function has been stubbed since 10.0.0+
368 256 *out_event = nullptr;
369 IPC::ResponseBuilder rb{ctx, 2, 1}; 257 R_SUCCEED();
370 rb.Push(ResultSuccess);
371 // Handle returned is null here
372} 258}
373 259
374void IHidServer::ReleaseXpadIdEventHandle(HLERequestContext& ctx) { 260Result IHidServer::ReleaseXpadIdEventHandle(ClientAppletResourceUserId aruid) {
375 IPC::RequestParser rp{ctx}; 261 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
376 const auto applet_resource_user_id{rp.Pop<u64>()};
377
378 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
379 262
380 // This function has been stubbed since 10.0.0+ 263 // This function has been stubbed since 10.0.0+
381 264 R_SUCCEED();
382 IPC::ResponseBuilder rb{ctx, 2};
383 rb.Push(ResultSuccess);
384} 265}
385 266
386void IHidServer::ActivateXpad(HLERequestContext& ctx) { 267Result IHidServer::ActivateXpad(u32 basic_xpad_id, ClientAppletResourceUserId aruid) {
387 IPC::RequestParser rp{ctx}; 268 LOG_DEBUG(Service_HID, "called, basic_xpad_id={}, applet_resource_user_id={}", basic_xpad_id,
388 struct Parameters { 269 aruid.pid);
389 u32 basic_xpad_id;
390 INSERT_PADDING_WORDS_NOINIT(1);
391 u64 applet_resource_user_id;
392 };
393 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
394
395 const auto parameters{rp.PopRaw<Parameters>()};
396
397 LOG_DEBUG(Service_HID, "called, basic_xpad_id={}, applet_resource_user_id={}",
398 parameters.basic_xpad_id, parameters.applet_resource_user_id);
399 270
400 // This function has been stubbed since 10.0.0+ 271 // This function has been stubbed since 10.0.0+
401 272 R_SUCCEED();
402 IPC::ResponseBuilder rb{ctx, 2};
403 rb.Push(ResultSuccess);
404} 273}
405 274
406void IHidServer::GetXpadIds(HLERequestContext& ctx) { 275Result IHidServer::GetXpadIds(Out<u64> out_count,
276 OutArray<u32, BufferAttr_HipcPointer> out_basic_pad_ids) {
407 LOG_DEBUG(Service_HID, "called"); 277 LOG_DEBUG(Service_HID, "called");
408 278
409 // This function has been hardcoded since 10.0.0+ 279 // This function has been hardcoded since 10.0.0+
410 const std::array<u32, 4> basic_xpad_id{0, 1, 2, 3}; 280 out_basic_pad_ids[0] = 0;
411 ctx.WriteBuffer(basic_xpad_id); 281 out_basic_pad_ids[1] = 1;
412 282 out_basic_pad_ids[2] = 2;
413 IPC::ResponseBuilder rb{ctx, 4}; 283 out_basic_pad_ids[3] = 3;
414 rb.Push(ResultSuccess); 284 *out_count = 4;
415 rb.Push<s64>(basic_xpad_id.size()); 285 R_SUCCEED();
416} 286}
417 287
418void IHidServer::ActivateJoyXpad(HLERequestContext& ctx) { 288Result IHidServer::ActivateJoyXpad(u32 joy_xpad_id) {
419 IPC::RequestParser rp{ctx};
420 const auto joy_xpad_id{rp.Pop<u32>()};
421
422 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 289 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
423 290
424 // This function has been stubbed since 10.0.0+ 291 // This function has been stubbed since 10.0.0+
425 292 R_SUCCEED();
426 IPC::ResponseBuilder rb{ctx, 2};
427 rb.Push(ResultSuccess);
428} 293}
429 294
430void IHidServer::GetJoyXpadLifoHandle(HLERequestContext& ctx) { 295Result IHidServer::GetJoyXpadLifoHandle(
431 IPC::RequestParser rp{ctx}; 296 OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle, u32 joy_xpad_id) {
432 const auto joy_xpad_id{rp.Pop<u32>()};
433
434 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 297 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
435 298
436 // This function has been stubbed since 10.0.0+ 299 // This function has been stubbed since 10.0.0+
437 300 *out_shared_memory_handle = nullptr;
438 IPC::ResponseBuilder rb{ctx, 2, 1}; 301 R_SUCCEED();
439 rb.Push(ResultSuccess);
440 // Handle returned is null here
441} 302}
442 303
443void IHidServer::GetJoyXpadIds(HLERequestContext& ctx) { 304Result IHidServer::GetJoyXpadIds(Out<s64> out_basic_xpad_id_count) {
444 LOG_DEBUG(Service_HID, "called"); 305 LOG_DEBUG(Service_HID, "called");
445 306
446 // This function has been hardcoded since 10.0.0+ 307 // This function has been hardcoded since 10.0.0+
447 const s64 basic_xpad_id_count{}; 308 *out_basic_xpad_id_count = 0;
448 309 R_SUCCEED();
449 IPC::ResponseBuilder rb{ctx, 4};
450 rb.Push(ResultSuccess);
451 rb.Push(basic_xpad_id_count);
452} 310}
453 311
454void IHidServer::ActivateSixAxisSensor(HLERequestContext& ctx) { 312Result IHidServer::ActivateSixAxisSensor(u32 joy_xpad_id) {
455 IPC::RequestParser rp{ctx};
456 const auto joy_xpad_id{rp.Pop<u32>()};
457
458 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 313 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
459 314
460 // This function has been stubbed since 10.0.0+ 315 // This function has been stubbed since 10.0.0+
461 316 R_SUCCEED();
462 IPC::ResponseBuilder rb{ctx, 2};
463 rb.Push(ResultSuccess);
464} 317}
465 318
466void IHidServer::DeactivateSixAxisSensor(HLERequestContext& ctx) { 319Result IHidServer::DeactivateSixAxisSensor(u32 joy_xpad_id) {
467 IPC::RequestParser rp{ctx};
468 const auto joy_xpad_id{rp.Pop<u32>()};
469
470 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 320 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
471 321
472 // This function has been stubbed since 10.0.0+ 322 // This function has been stubbed since 10.0.0+
473 323 R_SUCCEED();
474 IPC::ResponseBuilder rb{ctx, 2, 1};
475 rb.Push(ResultSuccess);
476} 324}
477 325
478void IHidServer::GetSixAxisSensorLifoHandle(HLERequestContext& ctx) { 326Result IHidServer::GetSixAxisSensorLifoHandle(
479 IPC::RequestParser rp{ctx}; 327 OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle, u32 joy_xpad_id) {
480 const auto joy_xpad_id{rp.Pop<u32>()};
481
482 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 328 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
483 329
484 // This function has been stubbed since 10.0.0+ 330 // This function has been stubbed since 10.0.0+
485 331 *out_shared_memory_handle = nullptr;
486 IPC::ResponseBuilder rb{ctx, 2}; 332 R_SUCCEED();
487 rb.Push(ResultSuccess);
488} 333}
489 334
490void IHidServer::ActivateJoySixAxisSensor(HLERequestContext& ctx) { 335Result IHidServer::ActivateJoySixAxisSensor(u32 joy_xpad_id) {
491 IPC::RequestParser rp{ctx};
492 const auto joy_xpad_id{rp.Pop<u32>()};
493
494 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 336 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
495 337
496 // This function has been stubbed since 10.0.0+ 338 // This function has been stubbed since 10.0.0+
497 339 R_SUCCEED();
498 IPC::ResponseBuilder rb{ctx, 2};
499 rb.Push(ResultSuccess);
500} 340}
501 341
502void IHidServer::DeactivateJoySixAxisSensor(HLERequestContext& ctx) { 342Result IHidServer::DeactivateJoySixAxisSensor(u32 joy_xpad_id) {
503 IPC::RequestParser rp{ctx};
504 const auto joy_xpad_id{rp.Pop<u32>()};
505
506 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 343 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
507 344
508 // This function has been stubbed since 10.0.0+ 345 // This function has been stubbed since 10.0.0+
509 346 R_SUCCEED();
510 IPC::ResponseBuilder rb{ctx, 2};
511 rb.Push(ResultSuccess);
512} 347}
513 348
514void IHidServer::GetJoySixAxisSensorLifoHandle(HLERequestContext& ctx) { 349Result IHidServer::GetJoySixAxisSensorLifoHandle(
515 IPC::RequestParser rp{ctx}; 350 OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle, u32 joy_xpad_id) {
516 const auto joy_xpad_id{rp.Pop<u32>()};
517
518 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id); 351 LOG_DEBUG(Service_HID, "called, joy_xpad_id={}", joy_xpad_id);
519 352
520 // This function has been stubbed since 10.0.0+ 353 // This function has been stubbed since 10.0.0+
521 354 *out_shared_memory_handle = nullptr;
522 IPC::ResponseBuilder rb{ctx, 2, 1}; 355 R_SUCCEED();
523 rb.Push(ResultSuccess);
524 // Handle returned is null here
525} 356}
526 357
527void IHidServer::StartSixAxisSensor(HLERequestContext& ctx) { 358Result IHidServer::StartSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle,
528 IPC::RequestParser rp{ctx}; 359 ClientAppletResourceUserId aruid) {
529 struct Parameters {
530 Core::HID::SixAxisSensorHandle sixaxis_handle;
531 INSERT_PADDING_WORDS_NOINIT(1);
532 u64 applet_resource_user_id;
533 };
534 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
535
536 const auto parameters{rp.PopRaw<Parameters>()};
537
538 auto six_axis = GetResourceManager()->GetSixAxis();
539 const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, true);
540
541 LOG_DEBUG(Service_HID, 360 LOG_DEBUG(Service_HID,
542 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 361 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
543 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 362 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
544 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 363 aruid.pid);
545 364
546 IPC::ResponseBuilder rb{ctx, 2}; 365 R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisEnabled(sixaxis_handle, true));
547 rb.Push(result);
548} 366}
549 367
550void IHidServer::StopSixAxisSensor(HLERequestContext& ctx) { 368Result IHidServer::StopSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle,
551 IPC::RequestParser rp{ctx}; 369 ClientAppletResourceUserId aruid) {
552 struct Parameters {
553 Core::HID::SixAxisSensorHandle sixaxis_handle;
554 INSERT_PADDING_WORDS_NOINIT(1);
555 u64 applet_resource_user_id;
556 };
557 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
558
559 const auto parameters{rp.PopRaw<Parameters>()};
560
561 auto six_axis = GetResourceManager()->GetSixAxis();
562 const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, false);
563
564 LOG_DEBUG(Service_HID, 370 LOG_DEBUG(Service_HID,
565 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 371 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
566 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 372 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
567 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 373 aruid.pid);
568 374
569 IPC::ResponseBuilder rb{ctx, 2}; 375 R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisEnabled(sixaxis_handle, false));
570 rb.Push(result);
571} 376}
572 377
573void IHidServer::IsSixAxisSensorFusionEnabled(HLERequestContext& ctx) { 378Result IHidServer::IsSixAxisSensorFusionEnabled(Out<bool> out_is_enabled,
574 IPC::RequestParser rp{ctx}; 379 Core::HID::SixAxisSensorHandle sixaxis_handle,
575 struct Parameters { 380 ClientAppletResourceUserId aruid) {
576 Core::HID::SixAxisSensorHandle sixaxis_handle;
577 INSERT_PADDING_WORDS_NOINIT(1);
578 u64 applet_resource_user_id;
579 };
580 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
581
582 const auto parameters{rp.PopRaw<Parameters>()};
583
584 bool is_enabled{};
585 auto six_axis = GetResourceManager()->GetSixAxis();
586 const auto result =
587 six_axis->IsSixAxisSensorFusionEnabled(parameters.sixaxis_handle, is_enabled);
588
589 LOG_DEBUG(Service_HID, 381 LOG_DEBUG(Service_HID,
590 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 382 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
591 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 383 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
592 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 384 aruid.pid);
593 385
594 IPC::ResponseBuilder rb{ctx, 3}; 386 R_RETURN(GetResourceManager()->GetSixAxis()->IsSixAxisSensorFusionEnabled(sixaxis_handle,
595 rb.Push(result); 387 *out_is_enabled));
596 rb.Push(is_enabled);
597} 388}
598 389
599void IHidServer::EnableSixAxisSensorFusion(HLERequestContext& ctx) { 390Result IHidServer::EnableSixAxisSensorFusion(bool is_enabled,
600 IPC::RequestParser rp{ctx}; 391 Core::HID::SixAxisSensorHandle sixaxis_handle,
601 struct Parameters { 392 ClientAppletResourceUserId aruid) {
602 bool enable_sixaxis_sensor_fusion;
603 INSERT_PADDING_BYTES_NOINIT(3);
604 Core::HID::SixAxisSensorHandle sixaxis_handle;
605 u64 applet_resource_user_id;
606 };
607 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
608
609 const auto parameters{rp.PopRaw<Parameters>()};
610
611 auto six_axis = GetResourceManager()->GetSixAxis();
612 const auto result = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle,
613 parameters.enable_sixaxis_sensor_fusion);
614
615 LOG_DEBUG(Service_HID, 393 LOG_DEBUG(Service_HID,
616 "called, enable_sixaxis_sensor_fusion={}, npad_type={}, npad_id={}, " 394 "called, is_enabled={}, npad_type={}, npad_id={}, "
617 "device_index={}, applet_resource_user_id={}", 395 "device_index={}, applet_resource_user_id={}",
618 parameters.enable_sixaxis_sensor_fusion, parameters.sixaxis_handle.npad_type, 396 is_enabled, sixaxis_handle.npad_type, sixaxis_handle.npad_id,
619 parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, 397 sixaxis_handle.device_index, aruid.pid);
620 parameters.applet_resource_user_id);
621 398
622 IPC::ResponseBuilder rb{ctx, 2}; 399 R_RETURN(
623 rb.Push(result); 400 GetResourceManager()->GetSixAxis()->SetSixAxisFusionEnabled(sixaxis_handle, is_enabled));
624} 401}
625 402
626void IHidServer::SetSixAxisSensorFusionParameters(HLERequestContext& ctx) { 403Result IHidServer::SetSixAxisSensorFusionParameters(
627 IPC::RequestParser rp{ctx}; 404 Core::HID::SixAxisSensorHandle sixaxis_handle,
628 struct Parameters { 405 Core::HID::SixAxisSensorFusionParameters sixaxis_fusion, ClientAppletResourceUserId aruid) {
629 Core::HID::SixAxisSensorHandle sixaxis_handle;
630 Core::HID::SixAxisSensorFusionParameters sixaxis_fusion;
631 INSERT_PADDING_WORDS_NOINIT(1);
632 u64 applet_resource_user_id;
633 };
634 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
635
636 const auto parameters{rp.PopRaw<Parameters>()};
637
638 auto six_axis = GetResourceManager()->GetSixAxis();
639 const auto result =
640 six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, parameters.sixaxis_fusion);
641
642 LOG_DEBUG(Service_HID, 406 LOG_DEBUG(Service_HID,
643 "called, npad_type={}, npad_id={}, device_index={}, parameter1={}, " 407 "called, npad_type={}, npad_id={}, device_index={}, parameter1={}, "
644 "parameter2={}, applet_resource_user_id={}", 408 "parameter2={}, applet_resource_user_id={}",
645 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 409 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
646 parameters.sixaxis_handle.device_index, parameters.sixaxis_fusion.parameter1, 410 sixaxis_fusion.parameter1, sixaxis_fusion.parameter2, aruid.pid);
647 parameters.sixaxis_fusion.parameter2, parameters.applet_resource_user_id);
648 411
649 IPC::ResponseBuilder rb{ctx, 2}; 412 R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisFusionParameters(sixaxis_handle,
650 rb.Push(result); 413 sixaxis_fusion));
651} 414}
652 415
653void IHidServer::GetSixAxisSensorFusionParameters(HLERequestContext& ctx) { 416Result IHidServer::GetSixAxisSensorFusionParameters(
654 IPC::RequestParser rp{ctx}; 417 Out<Core::HID::SixAxisSensorFusionParameters> out_fusion_parameters,
655 struct Parameters { 418 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) {
656 Core::HID::SixAxisSensorHandle sixaxis_handle;
657 INSERT_PADDING_WORDS_NOINIT(1);
658 u64 applet_resource_user_id;
659 };
660 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
661
662 const auto parameters{rp.PopRaw<Parameters>()};
663
664 Core::HID::SixAxisSensorFusionParameters fusion_parameters{};
665 auto six_axis = GetResourceManager()->GetSixAxis();
666 const auto result =
667 six_axis->GetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters);
668
669 LOG_DEBUG(Service_HID, 419 LOG_DEBUG(Service_HID,
670 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 420 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
671 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 421 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
672 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 422 aruid.pid);
673 423
674 IPC::ResponseBuilder rb{ctx, 4}; 424 R_RETURN(GetResourceManager()->GetSixAxis()->GetSixAxisFusionParameters(
675 rb.Push(result); 425 sixaxis_handle, *out_fusion_parameters));
676 rb.PushRaw(fusion_parameters);
677} 426}
678 427
679void IHidServer::ResetSixAxisSensorFusionParameters(HLERequestContext& ctx) { 428Result IHidServer::ResetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle,
680 IPC::RequestParser rp{ctx}; 429 ClientAppletResourceUserId aruid) {
681 struct Parameters { 430 LOG_DEBUG(Service_HID,
682 Core::HID::SixAxisSensorHandle sixaxis_handle; 431 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
683 INSERT_PADDING_WORDS_NOINIT(1); 432 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
684 u64 applet_resource_user_id; 433 aruid.pid);
685 };
686 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
687
688 const auto parameters{rp.PopRaw<Parameters>()};
689 434
690 // Since these parameters are unknown just use what HW outputs 435 // Since these parameters are unknown just use what HW outputs
691 const Core::HID::SixAxisSensorFusionParameters fusion_parameters{ 436 const Core::HID::SixAxisSensorFusionParameters fusion_parameters{
692 .parameter1 = 0.03f, 437 .parameter1 = 0.03f,
693 .parameter2 = 0.4f, 438 .parameter2 = 0.4f,
694 }; 439 };
695 auto six_axis = GetResourceManager()->GetSixAxis();
696 const auto result1 =
697 six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters);
698 const auto result2 = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle, true);
699 440
700 LOG_DEBUG(Service_HID, 441 R_TRY(GetResourceManager()->GetSixAxis()->SetSixAxisFusionParameters(sixaxis_handle,
701 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 442 fusion_parameters));
702 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 443 R_RETURN(GetResourceManager()->GetSixAxis()->SetSixAxisFusionEnabled(sixaxis_handle, true));
703 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
704
705 IPC::ResponseBuilder rb{ctx, 2};
706 if (result1.IsError()) {
707 rb.Push(result1);
708 return;
709 }
710 rb.Push(result2);
711} 444}
712 445
713void IHidServer::SetGyroscopeZeroDriftMode(HLERequestContext& ctx) { 446Result IHidServer::SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
714 IPC::RequestParser rp{ctx}; 447 Core::HID::GyroscopeZeroDriftMode drift_mode,
715 const auto sixaxis_handle{rp.PopRaw<Core::HID::SixAxisSensorHandle>()}; 448 ClientAppletResourceUserId aruid) {
716 const auto drift_mode{rp.PopEnum<Core::HID::GyroscopeZeroDriftMode>()};
717 const auto applet_resource_user_id{rp.Pop<u64>()};
718
719 auto six_axis = GetResourceManager()->GetSixAxis();
720 const auto result = six_axis->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode);
721
722 LOG_DEBUG(Service_HID, 449 LOG_DEBUG(Service_HID,
723 "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, " 450 "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, "
724 "applet_resource_user_id={}", 451 "applet_resource_user_id={}",
725 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, 452 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
726 drift_mode, applet_resource_user_id); 453 drift_mode, aruid.pid);
727 454
728 IPC::ResponseBuilder rb{ctx, 2}; 455 R_RETURN(
729 rb.Push(result); 456 GetResourceManager()->GetSixAxis()->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode));
730} 457}
731 458
732void IHidServer::GetGyroscopeZeroDriftMode(HLERequestContext& ctx) { 459Result IHidServer::GetGyroscopeZeroDriftMode(Out<Core::HID::GyroscopeZeroDriftMode> out_drift_mode,
733 IPC::RequestParser rp{ctx}; 460 Core::HID::SixAxisSensorHandle sixaxis_handle,
734 struct Parameters { 461 ClientAppletResourceUserId aruid) {
735 Core::HID::SixAxisSensorHandle sixaxis_handle;
736 INSERT_PADDING_WORDS_NOINIT(1);
737 u64 applet_resource_user_id;
738 };
739 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
740
741 const auto parameters{rp.PopRaw<Parameters>()};
742
743 auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard};
744 auto six_axis = GetResourceManager()->GetSixAxis();
745 const auto result = six_axis->GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode);
746
747 LOG_DEBUG(Service_HID, 462 LOG_DEBUG(Service_HID,
748 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 463 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
749 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 464 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
750 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 465 aruid.pid);
751 466
752 IPC::ResponseBuilder rb{ctx, 3}; 467 R_RETURN(GetResourceManager()->GetSixAxis()->GetGyroscopeZeroDriftMode(sixaxis_handle,
753 rb.Push(result); 468 *out_drift_mode));
754 rb.PushEnum(drift_mode);
755} 469}
756 470
757void IHidServer::ResetGyroscopeZeroDriftMode(HLERequestContext& ctx) { 471Result IHidServer::ResetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
758 IPC::RequestParser rp{ctx}; 472 ClientAppletResourceUserId aruid) {
759 struct Parameters {
760 Core::HID::SixAxisSensorHandle sixaxis_handle;
761 INSERT_PADDING_WORDS_NOINIT(1);
762 u64 applet_resource_user_id;
763 };
764 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
765
766 const auto parameters{rp.PopRaw<Parameters>()};
767
768 const auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard};
769 auto six_axis = GetResourceManager()->GetSixAxis();
770 const auto result = six_axis->SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode);
771
772 LOG_DEBUG(Service_HID, 473 LOG_DEBUG(Service_HID,
773 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 474 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
774 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 475 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
775 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 476 aruid.pid);
776 477
777 IPC::ResponseBuilder rb{ctx, 2}; 478 const auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard};
778 rb.Push(result); 479 R_RETURN(
480 GetResourceManager()->GetSixAxis()->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode));
779} 481}
780 482
781void IHidServer::IsSixAxisSensorAtRest(HLERequestContext& ctx) { 483Result IHidServer::IsSixAxisSensorAtRest(Out<bool> out_is_at_rest,
782 IPC::RequestParser rp{ctx}; 484 Core::HID::SixAxisSensorHandle sixaxis_handle,
783 struct Parameters { 485 ClientAppletResourceUserId aruid) {
784 Core::HID::SixAxisSensorHandle sixaxis_handle;
785 INSERT_PADDING_WORDS_NOINIT(1);
786 u64 applet_resource_user_id;
787 };
788 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
789
790 const auto parameters{rp.PopRaw<Parameters>()};
791
792 bool is_at_rest{};
793 auto six_axis = GetResourceManager()->GetSixAxis();
794 six_axis->IsSixAxisSensorAtRest(parameters.sixaxis_handle, is_at_rest);
795
796 LOG_DEBUG(Service_HID, 486 LOG_DEBUG(Service_HID,
797 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 487 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
798 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 488 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index,
799 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); 489 aruid.pid);
800 490
801 IPC::ResponseBuilder rb{ctx, 3}; 491 R_RETURN(
802 rb.Push(ResultSuccess); 492 GetResourceManager()->GetSixAxis()->IsSixAxisSensorAtRest(sixaxis_handle, *out_is_at_rest));
803 rb.Push(is_at_rest);
804} 493}
805 494
806void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx) { 495Result IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(
807 IPC::RequestParser rp{ctx}; 496 Out<bool> out_is_firmware_available, Core::HID::SixAxisSensorHandle sixaxis_handle,
808 struct Parameters { 497 ClientAppletResourceUserId aruid) {
809 Core::HID::SixAxisSensorHandle sixaxis_handle;
810 INSERT_PADDING_WORDS_NOINIT(1);
811 u64 applet_resource_user_id;
812 };
813 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
814
815 const auto parameters{rp.PopRaw<Parameters>()};
816
817 bool is_firmware_available{};
818 auto controller = GetResourceManager()->GetNpad();
819 controller->IsFirmwareUpdateAvailableForSixAxisSensor(
820 parameters.applet_resource_user_id, parameters.sixaxis_handle, is_firmware_available);
821
822 LOG_WARNING( 498 LOG_WARNING(
823 Service_HID, 499 Service_HID,
824 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 500 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
825 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 501 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid);
826 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
827 502
828 IPC::ResponseBuilder rb{ctx, 3}; 503 R_RETURN(GetResourceManager()->GetNpad()->IsFirmwareUpdateAvailableForSixAxisSensor(
829 rb.Push(ResultSuccess); 504 aruid.pid, sixaxis_handle, *out_is_firmware_available));
830 rb.Push(is_firmware_available);
831} 505}
832 506
833void IHidServer::EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx) { 507Result IHidServer::EnableSixAxisSensorUnalteredPassthrough(
834 IPC::RequestParser rp{ctx}; 508 bool is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle,
835 struct Parameters { 509 ClientAppletResourceUserId aruid) {
836 bool enabled;
837 Core::HID::SixAxisSensorHandle sixaxis_handle;
838 u64 applet_resource_user_id;
839 };
840 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
841
842 const auto parameters{rp.PopRaw<Parameters>()};
843
844 auto six_axis = GetResourceManager()->GetSixAxis();
845 const auto result = six_axis->EnableSixAxisSensorUnalteredPassthrough(parameters.sixaxis_handle,
846 parameters.enabled);
847
848 LOG_DEBUG(Service_HID, 510 LOG_DEBUG(Service_HID,
849 "(STUBBED) called, enabled={}, npad_type={}, npad_id={}, device_index={}, " 511 "(STUBBED) called, enabled={}, npad_type={}, npad_id={}, device_index={}, "
850 "applet_resource_user_id={}", 512 "applet_resource_user_id={}",
851 parameters.enabled, parameters.sixaxis_handle.npad_type, 513 is_enabled, sixaxis_handle.npad_type, sixaxis_handle.npad_id,
852 parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, 514 sixaxis_handle.device_index, aruid.pid);
853 parameters.applet_resource_user_id);
854 515
855 IPC::ResponseBuilder rb{ctx, 2}; 516 R_RETURN(GetResourceManager()->GetSixAxis()->EnableSixAxisSensorUnalteredPassthrough(
856 rb.Push(result); 517 sixaxis_handle, is_enabled));
857} 518}
858 519
859void IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx) { 520Result IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled(
860 IPC::RequestParser rp{ctx}; 521 Out<bool> out_is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle,
861 struct Parameters { 522 ClientAppletResourceUserId aruid) {
862 Core::HID::SixAxisSensorHandle sixaxis_handle;
863 INSERT_PADDING_WORDS_NOINIT(1);
864 u64 applet_resource_user_id;
865 };
866 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
867
868 const auto parameters{rp.PopRaw<Parameters>()};
869
870 bool is_unaltered_sisxaxis_enabled{};
871 auto six_axis = GetResourceManager()->GetSixAxis();
872 const auto result = six_axis->IsSixAxisSensorUnalteredPassthroughEnabled(
873 parameters.sixaxis_handle, is_unaltered_sisxaxis_enabled);
874
875 LOG_DEBUG( 523 LOG_DEBUG(
876 Service_HID, 524 Service_HID,
877 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 525 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
878 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 526 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid);
879 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
880 527
881 IPC::ResponseBuilder rb{ctx, 3}; 528 R_RETURN(GetResourceManager()->GetSixAxis()->IsSixAxisSensorUnalteredPassthroughEnabled(
882 rb.Push(result); 529 sixaxis_handle, *out_is_enabled));
883 rb.Push(is_unaltered_sisxaxis_enabled);
884} 530}
885 531
886void IHidServer::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { 532Result IHidServer::LoadSixAxisSensorCalibrationParameter(
887 IPC::RequestParser rp{ctx}; 533 OutLargeData<Core::HID::SixAxisSensorCalibrationParameter, BufferAttr_HipcMapAlias>
888 struct Parameters { 534 out_calibration,
889 Core::HID::SixAxisSensorHandle sixaxis_handle; 535 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) {
890 INSERT_PADDING_WORDS_NOINIT(1);
891 u64 applet_resource_user_id;
892 };
893 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
894
895 const auto parameters{rp.PopRaw<Parameters>()};
896
897 Core::HID::SixAxisSensorCalibrationParameter calibration{};
898 auto six_axis = GetResourceManager()->GetSixAxis();
899 const auto result =
900 six_axis->LoadSixAxisSensorCalibrationParameter(parameters.sixaxis_handle, calibration);
901
902 LOG_WARNING( 536 LOG_WARNING(
903 Service_HID, 537 Service_HID,
904 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 538 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
905 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 539 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid);
906 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
907
908 if (result.IsSuccess()) {
909 ctx.WriteBuffer(calibration);
910 }
911 540
912 IPC::ResponseBuilder rb{ctx, 2}; 541 R_RETURN(GetResourceManager()->GetSixAxis()->LoadSixAxisSensorCalibrationParameter(
913 rb.Push(result); 542 sixaxis_handle, *out_calibration));
914} 543}
915 544
916void IHidServer::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { 545Result IHidServer::GetSixAxisSensorIcInformation(
917 IPC::RequestParser rp{ctx}; 546 OutLargeData<Core::HID::SixAxisSensorIcInformation, BufferAttr_HipcPointer> out_ic_information,
918 struct Parameters { 547 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) {
919 Core::HID::SixAxisSensorHandle sixaxis_handle;
920 INSERT_PADDING_WORDS_NOINIT(1);
921 u64 applet_resource_user_id;
922 };
923 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
924
925 const auto parameters{rp.PopRaw<Parameters>()};
926
927 Core::HID::SixAxisSensorIcInformation ic_information{};
928 auto six_axis = GetResourceManager()->GetSixAxis();
929 const auto result =
930 six_axis->GetSixAxisSensorIcInformation(parameters.sixaxis_handle, ic_information);
931
932 LOG_WARNING( 548 LOG_WARNING(
933 Service_HID, 549 Service_HID,
934 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 550 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
935 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 551 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid);
936 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
937 552
938 if (result.IsSuccess()) { 553 R_RETURN(GetResourceManager()->GetSixAxis()->GetSixAxisSensorIcInformation(
939 ctx.WriteBuffer(ic_information); 554 sixaxis_handle, *out_ic_information));
940 }
941
942 IPC::ResponseBuilder rb{ctx, 2};
943 rb.Push(result);
944} 555}
945 556
946void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) { 557Result IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(
947 IPC::RequestParser rp{ctx}; 558 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid) {
948 struct Parameters {
949 Core::HID::SixAxisSensorHandle sixaxis_handle;
950 INSERT_PADDING_WORDS_NOINIT(1);
951 u64 applet_resource_user_id;
952 };
953 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
954
955 const auto parameters{rp.PopRaw<Parameters>()};
956
957 auto controller = GetResourceManager()->GetNpad();
958 const auto result = controller->ResetIsSixAxisSensorDeviceNewlyAssigned(
959 parameters.applet_resource_user_id, parameters.sixaxis_handle);
960
961 LOG_WARNING( 559 LOG_WARNING(
962 Service_HID, 560 Service_HID,
963 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 561 "(STUBBED) called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
964 parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, 562 sixaxis_handle.npad_type, sixaxis_handle.npad_id, sixaxis_handle.device_index, aruid.pid);
965 parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id);
966 563
967 IPC::ResponseBuilder rb{ctx, 2}; 564 R_RETURN(GetResourceManager()->GetNpad()->ResetIsSixAxisSensorDeviceNewlyAssigned(
968 rb.Push(result); 565 aruid.pid, sixaxis_handle));
969} 566}
970 567
971void IHidServer::ActivateGesture(HLERequestContext& ctx) { 568Result IHidServer::ActivateGesture(u32 basic_gesture_id, ClientAppletResourceUserId aruid) {
972 IPC::RequestParser rp{ctx};
973 struct Parameters {
974 u32 basic_gesture_id;
975 INSERT_PADDING_WORDS_NOINIT(1);
976 u64 applet_resource_user_id;
977 };
978 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
979
980 const auto parameters{rp.PopRaw<Parameters>()};
981
982 LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}", 569 LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}",
983 parameters.basic_gesture_id, parameters.applet_resource_user_id); 570 basic_gesture_id, aruid.pid);
984
985 Result result = ResultSuccess;
986 auto gesture = GetResourceManager()->GetGesture();
987 571
988 if (!firmware_settings->IsDeviceManaged()) { 572 if (!firmware_settings->IsDeviceManaged()) {
989 result = gesture->Activate(); 573 R_TRY(GetResourceManager()->GetGesture()->Activate());
990 }
991
992 if (result.IsSuccess()) {
993 result = gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id);
994 } 574 }
995 575
996 IPC::ResponseBuilder rb{ctx, 2}; 576 R_RETURN(GetResourceManager()->GetGesture()->Activate(aruid.pid, basic_gesture_id));
997 rb.Push(result);
998} 577}
999 578
1000void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) { 579Result IHidServer::SetSupportedNpadStyleSet(Core::HID::NpadStyleSet supported_style_set,
1001 IPC::RequestParser rp{ctx}; 580 ClientAppletResourceUserId aruid) {
1002 struct Parameters {
1003 Core::HID::NpadStyleSet supported_style_set;
1004 INSERT_PADDING_WORDS_NOINIT(1);
1005 u64 applet_resource_user_id;
1006 };
1007 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1008
1009 const auto parameters{rp.PopRaw<Parameters>()};
1010
1011 LOG_DEBUG(Service_HID, "called, supported_style_set={}, applet_resource_user_id={}", 581 LOG_DEBUG(Service_HID, "called, supported_style_set={}, applet_resource_user_id={}",
1012 parameters.supported_style_set, parameters.applet_resource_user_id); 582 supported_style_set, aruid.pid);
1013 583
1014 const auto npad = GetResourceManager()->GetNpad(); 584 R_TRY(
1015 const Result result = npad->SetSupportedNpadStyleSet(parameters.applet_resource_user_id, 585 GetResourceManager()->GetNpad()->SetSupportedNpadStyleSet(aruid.pid, supported_style_set));
1016 parameters.supported_style_set);
1017 586
1018 if (result.IsSuccess()) { 587 Core::HID::NpadStyleTag style_tag{supported_style_set};
1019 Core::HID::NpadStyleTag style_tag{parameters.supported_style_set}; 588 const auto revision = GetResourceManager()->GetNpad()->GetRevision(aruid.pid);
1020 const auto revision = npad->GetRevision(parameters.applet_resource_user_id);
1021 589
1022 if (style_tag.palma != 0 && revision < NpadRevision::Revision3) { 590 if (style_tag.palma != 0 && revision < NpadRevision::Revision3) {
1023 // GetResourceManager()->GetPalma()->EnableBoostMode(parameters.applet_resource_user_id, 591 // GetResourceManager()->GetPalma()->EnableBoostMode(aruid.pid, true);
1024 // true);
1025 }
1026 } 592 }
1027 593
1028 IPC::ResponseBuilder rb{ctx, 2}; 594 R_SUCCEED()
1029 rb.Push(result);
1030} 595}
1031 596
1032void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) { 597Result IHidServer::GetSupportedNpadStyleSet(Out<Core::HID::NpadStyleSet> out_supported_style_set,
1033 IPC::RequestParser rp{ctx}; 598 ClientAppletResourceUserId aruid) {
1034 const auto applet_resource_user_id{rp.Pop<u64>()}; 599 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1035 600
1036 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 601 R_RETURN(GetResourceManager()->GetNpad()->GetSupportedNpadStyleSet(aruid.pid,
1037 602 *out_supported_style_set));
1038 Core::HID::NpadStyleSet supported_style_set{};
1039 const auto npad = GetResourceManager()->GetNpad();
1040 const auto result =
1041 npad->GetSupportedNpadStyleSet(applet_resource_user_id, supported_style_set);
1042
1043 IPC::ResponseBuilder rb{ctx, 3};
1044 rb.Push(result);
1045 rb.PushEnum(supported_style_set);
1046} 603}
1047 604
1048void IHidServer::SetSupportedNpadIdType(HLERequestContext& ctx) { 605Result IHidServer::SetSupportedNpadIdType(
1049 IPC::RequestParser rp{ctx}; 606 ClientAppletResourceUserId aruid,
1050 const auto applet_resource_user_id{rp.Pop<u64>()}; 607 InArray<Core::HID::NpadIdType, BufferAttr_HipcPointer> supported_npad_list) {
1051 const auto buffer = ctx.ReadBuffer(); 608 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1052 const std::size_t elements = ctx.GetReadBufferNumElements<Core::HID::NpadIdType>();
1053
1054 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1055 609
1056 std::vector<Core::HID::NpadIdType> supported_npad_list(elements); 610 R_RETURN(
1057 memcpy(supported_npad_list.data(), buffer.data(), buffer.size()); 611 GetResourceManager()->GetNpad()->SetSupportedNpadIdType(aruid.pid, supported_npad_list));
1058
1059 const auto npad = GetResourceManager()->GetNpad();
1060 const Result result =
1061 npad->SetSupportedNpadIdType(applet_resource_user_id, supported_npad_list);
1062
1063 IPC::ResponseBuilder rb{ctx, 2};
1064 rb.Push(result);
1065} 612}
1066 613
1067void IHidServer::ActivateNpad(HLERequestContext& ctx) { 614Result IHidServer::ActivateNpad(ClientAppletResourceUserId aruid) {
1068 IPC::RequestParser rp{ctx}; 615 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1069 const auto applet_resource_user_id{rp.Pop<u64>()};
1070
1071 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1072 616
1073 auto npad = GetResourceManager()->GetNpad(); 617 auto npad = GetResourceManager()->GetNpad();
1074 618
1075 npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0); 619 GetResourceManager()->GetNpad()->SetRevision(aruid.pid, NpadRevision::Revision0);
1076 const Result result = npad->Activate(applet_resource_user_id); 620 R_RETURN(GetResourceManager()->GetNpad()->Activate(aruid.pid));
1077
1078 IPC::ResponseBuilder rb{ctx, 2};
1079 rb.Push(result);
1080} 621}
1081 622
1082void IHidServer::DeactivateNpad(HLERequestContext& ctx) { 623Result IHidServer::DeactivateNpad(ClientAppletResourceUserId aruid) {
1083 IPC::RequestParser rp{ctx}; 624 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1084 const auto applet_resource_user_id{rp.Pop<u64>()};
1085
1086 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1087 625
1088 // This function does nothing since 10.0.0+ 626 // This function does nothing since 10.0.0+
1089 627 R_SUCCEED();
1090 IPC::ResponseBuilder rb{ctx, 2};
1091 rb.Push(ResultSuccess);
1092} 628}
1093 629
1094void IHidServer::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) { 630Result IHidServer::AcquireNpadStyleSetUpdateEventHandle(
1095 IPC::RequestParser rp{ctx}; 631 OutCopyHandle<Kernel::KReadableEvent> out_event, Core::HID::NpadIdType npad_id,
1096 struct Parameters { 632 ClientAppletResourceUserId aruid, u64 unknown) {
1097 Core::HID::NpadIdType npad_id; 633 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}", npad_id,
1098 INSERT_PADDING_WORDS_NOINIT(1); 634 aruid.pid, unknown);
1099 u64 applet_resource_user_id;
1100 u64 unknown;
1101 };
1102 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1103 635
1104 const auto parameters{rp.PopRaw<Parameters>()}; 636 R_RETURN(GetResourceManager()->GetNpad()->AcquireNpadStyleSetUpdateEventHandle(
1105 637 aruid.pid, out_event, npad_id));
1106 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}, unknown={}",
1107 parameters.npad_id, parameters.applet_resource_user_id, parameters.unknown);
1108
1109 Kernel::KReadableEvent* style_set_update_event;
1110 const auto result = GetResourceManager()->GetNpad()->AcquireNpadStyleSetUpdateEventHandle(
1111 parameters.applet_resource_user_id, &style_set_update_event, parameters.npad_id);
1112
1113 IPC::ResponseBuilder rb{ctx, 2, 1};
1114 rb.Push(result);
1115 rb.PushCopyObjects(style_set_update_event);
1116} 638}
1117 639
1118void IHidServer::DisconnectNpad(HLERequestContext& ctx) { 640Result IHidServer::DisconnectNpad(Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid) {
1119 IPC::RequestParser rp{ctx}; 641 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid);
1120 struct Parameters {
1121 Core::HID::NpadIdType npad_id;
1122 INSERT_PADDING_WORDS_NOINIT(1);
1123 u64 applet_resource_user_id;
1124 };
1125 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1126
1127 const auto parameters{rp.PopRaw<Parameters>()};
1128
1129 auto controller = GetResourceManager()->GetNpad();
1130 controller->DisconnectNpad(parameters.applet_resource_user_id, parameters.npad_id);
1131 642
1132 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, 643 R_RETURN(GetResourceManager()->GetNpad()->DisconnectNpad(aruid.pid, npad_id));
1133 parameters.applet_resource_user_id);
1134
1135 IPC::ResponseBuilder rb{ctx, 2};
1136 rb.Push(ResultSuccess);
1137} 644}
1138 645
1139Result IHidServer::GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern, 646Result IHidServer::GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern,
@@ -1171,833 +678,445 @@ Result IHidServer::GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_patter
1171 } 678 }
1172} 679}
1173 680
1174void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { 681Result IHidServer::ActivateNpadWithRevision(NpadRevision revision,
1175 IPC::RequestParser rp{ctx}; 682 ClientAppletResourceUserId aruid) {
1176 struct Parameters { 683 LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", revision, aruid.pid);
1177 NpadRevision revision;
1178 INSERT_PADDING_WORDS_NOINIT(1);
1179 u64 applet_resource_user_id;
1180 };
1181 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1182
1183 const auto parameters{rp.PopRaw<Parameters>()};
1184
1185 LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", parameters.revision,
1186 parameters.applet_resource_user_id);
1187
1188 auto npad = GetResourceManager()->GetNpad();
1189
1190 npad->SetRevision(parameters.applet_resource_user_id, parameters.revision);
1191 const auto result = npad->Activate(parameters.applet_resource_user_id);
1192 684
1193 IPC::ResponseBuilder rb{ctx, 2}; 685 GetResourceManager()->GetNpad()->SetRevision(aruid.pid, revision);
1194 rb.Push(result); 686 R_RETURN(GetResourceManager()->GetNpad()->Activate(aruid.pid));
1195} 687}
1196 688
1197void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) { 689Result IHidServer::SetNpadJoyHoldType(ClientAppletResourceUserId aruid, NpadJoyHoldType hold_type) {
1198 IPC::RequestParser rp{ctx}; 690 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}", aruid.pid,
1199 const auto applet_resource_user_id{rp.Pop<u64>()}; 691 hold_type);
1200 const auto hold_type{rp.PopEnum<NpadJoyHoldType>()};
1201
1202 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}",
1203 applet_resource_user_id, hold_type);
1204 692
1205 if (hold_type != NpadJoyHoldType::Horizontal && hold_type != NpadJoyHoldType::Vertical) { 693 if (hold_type != NpadJoyHoldType::Horizontal && hold_type != NpadJoyHoldType::Vertical) {
1206 // This should crash console 694 // This should crash console
1207 ASSERT_MSG(false, "Invalid npad joy hold type"); 695 ASSERT_MSG(false, "Invalid npad joy hold type");
1208 } 696 }
1209 697
1210 const auto npad = GetResourceManager()->GetNpad(); 698 R_RETURN(GetResourceManager()->GetNpad()->SetNpadJoyHoldType(aruid.pid, hold_type));
1211 const auto result = npad->SetNpadJoyHoldType(applet_resource_user_id, hold_type);
1212
1213 IPC::ResponseBuilder rb{ctx, 2};
1214 rb.Push(result);
1215} 699}
1216 700
1217void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) { 701Result IHidServer::GetNpadJoyHoldType(Out<NpadJoyHoldType> out_hold_type,
1218 IPC::RequestParser rp{ctx}; 702 ClientAppletResourceUserId aruid) {
1219 const auto applet_resource_user_id{rp.Pop<u64>()}; 703 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1220
1221 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1222 704
1223 NpadJoyHoldType hold_type{}; 705 R_RETURN(GetResourceManager()->GetNpad()->GetNpadJoyHoldType(aruid.pid, *out_hold_type));
1224 const auto npad = GetResourceManager()->GetNpad();
1225 const auto result = npad->GetNpadJoyHoldType(applet_resource_user_id, hold_type);
1226
1227 IPC::ResponseBuilder rb{ctx, 4};
1228 rb.Push(result);
1229 rb.PushEnum(hold_type);
1230} 706}
1231 707
1232void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) { 708Result IHidServer::SetNpadJoyAssignmentModeSingleByDefault(Core::HID::NpadIdType npad_id,
1233 IPC::RequestParser rp{ctx}; 709 ClientAppletResourceUserId aruid) {
1234 struct Parameters { 710 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid);
1235 Core::HID::NpadIdType npad_id;
1236 INSERT_PADDING_WORDS_NOINIT(1);
1237 u64 applet_resource_user_id;
1238 };
1239 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1240
1241 const auto parameters{rp.PopRaw<Parameters>()};
1242 711
1243 Core::HID::NpadIdType new_npad_id{}; 712 Core::HID::NpadIdType new_npad_id{};
1244 auto controller = GetResourceManager()->GetNpad(); 713 GetResourceManager()->GetNpad()->SetNpadMode(
1245 controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, 714 aruid.pid, new_npad_id, npad_id, NpadJoyDeviceType::Left, NpadJoyAssignmentMode::Single);
1246 NpadJoyDeviceType::Left, NpadJoyAssignmentMode::Single); 715 R_SUCCEED();
1247
1248 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
1249 parameters.applet_resource_user_id);
1250
1251 IPC::ResponseBuilder rb{ctx, 2};
1252 rb.Push(ResultSuccess);
1253} 716}
1254 717
1255void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) { 718Result IHidServer::SetNpadJoyAssignmentModeSingle(Core::HID::NpadIdType npad_id,
1256 IPC::RequestParser rp{ctx}; 719 ClientAppletResourceUserId aruid,
1257 struct Parameters { 720 NpadJoyDeviceType npad_joy_device_type) {
1258 Core::HID::NpadIdType npad_id;
1259 INSERT_PADDING_WORDS_NOINIT(1);
1260 u64 applet_resource_user_id;
1261 NpadJoyDeviceType npad_joy_device_type;
1262 };
1263 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1264
1265 const auto parameters{rp.PopRaw<Parameters>()};
1266
1267 Core::HID::NpadIdType new_npad_id{};
1268 auto controller = GetResourceManager()->GetNpad();
1269 controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id,
1270 parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single);
1271
1272 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", 721 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
1273 parameters.npad_id, parameters.applet_resource_user_id, 722 npad_id, aruid.pid, npad_joy_device_type);
1274 parameters.npad_joy_device_type);
1275 723
1276 IPC::ResponseBuilder rb{ctx, 2}; 724 Core::HID::NpadIdType new_npad_id{};
1277 rb.Push(ResultSuccess); 725 GetResourceManager()->GetNpad()->SetNpadMode(
726 aruid.pid, new_npad_id, npad_id, npad_joy_device_type, NpadJoyAssignmentMode::Single);
727 R_SUCCEED();
1278} 728}
1279 729
1280void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) { 730Result IHidServer::SetNpadJoyAssignmentModeDual(Core::HID::NpadIdType npad_id,
1281 IPC::RequestParser rp{ctx}; 731 ClientAppletResourceUserId aruid) {
1282 struct Parameters { 732 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid);
1283 Core::HID::NpadIdType npad_id;
1284 INSERT_PADDING_WORDS_NOINIT(1);
1285 u64 applet_resource_user_id;
1286 };
1287 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1288
1289 const auto parameters{rp.PopRaw<Parameters>()};
1290 733
1291 Core::HID::NpadIdType new_npad_id{}; 734 Core::HID::NpadIdType new_npad_id{};
1292 auto controller = GetResourceManager()->GetNpad(); 735 GetResourceManager()->GetNpad()->SetNpadMode(aruid.pid, new_npad_id, npad_id, {},
1293 controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id, {}, 736 NpadJoyAssignmentMode::Dual);
1294 NpadJoyAssignmentMode::Dual); 737 R_SUCCEED();
1295
1296 LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id,
1297 parameters.applet_resource_user_id); // Spams a lot when controller applet is open
1298
1299 IPC::ResponseBuilder rb{ctx, 2};
1300 rb.Push(ResultSuccess);
1301} 738}
1302 739
1303void IHidServer::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) { 740Result IHidServer::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1,
1304 IPC::RequestParser rp{ctx}; 741 Core::HID::NpadIdType npad_id_2,
1305 const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; 742 ClientAppletResourceUserId aruid) {
1306 const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()};
1307 const auto applet_resource_user_id{rp.Pop<u64>()};
1308
1309 auto controller = GetResourceManager()->GetNpad();
1310 const auto result =
1311 controller->MergeSingleJoyAsDualJoy(applet_resource_user_id, npad_id_1, npad_id_2);
1312
1313 LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", 743 LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
1314 npad_id_1, npad_id_2, applet_resource_user_id); 744 npad_id_1, npad_id_2, aruid.pid);
1315 745
1316 IPC::ResponseBuilder rb{ctx, 2}; 746 R_RETURN(
1317 rb.Push(result); 747 GetResourceManager()->GetNpad()->MergeSingleJoyAsDualJoy(aruid.pid, npad_id_1, npad_id_2));
1318} 748}
1319 749
1320void IHidServer::StartLrAssignmentMode(HLERequestContext& ctx) { 750Result IHidServer::StartLrAssignmentMode(ClientAppletResourceUserId aruid) {
1321 IPC::RequestParser rp{ctx}; 751 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1322 const auto applet_resource_user_id{rp.Pop<u64>()};
1323
1324 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1325
1326 GetResourceManager()->GetNpad()->StartLrAssignmentMode(applet_resource_user_id);
1327 752
1328 IPC::ResponseBuilder rb{ctx, 2}; 753 GetResourceManager()->GetNpad()->StartLrAssignmentMode(aruid.pid);
1329 rb.Push(ResultSuccess); 754 R_SUCCEED();
1330} 755}
1331 756
1332void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) { 757Result IHidServer::StopLrAssignmentMode(ClientAppletResourceUserId aruid) {
1333 IPC::RequestParser rp{ctx}; 758 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1334 const auto applet_resource_user_id{rp.Pop<u64>()};
1335 759
1336 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 760 GetResourceManager()->GetNpad()->StopLrAssignmentMode(aruid.pid);
1337 761 R_SUCCEED();
1338 GetResourceManager()->GetNpad()->StopLrAssignmentMode(applet_resource_user_id);
1339
1340 IPC::ResponseBuilder rb{ctx, 2};
1341 rb.Push(ResultSuccess);
1342} 762}
1343 763
1344void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) { 764Result IHidServer::SetNpadHandheldActivationMode(ClientAppletResourceUserId aruid,
1345 IPC::RequestParser rp{ctx}; 765 NpadHandheldActivationMode activation_mode) {
1346 const auto applet_resource_user_id{rp.Pop<u64>()}; 766 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}", aruid.pid,
1347 const auto activation_mode{rp.PopEnum<NpadHandheldActivationMode>()}; 767 activation_mode);
1348
1349 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}",
1350 applet_resource_user_id, activation_mode);
1351 768
1352 if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) { 769 if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) {
1353 // Console should crash here 770 // Console should crash here
1354 ASSERT_MSG(false, "Activation mode should be always None, Single or Dual"); 771 ASSERT_MSG(false, "Activation mode should be always None, Single or Dual");
1355 IPC::ResponseBuilder rb{ctx, 2}; 772 R_SUCCEED();
1356 rb.Push(ResultSuccess);
1357 return;
1358 } 773 }
1359 774
1360 const auto npad = GetResourceManager()->GetNpad(); 775 R_RETURN(
1361 const auto result = 776 GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(aruid.pid, activation_mode));
1362 npad->SetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
1363
1364 IPC::ResponseBuilder rb{ctx, 2};
1365 rb.Push(result);
1366} 777}
1367 778
1368void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) { 779Result IHidServer::GetNpadHandheldActivationMode(
1369 IPC::RequestParser rp{ctx}; 780 Out<NpadHandheldActivationMode> out_activation_mode, ClientAppletResourceUserId aruid) {
1370 const auto applet_resource_user_id{rp.Pop<u64>()}; 781 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1371
1372 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1373 782
1374 NpadHandheldActivationMode activation_mode{}; 783 R_RETURN(GetResourceManager()->GetNpad()->GetNpadHandheldActivationMode(aruid.pid,
1375 const auto npad = GetResourceManager()->GetNpad(); 784 *out_activation_mode));
1376 const auto result =
1377 npad->GetNpadHandheldActivationMode(applet_resource_user_id, activation_mode);
1378
1379 IPC::ResponseBuilder rb{ctx, 4};
1380 rb.Push(result);
1381 rb.PushEnum(activation_mode);
1382} 785}
1383 786
1384void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) { 787Result IHidServer::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1,
1385 IPC::RequestParser rp{ctx}; 788 Core::HID::NpadIdType npad_id_2,
1386 const auto npad_id_1{rp.PopEnum<Core::HID::NpadIdType>()}; 789 ClientAppletResourceUserId aruid) {
1387 const auto npad_id_2{rp.PopEnum<Core::HID::NpadIdType>()};
1388 const auto applet_resource_user_id{rp.Pop<u64>()};
1389
1390 LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", 790 LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}",
1391 npad_id_1, npad_id_2, applet_resource_user_id); 791 npad_id_1, npad_id_2, aruid.pid);
1392
1393 const auto npad = GetResourceManager()->GetNpad();
1394 const auto result = npad->SwapNpadAssignment(applet_resource_user_id, npad_id_1, npad_id_2);
1395 792
1396 IPC::ResponseBuilder rb{ctx, 2}; 793 R_RETURN(GetResourceManager()->GetNpad()->SwapNpadAssignment(aruid.pid, npad_id_1, npad_id_2))
1397 rb.Push(result);
1398} 794}
1399 795
1400void IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx) { 796Result IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(Out<bool> out_is_enabled,
1401 IPC::RequestParser rp{ctx}; 797 Core::HID::NpadIdType npad_id,
1402 struct Parameters { 798 ClientAppletResourceUserId aruid) {
1403 Core::HID::NpadIdType npad_id; 799 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", npad_id, aruid.pid);
1404 INSERT_PADDING_WORDS_NOINIT(1);
1405 u64 applet_resource_user_id;
1406 };
1407 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1408
1409 const auto parameters{rp.PopRaw<Parameters>()};
1410 800
1411 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, 801 R_UNLESS(IsNpadIdValid(npad_id), ResultInvalidNpadId);
1412 parameters.applet_resource_user_id); 802 R_RETURN(GetResourceManager()->GetNpad()->IsUnintendedHomeButtonInputProtectionEnabled(
1413 803 *out_is_enabled, aruid.pid, npad_id));
1414 if (!IsNpadIdValid(parameters.npad_id)) {
1415 IPC::ResponseBuilder rb{ctx, 3};
1416 rb.Push(ResultInvalidNpadId);
1417 return;
1418 }
1419
1420 bool is_enabled{};
1421 const auto npad = GetResourceManager()->GetNpad();
1422 const auto result = npad->IsUnintendedHomeButtonInputProtectionEnabled(
1423 is_enabled, parameters.applet_resource_user_id, parameters.npad_id);
1424
1425 IPC::ResponseBuilder rb{ctx, 3};
1426 rb.Push(result);
1427 rb.Push(is_enabled);
1428} 804}
1429 805
1430void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx) { 806Result IHidServer::EnableUnintendedHomeButtonInputProtection(bool is_enabled,
1431 IPC::RequestParser rp{ctx}; 807 Core::HID::NpadIdType npad_id,
1432 struct Parameters { 808 ClientAppletResourceUserId aruid) {
1433 bool is_enabled;
1434 INSERT_PADDING_BYTES_NOINIT(3);
1435 Core::HID::NpadIdType npad_id;
1436 u64 applet_resource_user_id;
1437 };
1438 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1439
1440 const auto parameters{rp.PopRaw<Parameters>()};
1441
1442 LOG_DEBUG(Service_HID, "called, is_enabled={}, npad_id={}, applet_resource_user_id={}", 809 LOG_DEBUG(Service_HID, "called, is_enabled={}, npad_id={}, applet_resource_user_id={}",
1443 parameters.is_enabled, parameters.npad_id, parameters.applet_resource_user_id); 810 is_enabled, npad_id, aruid.pid);
1444
1445 if (!IsNpadIdValid(parameters.npad_id)) {
1446 IPC::ResponseBuilder rb{ctx, 3};
1447 rb.Push(ResultInvalidNpadId);
1448 return;
1449 }
1450
1451 const auto npad = GetResourceManager()->GetNpad();
1452 const auto result = npad->EnableUnintendedHomeButtonInputProtection(
1453 parameters.applet_resource_user_id, parameters.npad_id, parameters.is_enabled);
1454 811
1455 IPC::ResponseBuilder rb{ctx, 2}; 812 R_UNLESS(IsNpadIdValid(npad_id), ResultInvalidNpadId);
1456 rb.Push(result); 813 R_RETURN(GetResourceManager()->GetNpad()->EnableUnintendedHomeButtonInputProtection(
814 aruid.pid, npad_id, is_enabled));
1457} 815}
1458 816
1459void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext& ctx) { 817Result IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(
1460 IPC::RequestParser rp{ctx}; 818 Out<bool> out_is_reassigned, Out<Core::HID::NpadIdType> out_new_npad_id,
1461 struct Parameters { 819 Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid,
1462 Core::HID::NpadIdType npad_id; 820 NpadJoyDeviceType npad_joy_device_type) {
1463 INSERT_PADDING_WORDS_NOINIT(1);
1464 u64 applet_resource_user_id;
1465 NpadJoyDeviceType npad_joy_device_type;
1466 };
1467 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1468
1469 const auto parameters{rp.PopRaw<Parameters>()};
1470
1471 Core::HID::NpadIdType new_npad_id{};
1472 auto controller = GetResourceManager()->GetNpad();
1473 const auto is_reassigned =
1474 controller->SetNpadMode(parameters.applet_resource_user_id, new_npad_id, parameters.npad_id,
1475 parameters.npad_joy_device_type, NpadJoyAssignmentMode::Single);
1476
1477 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", 821 LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}",
1478 parameters.npad_id, parameters.applet_resource_user_id, 822 npad_id, aruid.pid, npad_joy_device_type);
1479 parameters.npad_joy_device_type);
1480 823
1481 IPC::ResponseBuilder rb{ctx, 4}; 824 *out_is_reassigned = GetResourceManager()->GetNpad()->SetNpadMode(
1482 rb.Push(ResultSuccess); 825 aruid.pid, *out_new_npad_id, npad_id, npad_joy_device_type, NpadJoyAssignmentMode::Single);
1483 rb.Push(is_reassigned);
1484 rb.PushEnum(new_npad_id);
1485}
1486
1487void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) {
1488 IPC::RequestParser rp{ctx};
1489 struct Parameters {
1490 bool use_center_clamp;
1491 INSERT_PADDING_BYTES_NOINIT(7);
1492 u64 applet_resource_user_id;
1493 };
1494 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1495 826
1496 const auto parameters{rp.PopRaw<Parameters>()}; 827 R_SUCCEED();
828}
1497 829
830Result IHidServer::SetNpadAnalogStickUseCenterClamp(bool use_center_clamp,
831 ClientAppletResourceUserId aruid) {
1498 LOG_INFO(Service_HID, "called, use_center_clamp={}, applet_resource_user_id={}", 832 LOG_INFO(Service_HID, "called, use_center_clamp={}, applet_resource_user_id={}",
1499 parameters.use_center_clamp, parameters.applet_resource_user_id); 833 use_center_clamp, aruid.pid);
1500
1501 GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(
1502 parameters.applet_resource_user_id, parameters.use_center_clamp);
1503 834
1504 IPC::ResponseBuilder rb{ctx, 2}; 835 GetResourceManager()->GetNpad()->SetNpadAnalogStickUseCenterClamp(aruid.pid, use_center_clamp);
1505 rb.Push(ResultSuccess); 836 R_SUCCEED();
1506} 837}
1507 838
1508void IHidServer::SetNpadCaptureButtonAssignment(HLERequestContext& ctx) { 839Result IHidServer::SetNpadCaptureButtonAssignment(Core::HID::NpadStyleSet npad_styleset,
1509 IPC::RequestParser rp{ctx}; 840 ClientAppletResourceUserId aruid,
1510 struct Parameters { 841 Core::HID::NpadButton button) {
1511 Core::HID::NpadStyleSet npad_styleset;
1512 INSERT_PADDING_WORDS_NOINIT(1);
1513 u64 applet_resource_user_id;
1514 Core::HID::NpadButton button;
1515 };
1516 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1517
1518 const auto parameters{rp.PopRaw<Parameters>()};
1519
1520 LOG_INFO(Service_HID, "called, npad_styleset={}, applet_resource_user_id={}, button={}", 842 LOG_INFO(Service_HID, "called, npad_styleset={}, applet_resource_user_id={}, button={}",
1521 parameters.npad_styleset, parameters.applet_resource_user_id, parameters.button); 843 npad_styleset, aruid.pid, button);
1522
1523 const auto result = GetResourceManager()->GetNpad()->SetNpadCaptureButtonAssignment(
1524 parameters.applet_resource_user_id, parameters.npad_styleset, parameters.button);
1525 844
1526 IPC::ResponseBuilder rb{ctx, 2}; 845 R_RETURN(GetResourceManager()->GetNpad()->SetNpadCaptureButtonAssignment(
1527 rb.Push(result); 846 aruid.pid, npad_styleset, button));
1528} 847}
1529 848
1530void IHidServer::ClearNpadCaptureButtonAssignment(HLERequestContext& ctx) { 849Result IHidServer::ClearNpadCaptureButtonAssignment(ClientAppletResourceUserId aruid) {
1531 IPC::RequestParser rp{ctx}; 850 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1532 const auto applet_resource_user_id{rp.Pop<u64>()};
1533 851
1534 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 852 R_RETURN(GetResourceManager()->GetNpad()->ClearNpadCaptureButtonAssignment(aruid.pid));
1535
1536 const auto result =
1537 GetResourceManager()->GetNpad()->ClearNpadCaptureButtonAssignment(applet_resource_user_id);
1538
1539 IPC::ResponseBuilder rb{ctx, 2};
1540 rb.Push(result);
1541} 853}
1542 854
1543void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) { 855Result IHidServer::GetVibrationDeviceInfo(
1544 IPC::RequestParser rp{ctx}; 856 Out<Core::HID::VibrationDeviceInfo> out_vibration_device_info,
1545 const auto vibration_device_handle{rp.PopRaw<Core::HID::VibrationDeviceHandle>()}; 857 Core::HID::VibrationDeviceHandle vibration_device_handle) {
858 LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}",
859 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
860 vibration_device_handle.device_index);
1546 861
1547 Core::HID::VibrationDeviceInfo vibration_device_info{}; 862 R_RETURN(GetResourceManager()->GetVibrationDeviceInfo(*out_vibration_device_info,
1548 const auto result = GetResourceManager()->GetVibrationDeviceInfo(vibration_device_info, 863 vibration_device_handle));
1549 vibration_device_handle);
1550
1551 IPC::ResponseBuilder rb{ctx, 4};
1552 rb.Push(result);
1553 rb.PushRaw(vibration_device_info);
1554} 864}
1555 865
1556void IHidServer::SendVibrationValue(HLERequestContext& ctx) { 866Result IHidServer::SendVibrationValue(Core::HID::VibrationDeviceHandle vibration_device_handle,
1557 IPC::RequestParser rp{ctx}; 867 Core::HID::VibrationValue vibration_value,
1558 struct Parameters { 868 ClientAppletResourceUserId aruid) {
1559 Core::HID::VibrationDeviceHandle vibration_device_handle;
1560 Core::HID::VibrationValue vibration_value;
1561 INSERT_PADDING_WORDS_NOINIT(1);
1562 u64 applet_resource_user_id;
1563 };
1564 static_assert(sizeof(Parameters) == 0x20, "Parameters has incorrect size.");
1565
1566 const auto parameters{rp.PopRaw<Parameters>()};
1567
1568 LOG_DEBUG(Service_HID, 869 LOG_DEBUG(Service_HID,
1569 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 870 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
1570 parameters.vibration_device_handle.npad_type, 871 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1571 parameters.vibration_device_handle.npad_id, 872 vibration_device_handle.device_index, aruid.pid);
1572 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
1573
1574 GetResourceManager()->SendVibrationValue(parameters.applet_resource_user_id,
1575 parameters.vibration_device_handle,
1576 parameters.vibration_value);
1577 873
1578 IPC::ResponseBuilder rb{ctx, 2}; 874 GetResourceManager()->SendVibrationValue(aruid.pid, vibration_device_handle, vibration_value);
1579 rb.Push(ResultSuccess); 875 R_SUCCEED()
1580} 876}
1581 877
1582void IHidServer::GetActualVibrationValue(HLERequestContext& ctx) { 878Result IHidServer::GetActualVibrationValue(Out<Core::HID::VibrationValue> out_vibration_value,
1583 IPC::RequestParser rp{ctx}; 879 Core::HID::VibrationDeviceHandle vibration_device_handle,
1584 struct Parameters { 880 ClientAppletResourceUserId aruid) {
1585 Core::HID::VibrationDeviceHandle vibration_device_handle;
1586 INSERT_PADDING_WORDS_NOINIT(1);
1587 u64 applet_resource_user_id;
1588 };
1589 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1590
1591 const auto parameters{rp.PopRaw<Parameters>()};
1592
1593 LOG_DEBUG(Service_HID, 881 LOG_DEBUG(Service_HID,
1594 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 882 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
1595 parameters.vibration_device_handle.npad_type, 883 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1596 parameters.vibration_device_handle.npad_id, 884 vibration_device_handle.device_index, aruid.pid);
1597 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
1598 885
1599 bool has_active_aruid{}; 886 bool has_active_aruid{};
1600 NpadVibrationDevice* device{nullptr}; 887 R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid));
1601 Core::HID::VibrationValue vibration_value{};
1602 Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
1603 has_active_aruid);
1604 888
1605 if (result.IsSuccess() && has_active_aruid) { 889 if (!has_active_aruid) {
1606 result = IsVibrationHandleValid(parameters.vibration_device_handle); 890 *out_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE;
1607 } 891 R_SUCCEED();
1608 if (result.IsSuccess() && has_active_aruid) {
1609 device = GetResourceManager()->GetNSVibrationDevice(parameters.vibration_device_handle);
1610 }
1611 if (device != nullptr) {
1612 result = device->GetActualVibrationValue(vibration_value);
1613 } 892 }
1614 if (result.IsError()) { 893
1615 vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE; 894 R_TRY(IsVibrationHandleValid(vibration_device_handle));
895 NpadVibrationDevice* device =
896 GetResourceManager()->GetNSVibrationDevice(vibration_device_handle);
897
898 if (device == nullptr || R_FAILED(device->GetActualVibrationValue(*out_vibration_value))) {
899 *out_vibration_value = Core::HID::DEFAULT_VIBRATION_VALUE;
1616 } 900 }
1617 901
1618 IPC::ResponseBuilder rb{ctx, 6}; 902 R_SUCCEED();
1619 rb.Push(ResultSuccess);
1620 rb.PushRaw(vibration_value);
1621} 903}
1622 904
1623void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { 905Result IHidServer::CreateActiveVibrationDeviceList(
906 OutInterface<IActiveVibrationDeviceList> out_interface) {
1624 LOG_DEBUG(Service_HID, "called"); 907 LOG_DEBUG(Service_HID, "called");
1625 908
1626 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 909 *out_interface = std::make_shared<IActiveVibrationDeviceList>(system, GetResourceManager());
1627 rb.Push(ResultSuccess); 910 R_SUCCEED();
1628 rb.PushIpcInterface<IActiveVibrationDeviceList>(system, GetResourceManager());
1629} 911}
1630 912
1631void IHidServer::PermitVibration(HLERequestContext& ctx) { 913Result IHidServer::PermitVibration(bool can_vibrate) {
1632 IPC::RequestParser rp{ctx};
1633 const auto can_vibrate{rp.Pop<bool>()};
1634
1635 LOG_DEBUG(Service_HID, "called, can_vibrate={}", can_vibrate); 914 LOG_DEBUG(Service_HID, "called, can_vibrate={}", can_vibrate);
1636 915
1637 const auto result = 916 R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->SetVibrationMasterVolume(
1638 GetResourceManager()->GetNpad()->GetVibrationHandler()->SetVibrationMasterVolume( 917 can_vibrate ? 1.0f : 0.0f));
1639 can_vibrate ? 1.0f : 0.0f);
1640
1641 IPC::ResponseBuilder rb{ctx, 2};
1642 rb.Push(result);
1643} 918}
1644 919
1645void IHidServer::IsVibrationPermitted(HLERequestContext& ctx) { 920Result IHidServer::IsVibrationPermitted(Out<bool> out_is_permitted) {
1646 LOG_DEBUG(Service_HID, "called"); 921 LOG_DEBUG(Service_HID, "called");
1647 922
1648 f32 master_volume{}; 923 f32 master_volume{};
1649 const auto result = 924 R_TRY(GetResourceManager()->GetNpad()->GetVibrationHandler()->GetVibrationMasterVolume(
1650 GetResourceManager()->GetNpad()->GetVibrationHandler()->GetVibrationMasterVolume( 925 master_volume));
1651 master_volume);
1652 926
1653 IPC::ResponseBuilder rb{ctx, 3}; 927 *out_is_permitted = master_volume > 0.0f;
1654 rb.Push(result); 928 R_SUCCEED();
1655 rb.Push(master_volume > 0.0f);
1656} 929}
1657 930
1658void IHidServer::SendVibrationValues(HLERequestContext& ctx) { 931Result IHidServer::SendVibrationValues(
1659 IPC::RequestParser rp{ctx}; 932 ClientAppletResourceUserId aruid,
1660 const auto applet_resource_user_id{rp.Pop<u64>()}; 933 InArray<Core::HID::VibrationDeviceHandle, BufferAttr_HipcPointer> vibration_handles,
1661 934 InArray<Core::HID::VibrationValue, BufferAttr_HipcPointer> vibration_values) {
1662 const auto handle_data = ctx.ReadBuffer(0); 935 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1663 const auto handle_count = ctx.GetReadBufferNumElements<Core::HID::VibrationDeviceHandle>(0);
1664 const auto vibration_data = ctx.ReadBuffer(1);
1665 const auto vibration_count = ctx.GetReadBufferNumElements<Core::HID::VibrationValue>(1);
1666 936
1667 auto vibration_device_handles = 937 R_UNLESS(vibration_handles.size() == vibration_values.size(), ResultVibrationArraySizeMismatch);
1668 std::span(reinterpret_cast<const Core::HID::VibrationDeviceHandle*>(handle_data.data()),
1669 handle_count);
1670 auto vibration_values = std::span(
1671 reinterpret_cast<const Core::HID::VibrationValue*>(vibration_data.data()), vibration_count);
1672 938
1673 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 939 for (std::size_t i = 0; i < vibration_handles.size(); i++) {
1674 940 R_TRY(GetResourceManager()->SendVibrationValue(aruid.pid, vibration_handles[i],
1675 Result result = ResultSuccess; 941 vibration_values[i]));
1676 if (handle_count != vibration_count) {
1677 result = ResultVibrationArraySizeMismatch;
1678 }
1679
1680 for (std::size_t i = 0; i < handle_count; i++) {
1681 if (result.IsSuccess()) {
1682 result = GetResourceManager()->SendVibrationValue(
1683 applet_resource_user_id, vibration_device_handles[i], vibration_values[i]);
1684 }
1685 } 942 }
1686 943
1687 IPC::ResponseBuilder rb{ctx, 2}; 944 R_SUCCEED();
1688 rb.Push(result);
1689} 945}
1690 946
1691void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) { 947Result IHidServer::SendVibrationGcErmCommand(
1692 IPC::RequestParser rp{ctx}; 948 Core::HID::VibrationDeviceHandle vibration_device_handle, ClientAppletResourceUserId aruid,
1693 struct Parameters { 949 Core::HID::VibrationGcErmCommand gc_erm_command) {
1694 Core::HID::VibrationDeviceHandle vibration_device_handle;
1695 INSERT_PADDING_WORDS_NOINIT(1);
1696 u64 applet_resource_user_id;
1697 Core::HID::VibrationGcErmCommand gc_erm_command;
1698 };
1699 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1700
1701 const auto parameters{rp.PopRaw<Parameters>()};
1702
1703 LOG_DEBUG(Service_HID, 950 LOG_DEBUG(Service_HID,
1704 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, " 951 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, "
1705 "gc_erm_command={}", 952 "gc_erm_command={}",
1706 parameters.vibration_device_handle.npad_type, 953 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1707 parameters.vibration_device_handle.npad_id, 954 vibration_device_handle.device_index, aruid.pid, gc_erm_command);
1708 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id,
1709 parameters.gc_erm_command);
1710 955
1711 bool has_active_aruid{}; 956 bool has_active_aruid{};
1712 NpadGcVibrationDevice* gc_device{nullptr}; 957 R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid));
1713 Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
1714 has_active_aruid);
1715 958
1716 if (result.IsSuccess() && has_active_aruid) { 959 if (!has_active_aruid) {
1717 result = IsVibrationHandleValid(parameters.vibration_device_handle); 960 R_SUCCEED();
1718 }
1719 if (result.IsSuccess() && has_active_aruid) {
1720 gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle);
1721 } 961 }
962
963 R_TRY(IsVibrationHandleValid(vibration_device_handle));
964 NpadGcVibrationDevice* gc_device =
965 GetResourceManager()->GetGcVibrationDevice(vibration_device_handle);
1722 if (gc_device != nullptr) { 966 if (gc_device != nullptr) {
1723 result = gc_device->SendVibrationGcErmCommand(parameters.gc_erm_command); 967 R_RETURN(gc_device->SendVibrationGcErmCommand(gc_erm_command));
1724 } 968 }
1725 969
1726 IPC::ResponseBuilder rb{ctx, 2}; 970 R_SUCCEED();
1727 rb.Push(result);
1728} 971}
1729 972
1730void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) { 973Result IHidServer::GetActualVibrationGcErmCommand(
1731 IPC::RequestParser rp{ctx}; 974 Out<Core::HID::VibrationGcErmCommand> out_gc_erm_command,
1732 struct Parameters { 975 Core::HID::VibrationDeviceHandle vibration_device_handle, ClientAppletResourceUserId aruid) {
1733 Core::HID::VibrationDeviceHandle vibration_device_handle;
1734 INSERT_PADDING_WORDS_NOINIT(1);
1735 u64 applet_resource_user_id;
1736 };
1737
1738 const auto parameters{rp.PopRaw<Parameters>()};
1739
1740 LOG_DEBUG(Service_HID, 976 LOG_DEBUG(Service_HID,
1741 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 977 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
1742 parameters.vibration_device_handle.npad_type, 978 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1743 parameters.vibration_device_handle.npad_id, 979 vibration_device_handle.device_index, aruid.pid);
1744 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
1745 980
1746 bool has_active_aruid{}; 981 bool has_active_aruid{};
1747 NpadGcVibrationDevice* gc_device{nullptr}; 982 R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid));
1748 Core::HID::VibrationGcErmCommand gc_erm_command{};
1749 Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
1750 has_active_aruid);
1751 983
1752 if (result.IsSuccess() && has_active_aruid) { 984 if (!has_active_aruid) {
1753 result = IsVibrationHandleValid(parameters.vibration_device_handle); 985 *out_gc_erm_command = Core::HID::VibrationGcErmCommand::Stop;
1754 }
1755 if (result.IsSuccess() && has_active_aruid) {
1756 gc_device = GetResourceManager()->GetGcVibrationDevice(parameters.vibration_device_handle);
1757 }
1758 if (gc_device != nullptr) {
1759 result = gc_device->GetActualVibrationGcErmCommand(gc_erm_command);
1760 }
1761 if (result.IsError()) {
1762 gc_erm_command = Core::HID::VibrationGcErmCommand::Stop;
1763 } 986 }
1764 987
1765 IPC::ResponseBuilder rb{ctx, 4}; 988 R_TRY(IsVibrationHandleValid(vibration_device_handle));
1766 rb.Push(ResultSuccess); 989 NpadGcVibrationDevice* gc_device =
1767 rb.PushEnum(gc_erm_command); 990 GetResourceManager()->GetGcVibrationDevice(vibration_device_handle);
1768}
1769 991
1770void IHidServer::BeginPermitVibrationSession(HLERequestContext& ctx) { 992 if (gc_device == nullptr ||
1771 IPC::RequestParser rp{ctx}; 993 R_FAILED(gc_device->GetActualVibrationGcErmCommand(*out_gc_erm_command))) {
1772 const auto applet_resource_user_id{rp.Pop<u64>()}; 994 *out_gc_erm_command = Core::HID::VibrationGcErmCommand::Stop;
995 }
1773 996
1774 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); 997 R_SUCCEED();
998}
1775 999
1776 const auto result = 1000Result IHidServer::BeginPermitVibrationSession(ClientAppletResourceUserId aruid) {
1777 GetResourceManager()->GetNpad()->GetVibrationHandler()->BeginPermitVibrationSession( 1001 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1778 applet_resource_user_id);
1779 1002
1780 IPC::ResponseBuilder rb{ctx, 2}; 1003 R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->BeginPermitVibrationSession(
1781 rb.Push(result); 1004 aruid.pid));
1782} 1005}
1783 1006
1784void IHidServer::EndPermitVibrationSession(HLERequestContext& ctx) { 1007Result IHidServer::EndPermitVibrationSession(ClientAppletResourceUserId aruid) {
1785 LOG_DEBUG(Service_HID, "called"); 1008 LOG_DEBUG(Service_HID, "called");
1786 1009
1787 const auto result = 1010 R_RETURN(GetResourceManager()->GetNpad()->GetVibrationHandler()->EndPermitVibrationSession());
1788 GetResourceManager()->GetNpad()->GetVibrationHandler()->EndPermitVibrationSession();
1789
1790 IPC::ResponseBuilder rb{ctx, 2};
1791 rb.Push(result);
1792} 1011}
1793 1012
1794void IHidServer::IsVibrationDeviceMounted(HLERequestContext& ctx) { 1013Result IHidServer::IsVibrationDeviceMounted(
1795 IPC::RequestParser rp{ctx}; 1014 Out<bool> out_is_mounted, Core::HID::VibrationDeviceHandle vibration_device_handle,
1796 struct Parameters { 1015 ClientAppletResourceUserId aruid) {
1797 Core::HID::VibrationDeviceHandle vibration_device_handle;
1798 INSERT_PADDING_WORDS_NOINIT(1);
1799 u64 applet_resource_user_id;
1800 };
1801 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1802
1803 const auto parameters{rp.PopRaw<Parameters>()};
1804
1805 LOG_DEBUG(Service_HID, 1016 LOG_DEBUG(Service_HID,
1806 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", 1017 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}",
1807 parameters.vibration_device_handle.npad_type, 1018 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1808 parameters.vibration_device_handle.npad_id, 1019 vibration_device_handle.device_index, aruid.pid);
1809 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id);
1810 1020
1811 bool is_mounted{}; 1021 R_TRY(IsVibrationHandleValid(vibration_device_handle));
1812 NpadVibrationBase* device{nullptr};
1813 Result result = IsVibrationHandleValid(parameters.vibration_device_handle);
1814 1022
1815 if (result.IsSuccess()) { 1023 NpadVibrationBase* device = GetResourceManager()->GetVibrationDevice(vibration_device_handle);
1816 device = GetResourceManager()->GetVibrationDevice(parameters.vibration_device_handle);
1817 }
1818 1024
1819 if (device != nullptr) { 1025 if (device != nullptr) {
1820 is_mounted = device->IsVibrationMounted(); 1026 *out_is_mounted = device->IsVibrationMounted();
1821 } 1027 }
1822 1028
1823 IPC::ResponseBuilder rb{ctx, 3}; 1029 R_SUCCEED();
1824 rb.Push(result);
1825 rb.Push(is_mounted);
1826} 1030}
1827 1031
1828void IHidServer::SendVibrationValueInBool(HLERequestContext& ctx) { 1032Result IHidServer::SendVibrationValueInBool(
1829 IPC::RequestParser rp{ctx}; 1033 bool is_vibrating, Core::HID::VibrationDeviceHandle vibration_device_handle,
1830 struct Parameters { 1034 ClientAppletResourceUserId aruid) {
1831 Core::HID::VibrationDeviceHandle vibration_device_handle;
1832 INSERT_PADDING_WORDS_NOINIT(1);
1833 u64 applet_resource_user_id;
1834 bool is_vibrating;
1835 };
1836 static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size.");
1837
1838 const auto parameters{rp.PopRaw<Parameters>()};
1839
1840 LOG_DEBUG(Service_HID, 1035 LOG_DEBUG(Service_HID,
1841 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, " 1036 "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, "
1842 "is_vibrating={}", 1037 "is_vibrating={}",
1843 parameters.vibration_device_handle.npad_type, 1038 vibration_device_handle.npad_type, vibration_device_handle.npad_id,
1844 parameters.vibration_device_handle.npad_id, 1039 vibration_device_handle.device_index, aruid.pid, is_vibrating);
1845 parameters.vibration_device_handle.device_index, parameters.applet_resource_user_id,
1846 parameters.is_vibrating);
1847 1040
1848 bool has_active_aruid{}; 1041 bool has_active_aruid{};
1849 NpadN64VibrationDevice* n64_device{nullptr}; 1042 R_TRY(GetResourceManager()->IsVibrationAruidActive(aruid.pid, has_active_aruid));
1850 Result result = GetResourceManager()->IsVibrationAruidActive(parameters.applet_resource_user_id,
1851 has_active_aruid);
1852 1043
1853 if (result.IsSuccess() && has_active_aruid) { 1044 if (!has_active_aruid) {
1854 result = IsVibrationHandleValid(parameters.vibration_device_handle); 1045 R_SUCCEED();
1855 }
1856 if (result.IsSuccess() && has_active_aruid) {
1857 n64_device =
1858 GetResourceManager()->GetN64VibrationDevice(parameters.vibration_device_handle);
1859 } 1046 }
1047
1048 R_TRY(IsVibrationHandleValid(vibration_device_handle));
1049 NpadN64VibrationDevice* n64_device =
1050 GetResourceManager()->GetN64VibrationDevice(vibration_device_handle);
1051
1860 if (n64_device != nullptr) { 1052 if (n64_device != nullptr) {
1861 result = n64_device->SendValueInBool(parameters.is_vibrating); 1053 R_TRY(n64_device->SendValueInBool(is_vibrating));
1862 } 1054 }
1863 1055
1864 IPC::ResponseBuilder rb{ctx, 2}; 1056 R_SUCCEED();
1865 rb.Push(result);
1866} 1057}
1867 1058
1868void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { 1059Result IHidServer::ActivateConsoleSixAxisSensor(ClientAppletResourceUserId aruid) {
1869 IPC::RequestParser rp{ctx}; 1060 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1870 const auto applet_resource_user_id{rp.Pop<u64>()};
1871
1872 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1873
1874 Result result = ResultSuccess;
1875 auto console_sixaxis = GetResourceManager()->GetConsoleSixAxis();
1876 1061
1877 if (!firmware_settings->IsDeviceManaged()) { 1062 if (!firmware_settings->IsDeviceManaged()) {
1878 result = console_sixaxis->Activate(); 1063 R_TRY(GetResourceManager()->GetConsoleSixAxis()->Activate());
1879 }
1880
1881 if (result.IsSuccess()) {
1882 result = console_sixaxis->Activate(applet_resource_user_id);
1883 } 1064 }
1884 1065
1885 IPC::ResponseBuilder rb{ctx, 2}; 1066 R_RETURN(GetResourceManager()->GetConsoleSixAxis()->Activate(aruid.pid));
1886 rb.Push(result);
1887} 1067}
1888 1068
1889void IHidServer::StartConsoleSixAxisSensor(HLERequestContext& ctx) { 1069Result IHidServer::StartConsoleSixAxisSensor(
1890 IPC::RequestParser rp{ctx}; 1070 Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle,
1891 struct Parameters { 1071 ClientAppletResourceUserId aruid) {
1892 Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle;
1893 INSERT_PADDING_WORDS_NOINIT(1);
1894 u64 applet_resource_user_id;
1895 };
1896 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1897
1898 const auto parameters{rp.PopRaw<Parameters>()};
1899
1900 LOG_WARNING(Service_HID, 1072 LOG_WARNING(Service_HID,
1901 "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", 1073 "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}",
1902 parameters.console_sixaxis_handle.unknown_1, 1074 console_sixaxis_handle.unknown_1, console_sixaxis_handle.unknown_2, aruid.pid);
1903 parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); 1075 R_SUCCEED();
1904
1905 IPC::ResponseBuilder rb{ctx, 2};
1906 rb.Push(ResultSuccess);
1907} 1076}
1908 1077
1909void IHidServer::StopConsoleSixAxisSensor(HLERequestContext& ctx) { 1078Result IHidServer::StopConsoleSixAxisSensor(
1910 IPC::RequestParser rp{ctx}; 1079 Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle,
1911 struct Parameters { 1080 ClientAppletResourceUserId aruid) {
1912 Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle;
1913 INSERT_PADDING_WORDS_NOINIT(1);
1914 u64 applet_resource_user_id;
1915 };
1916 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
1917
1918 const auto parameters{rp.PopRaw<Parameters>()};
1919
1920 LOG_WARNING(Service_HID, 1081 LOG_WARNING(Service_HID,
1921 "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}", 1082 "(STUBBED) called, unknown_1={}, unknown_2={}, applet_resource_user_id={}",
1922 parameters.console_sixaxis_handle.unknown_1, 1083 console_sixaxis_handle.unknown_1, console_sixaxis_handle.unknown_2, aruid.pid);
1923 parameters.console_sixaxis_handle.unknown_2, parameters.applet_resource_user_id); 1084 R_SUCCEED();
1924
1925 IPC::ResponseBuilder rb{ctx, 2};
1926 rb.Push(ResultSuccess);
1927} 1085}
1928 1086
1929void IHidServer::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { 1087Result IHidServer::ActivateSevenSixAxisSensor(ClientAppletResourceUserId aruid) {
1930 IPC::RequestParser rp{ctx}; 1088 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
1931 const auto applet_resource_user_id{rp.Pop<u64>()};
1932
1933 LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
1934
1935 Result result = ResultSuccess;
1936 auto seven_sixaxis = GetResourceManager()->GetSevenSixAxis();
1937 1089
1938 if (!firmware_settings->IsDeviceManaged()) { 1090 if (!firmware_settings->IsDeviceManaged()) {
1939 result = seven_sixaxis->Activate(); 1091 R_TRY(GetResourceManager()->GetSevenSixAxis()->Activate());
1940 } 1092 }
1941 1093
1942 if (result.IsSuccess()) { 1094 GetResourceManager()->GetSevenSixAxis()->Activate(aruid.pid);
1943 seven_sixaxis->Activate(applet_resource_user_id); 1095 R_SUCCEED();
1944 }
1945
1946 IPC::ResponseBuilder rb{ctx, 2};
1947 rb.Push(ResultSuccess);
1948} 1096}
1949 1097
1950void IHidServer::StartSevenSixAxisSensor(HLERequestContext& ctx) { 1098Result IHidServer::StartSevenSixAxisSensor(ClientAppletResourceUserId aruid) {
1951 IPC::RequestParser rp{ctx}; 1099 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
1952 const auto applet_resource_user_id{rp.Pop<u64>()}; 1100 R_SUCCEED();
1953
1954 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
1955 applet_resource_user_id);
1956
1957 IPC::ResponseBuilder rb{ctx, 2};
1958 rb.Push(ResultSuccess);
1959} 1101}
1960 1102
1961void IHidServer::StopSevenSixAxisSensor(HLERequestContext& ctx) { 1103Result IHidServer::StopSevenSixAxisSensor(ClientAppletResourceUserId aruid) {
1962 IPC::RequestParser rp{ctx}; 1104 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
1963 const auto applet_resource_user_id{rp.Pop<u64>()}; 1105 R_SUCCEED();
1964
1965 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
1966 applet_resource_user_id);
1967
1968 IPC::ResponseBuilder rb{ctx, 2};
1969 rb.Push(ResultSuccess);
1970} 1106}
1971 1107
1972void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { 1108Result IHidServer::InitializeSevenSixAxisSensor(ClientAppletResourceUserId aruid, u64 t_mem_1_size,
1973 IPC::RequestParser rp{ctx}; 1109 u64 t_mem_2_size,
1974 const auto applet_resource_user_id{rp.Pop<u64>()}; 1110 InCopyHandle<Kernel::KTransferMemory> t_mem_1,
1975 const auto t_mem_1_size{rp.Pop<u64>()}; 1111 InCopyHandle<Kernel::KTransferMemory> t_mem_2) {
1976 const auto t_mem_2_size{rp.Pop<u64>()}; 1112 LOG_WARNING(Service_HID,
1977 const auto t_mem_1_handle{ctx.GetCopyHandle(0)}; 1113 "called, t_mem_1_size=0x{:08X}, t_mem_2_size=0x{:08X}, "
1978 const auto t_mem_2_handle{ctx.GetCopyHandle(1)}; 1114 "applet_resource_user_id={}",
1115 t_mem_1_size, t_mem_2_size, aruid.pid);
1979 1116
1980 ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes"); 1117 ASSERT_MSG(t_mem_1_size == 0x1000, "t_mem_1_size is not 0x1000 bytes");
1981 ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes"); 1118 ASSERT_MSG(t_mem_2_size == 0x7F000, "t_mem_2_size is not 0x7F000 bytes");
1982 1119
1983 auto t_mem_1 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_1_handle);
1984
1985 if (t_mem_1.IsNull()) {
1986 LOG_ERROR(Service_HID, "t_mem_1 is a nullptr for handle=0x{:08X}", t_mem_1_handle);
1987 IPC::ResponseBuilder rb{ctx, 2};
1988 rb.Push(ResultUnknown);
1989 return;
1990 }
1991
1992 auto t_mem_2 = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_2_handle);
1993
1994 if (t_mem_2.IsNull()) {
1995 LOG_ERROR(Service_HID, "t_mem_2 is a nullptr for handle=0x{:08X}", t_mem_2_handle);
1996 IPC::ResponseBuilder rb{ctx, 2};
1997 rb.Push(ResultUnknown);
1998 return;
1999 }
2000
2001 ASSERT_MSG(t_mem_1->GetSize() == 0x1000, "t_mem_1 has incorrect size"); 1120 ASSERT_MSG(t_mem_1->GetSize() == 0x1000, "t_mem_1 has incorrect size");
2002 ASSERT_MSG(t_mem_2->GetSize() == 0x7F000, "t_mem_2 has incorrect size"); 1121 ASSERT_MSG(t_mem_2->GetSize() == 0x7F000, "t_mem_2 has incorrect size");
2003 1122
@@ -2007,519 +1126,309 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) {
2007 1126
2008 GetResourceManager()->GetSevenSixAxis()->SetTransferMemoryAddress(t_mem_1->GetSourceAddress()); 1127 GetResourceManager()->GetSevenSixAxis()->SetTransferMemoryAddress(t_mem_1->GetSourceAddress());
2009 1128
2010 LOG_WARNING(Service_HID, 1129 R_SUCCEED();
2011 "called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, "
2012 "applet_resource_user_id={}",
2013 t_mem_1_handle, t_mem_2_handle, applet_resource_user_id);
2014
2015 IPC::ResponseBuilder rb{ctx, 2};
2016 rb.Push(ResultSuccess);
2017} 1130}
2018 1131
2019void IHidServer::FinalizeSevenSixAxisSensor(HLERequestContext& ctx) { 1132Result IHidServer::FinalizeSevenSixAxisSensor(ClientAppletResourceUserId aruid) {
2020 IPC::RequestParser rp{ctx}; 1133 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
2021 const auto applet_resource_user_id{rp.Pop<u64>()};
2022
2023 LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}",
2024 applet_resource_user_id);
2025 1134
2026 IPC::ResponseBuilder rb{ctx, 2}; 1135 R_SUCCEED();
2027 rb.Push(ResultSuccess);
2028} 1136}
2029 1137
2030void IHidServer::ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx) { 1138Result IHidServer::ResetSevenSixAxisSensorTimestamp(ClientAppletResourceUserId aruid) {
2031 IPC::RequestParser rp{ctx}; 1139 LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
2032 const auto applet_resource_user_id{rp.Pop<u64>()};
2033 1140
2034 GetResourceManager()->GetSevenSixAxis()->ResetTimestamp(); 1141 GetResourceManager()->GetSevenSixAxis()->ResetTimestamp();
2035 1142 R_SUCCEED();
2036 LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
2037
2038 IPC::ResponseBuilder rb{ctx, 2};
2039 rb.Push(ResultSuccess);
2040} 1143}
2041 1144
2042void IHidServer::IsUsbFullKeyControllerEnabled(HLERequestContext& ctx) { 1145Result IHidServer::IsUsbFullKeyControllerEnabled(Out<bool> out_is_enabled,
2043 IPC::RequestParser rp{ctx}; 1146 ClientAppletResourceUserId aruid) {
2044
2045 LOG_WARNING(Service_HID, "(STUBBED) called"); 1147 LOG_WARNING(Service_HID, "(STUBBED) called");
2046 1148
2047 IPC::ResponseBuilder rb{ctx, 3}; 1149 *out_is_enabled = false;
2048 rb.Push(ResultSuccess); 1150 R_SUCCEED();
2049 rb.Push(false);
2050} 1151}
2051 1152
2052void IHidServer::GetPalmaConnectionHandle(HLERequestContext& ctx) { 1153Result IHidServer::GetPalmaConnectionHandle(Out<Palma::PalmaConnectionHandle> out_handle,
2053 IPC::RequestParser rp{ctx}; 1154 Core::HID::NpadIdType npad_id,
2054 struct Parameters { 1155 ClientAppletResourceUserId aruid) {
2055 Core::HID::NpadIdType npad_id; 1156 LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}", npad_id,
2056 INSERT_PADDING_WORDS_NOINIT(1); 1157 aruid.pid);
2057 u64 applet_resource_user_id;
2058 };
2059 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
2060
2061 const auto parameters{rp.PopRaw<Parameters>()};
2062
2063 LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}",
2064 parameters.npad_id, parameters.applet_resource_user_id);
2065
2066 Palma::PalmaConnectionHandle handle;
2067 auto controller = GetResourceManager()->GetPalma();
2068 const auto result = controller->GetPalmaConnectionHandle(parameters.npad_id, handle);
2069 1158
2070 IPC::ResponseBuilder rb{ctx, 4}; 1159 R_RETURN(GetResourceManager()->GetPalma()->GetPalmaConnectionHandle(npad_id, *out_handle));
2071 rb.Push(result);
2072 rb.PushRaw(handle);
2073} 1160}
2074 1161
2075void IHidServer::InitializePalma(HLERequestContext& ctx) { 1162Result IHidServer::InitializePalma(Palma::PalmaConnectionHandle connection_handle) {
2076 IPC::RequestParser rp{ctx};
2077 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2078
2079 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1163 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2080 1164
2081 auto controller = GetResourceManager()->GetPalma(); 1165 R_RETURN(GetResourceManager()->GetPalma()->InitializePalma(connection_handle));
2082 const auto result = controller->InitializePalma(connection_handle);
2083
2084 IPC::ResponseBuilder rb{ctx, 2};
2085 rb.Push(result);
2086} 1166}
2087 1167
2088void IHidServer::AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx) { 1168Result IHidServer::AcquirePalmaOperationCompleteEvent(
2089 IPC::RequestParser rp{ctx}; 1169 OutCopyHandle<Kernel::KReadableEvent> out_event,
2090 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()}; 1170 Palma::PalmaConnectionHandle connection_handle) {
2091
2092 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1171 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2093 1172
2094 auto controller = GetResourceManager()->GetPalma(); 1173 *out_event =
2095 1174 &GetResourceManager()->GetPalma()->AcquirePalmaOperationCompleteEvent(connection_handle);
2096 IPC::ResponseBuilder rb{ctx, 2, 1}; 1175 R_SUCCEED();
2097 rb.Push(ResultSuccess);
2098 rb.PushCopyObjects(controller->AcquirePalmaOperationCompleteEvent(connection_handle));
2099} 1176}
2100 1177
2101void IHidServer::GetPalmaOperationInfo(HLERequestContext& ctx) { 1178Result IHidServer::GetPalmaOperationInfo(Out<Palma::PalmaOperationType> out_operation_type,
2102 IPC::RequestParser rp{ctx}; 1179 Palma::PalmaConnectionHandle connection_handle,
2103 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()}; 1180 OutBuffer<BufferAttr_HipcMapAlias> out_data) {
2104
2105 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1181 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2106 1182
2107 Palma::PalmaOperationType operation_type; 1183 R_RETURN(GetResourceManager()->GetPalma()->GetPalmaOperationInfo(
2108 Palma::PalmaOperationData data; 1184 connection_handle, *out_operation_type, out_data));
2109 auto controller = GetResourceManager()->GetPalma();
2110 const auto result = controller->GetPalmaOperationInfo(connection_handle, operation_type, data);
2111
2112 if (result.IsError()) {
2113 IPC::ResponseBuilder rb{ctx, 2};
2114 rb.Push(result);
2115 }
2116
2117 ctx.WriteBuffer(data);
2118 IPC::ResponseBuilder rb{ctx, 4};
2119 rb.Push(result);
2120 rb.Push(static_cast<u64>(operation_type));
2121} 1185}
2122 1186
2123void IHidServer::PlayPalmaActivity(HLERequestContext& ctx) { 1187Result IHidServer::PlayPalmaActivity(Palma::PalmaConnectionHandle connection_handle,
2124 IPC::RequestParser rp{ctx}; 1188 u64 palma_activity) {
2125 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2126 const auto palma_activity{rp.Pop<u64>()};
2127
2128 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, palma_activity={}", 1189 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, palma_activity={}",
2129 connection_handle.npad_id, palma_activity); 1190 connection_handle.npad_id, palma_activity);
2130 1191
2131 auto controller = GetResourceManager()->GetPalma(); 1192 R_RETURN(
2132 const auto result = controller->PlayPalmaActivity(connection_handle, palma_activity); 1193 GetResourceManager()->GetPalma()->PlayPalmaActivity(connection_handle, palma_activity));
2133
2134 IPC::ResponseBuilder rb{ctx, 2};
2135 rb.Push(result);
2136} 1194}
2137 1195
2138void IHidServer::SetPalmaFrModeType(HLERequestContext& ctx) { 1196Result IHidServer::SetPalmaFrModeType(Palma::PalmaConnectionHandle connection_handle,
2139 IPC::RequestParser rp{ctx}; 1197 Palma::PalmaFrModeType fr_mode) {
2140 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2141 const auto fr_mode{rp.PopEnum<Palma::PalmaFrModeType>()};
2142
2143 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, fr_mode={}", 1198 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, fr_mode={}",
2144 connection_handle.npad_id, fr_mode); 1199 connection_handle.npad_id, fr_mode);
2145 1200
2146 auto controller = GetResourceManager()->GetPalma(); 1201 R_RETURN(GetResourceManager()->GetPalma()->SetPalmaFrModeType(connection_handle, fr_mode));
2147 const auto result = controller->SetPalmaFrModeType(connection_handle, fr_mode);
2148
2149 IPC::ResponseBuilder rb{ctx, 2};
2150 rb.Push(result);
2151} 1202}
2152 1203
2153void IHidServer::ReadPalmaStep(HLERequestContext& ctx) { 1204Result IHidServer::ReadPalmaStep(Palma::PalmaConnectionHandle connection_handle) {
2154 IPC::RequestParser rp{ctx};
2155 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2156
2157 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1205 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2158 1206
2159 auto controller = GetResourceManager()->GetPalma(); 1207 R_RETURN(GetResourceManager()->GetPalma()->ReadPalmaStep(connection_handle));
2160 const auto result = controller->ReadPalmaStep(connection_handle);
2161
2162 IPC::ResponseBuilder rb{ctx, 2};
2163 rb.Push(result);
2164} 1208}
2165 1209
2166void IHidServer::EnablePalmaStep(HLERequestContext& ctx) { 1210Result IHidServer::EnablePalmaStep(bool is_enabled,
2167 IPC::RequestParser rp{ctx}; 1211 Palma::PalmaConnectionHandle connection_handle) {
2168 struct Parameters {
2169 bool is_enabled;
2170 INSERT_PADDING_WORDS_NOINIT(1);
2171 Palma::PalmaConnectionHandle connection_handle;
2172 };
2173 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
2174
2175 const auto parameters{rp.PopRaw<Parameters>()};
2176
2177 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, is_enabled={}", 1212 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, is_enabled={}",
2178 parameters.connection_handle.npad_id, parameters.is_enabled); 1213 connection_handle.npad_id, is_enabled);
2179 1214
2180 auto controller = GetResourceManager()->GetPalma(); 1215 R_RETURN(GetResourceManager()->GetPalma()->EnablePalmaStep(connection_handle, is_enabled));
2181 const auto result =
2182 controller->EnablePalmaStep(parameters.connection_handle, parameters.is_enabled);
2183
2184 IPC::ResponseBuilder rb{ctx, 2};
2185 rb.Push(result);
2186} 1216}
2187 1217
2188void IHidServer::ResetPalmaStep(HLERequestContext& ctx) { 1218Result IHidServer::ResetPalmaStep(Palma::PalmaConnectionHandle connection_handle) {
2189 IPC::RequestParser rp{ctx};
2190 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2191
2192 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1219 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2193 1220
2194 auto controller = GetResourceManager()->GetPalma(); 1221 R_RETURN(GetResourceManager()->GetPalma()->ResetPalmaStep(connection_handle));
2195 const auto result = controller->ResetPalmaStep(connection_handle);
2196
2197 IPC::ResponseBuilder rb{ctx, 2};
2198 rb.Push(result);
2199} 1222}
2200 1223
2201void IHidServer::ReadPalmaApplicationSection(HLERequestContext& ctx) { 1224Result IHidServer::ReadPalmaApplicationSection(Palma::PalmaConnectionHandle connection_handle,
2202 LOG_WARNING(Service_HID, "(STUBBED) called"); 1225 u64 offset, u64 size) {
2203 1226 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, offset={}, size={}",
2204 IPC::ResponseBuilder rb{ctx, 2}; 1227 connection_handle.npad_id, offset, size);
2205 rb.Push(ResultSuccess); 1228 R_SUCCEED();
2206} 1229}
2207 1230
2208void IHidServer::WritePalmaApplicationSection(HLERequestContext& ctx) { 1231Result IHidServer::WritePalmaApplicationSection(
2209 LOG_WARNING(Service_HID, "(STUBBED) called"); 1232 Palma::PalmaConnectionHandle connection_handle, u64 offset, u64 size,
2210 1233 InLargeData<Palma::PalmaApplicationSection, BufferAttr_HipcPointer> data) {
2211 IPC::ResponseBuilder rb{ctx, 2}; 1234 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, offset={}, size={}",
2212 rb.Push(ResultSuccess); 1235 connection_handle.npad_id, offset, size);
1236 R_SUCCEED();
2213} 1237}
2214 1238
2215void IHidServer::ReadPalmaUniqueCode(HLERequestContext& ctx) { 1239Result IHidServer::ReadPalmaUniqueCode(Palma::PalmaConnectionHandle connection_handle) {
2216 IPC::RequestParser rp{ctx};
2217 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2218
2219 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1240 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2220 1241
2221 GetResourceManager()->GetPalma()->ReadPalmaUniqueCode(connection_handle); 1242 GetResourceManager()->GetPalma()->ReadPalmaUniqueCode(connection_handle);
2222 1243 R_SUCCEED();
2223 IPC::ResponseBuilder rb{ctx, 2};
2224 rb.Push(ResultSuccess);
2225} 1244}
2226 1245
2227void IHidServer::SetPalmaUniqueCodeInvalid(HLERequestContext& ctx) { 1246Result IHidServer::SetPalmaUniqueCodeInvalid(Palma::PalmaConnectionHandle connection_handle) {
2228 IPC::RequestParser rp{ctx};
2229 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2230
2231 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1247 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2232 1248
2233 GetResourceManager()->GetPalma()->SetPalmaUniqueCodeInvalid(connection_handle); 1249 GetResourceManager()->GetPalma()->SetPalmaUniqueCodeInvalid(connection_handle);
2234 1250 R_SUCCEED();
2235 IPC::ResponseBuilder rb{ctx, 2};
2236 rb.Push(ResultSuccess);
2237} 1251}
2238 1252
2239void IHidServer::WritePalmaActivityEntry(HLERequestContext& ctx) { 1253Result IHidServer::WritePalmaActivityEntry(Palma::PalmaConnectionHandle connection_handle,
2240 LOG_CRITICAL(Service_HID, "(STUBBED) called"); 1254 Palma::PalmaActivityEntry activity_entry) {
2241 1255 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2242 IPC::ResponseBuilder rb{ctx, 2}; 1256 R_SUCCEED();
2243 rb.Push(ResultSuccess);
2244} 1257}
2245 1258
2246void IHidServer::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { 1259Result IHidServer::WritePalmaRgbLedPatternEntry(Palma::PalmaConnectionHandle connection_handle,
2247 IPC::RequestParser rp{ctx}; 1260 u64 unknown,
2248 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()}; 1261 InBuffer<BufferAttr_HipcMapAlias> led_pattern) {
2249 const auto unknown{rp.Pop<u64>()};
2250
2251 [[maybe_unused]] const auto buffer = ctx.ReadBuffer();
2252
2253 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}", 1262 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}",
2254 connection_handle.npad_id, unknown); 1263 connection_handle.npad_id, unknown);
2255 1264
2256 GetResourceManager()->GetPalma()->WritePalmaRgbLedPatternEntry(connection_handle, unknown); 1265 GetResourceManager()->GetPalma()->WritePalmaRgbLedPatternEntry(connection_handle, unknown);
2257 1266 R_SUCCEED();
2258 IPC::ResponseBuilder rb{ctx, 2};
2259 rb.Push(ResultSuccess);
2260} 1267}
2261 1268
2262void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) { 1269Result IHidServer::WritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle,
2263 IPC::RequestParser rp{ctx}; 1270 Palma::PalmaWaveSet wave_set, u64 unknown, u64 t_mem_size,
2264 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()}; 1271 u64 size, InCopyHandle<Kernel::KTransferMemory> t_mem) {
2265 const auto wave_set{rp.PopEnum<Palma::PalmaWaveSet>()}; 1272 ASSERT_MSG(t_mem->GetSize() == t_mem_size, "t_mem has incorrect size");
2266 const auto unknown{rp.Pop<u64>()};
2267 const auto t_mem_size{rp.Pop<u64>()};
2268 const auto t_mem_handle{ctx.GetCopyHandle(0)};
2269 const auto size{rp.Pop<u64>()};
2270
2271 ASSERT_MSG(t_mem_size == 0x3000, "t_mem_size is not 0x3000 bytes");
2272
2273 auto t_mem = ctx.GetObjectFromHandle<Kernel::KTransferMemory>(t_mem_handle);
2274
2275 if (t_mem.IsNull()) {
2276 LOG_ERROR(Service_HID, "t_mem is a nullptr for handle=0x{:08X}", t_mem_handle);
2277 IPC::ResponseBuilder rb{ctx, 2};
2278 rb.Push(ResultUnknown);
2279 return;
2280 }
2281
2282 ASSERT_MSG(t_mem->GetSize() == 0x3000, "t_mem has incorrect size");
2283 1273
2284 LOG_WARNING(Service_HID, 1274 LOG_WARNING(
2285 "(STUBBED) called, connection_handle={}, wave_set={}, unknown={}, " 1275 Service_HID,
2286 "t_mem_handle=0x{:08X}, t_mem_size={}, size={}", 1276 "(STUBBED) called, connection_handle={}, wave_set={}, unknown={}, t_mem_size={}, size={}",
2287 connection_handle.npad_id, wave_set, unknown, t_mem_handle, t_mem_size, size); 1277 connection_handle.npad_id, wave_set, unknown, t_mem_size, size);
2288 1278
2289 GetResourceManager()->GetPalma()->WritePalmaWaveEntry(connection_handle, wave_set, 1279 GetResourceManager()->GetPalma()->WritePalmaWaveEntry(connection_handle, wave_set,
2290 t_mem->GetSourceAddress(), t_mem_size); 1280 t_mem->GetSourceAddress(), t_mem_size);
2291 1281 R_SUCCEED();
2292 IPC::ResponseBuilder rb{ctx, 2};
2293 rb.Push(ResultSuccess);
2294} 1282}
2295 1283
2296void IHidServer::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { 1284Result IHidServer::SetPalmaDataBaseIdentificationVersion(
2297 IPC::RequestParser rp{ctx}; 1285 s32 database_id_version, Palma::PalmaConnectionHandle connection_handle) {
2298 struct Parameters {
2299 s32 database_id_version;
2300 INSERT_PADDING_WORDS_NOINIT(1);
2301 Palma::PalmaConnectionHandle connection_handle;
2302 };
2303 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
2304
2305 const auto parameters{rp.PopRaw<Parameters>()};
2306
2307 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, database_id_version={}", 1286 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, database_id_version={}",
2308 parameters.connection_handle.npad_id, parameters.database_id_version); 1287 connection_handle.npad_id, database_id_version);
2309 1288
2310 GetResourceManager()->GetPalma()->SetPalmaDataBaseIdentificationVersion( 1289 GetResourceManager()->GetPalma()->SetPalmaDataBaseIdentificationVersion(connection_handle,
2311 parameters.connection_handle, parameters.database_id_version); 1290 database_id_version);
2312 1291 R_SUCCEED();
2313 IPC::ResponseBuilder rb{ctx, 2};
2314 rb.Push(ResultSuccess);
2315} 1292}
2316 1293
2317void IHidServer::GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { 1294Result IHidServer::GetPalmaDataBaseIdentificationVersion(
2318 IPC::RequestParser rp{ctx}; 1295 Palma::PalmaConnectionHandle connection_handle) {
2319 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2320
2321 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1296 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2322 1297
2323 GetResourceManager()->GetPalma()->GetPalmaDataBaseIdentificationVersion(connection_handle); 1298 R_RETURN(
2324 1299 GetResourceManager()->GetPalma()->GetPalmaDataBaseIdentificationVersion(connection_handle));
2325 IPC::ResponseBuilder rb{ctx, 2};
2326 rb.Push(ResultSuccess);
2327} 1300}
2328 1301
2329void IHidServer::SuspendPalmaFeature(HLERequestContext& ctx) { 1302Result IHidServer::SuspendPalmaFeature(Palma::PalmaFeature feature,
2330 LOG_WARNING(Service_HID, "(STUBBED) called"); 1303 Palma::PalmaConnectionHandle connection_handle) {
2331 1304 LOG_WARNING(Service_HID, "(STUBBED) called, feature={}, connection_handle={}", feature,
2332 IPC::ResponseBuilder rb{ctx, 2}; 1305 connection_handle.npad_id);
2333 rb.Push(ResultSuccess); 1306 R_SUCCEED();
2334} 1307}
2335 1308
2336void IHidServer::GetPalmaOperationResult(HLERequestContext& ctx) { 1309Result IHidServer::GetPalmaOperationResult(Palma::PalmaConnectionHandle connection_handle) {
2337 IPC::RequestParser rp{ctx};
2338 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2339
2340 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1310 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2341 1311
2342 const auto result = 1312 R_RETURN(GetResourceManager()->GetPalma()->GetPalmaOperationResult(connection_handle));
2343 GetResourceManager()->GetPalma()->GetPalmaOperationResult(connection_handle);
2344
2345 IPC::ResponseBuilder rb{ctx, 2};
2346 rb.Push(result);
2347} 1313}
2348 1314
2349void IHidServer::ReadPalmaPlayLog(HLERequestContext& ctx) { 1315Result IHidServer::ReadPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle) {
2350 LOG_WARNING(Service_HID, "(STUBBED) called"); 1316 LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, connection_handle={}", unknown,
2351 1317 connection_handle.npad_id);
2352 IPC::ResponseBuilder rb{ctx, 2}; 1318 R_SUCCEED();
2353 rb.Push(ResultSuccess);
2354} 1319}
2355 1320
2356void IHidServer::ResetPalmaPlayLog(HLERequestContext& ctx) { 1321Result IHidServer::ResetPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle) {
2357 LOG_WARNING(Service_HID, "(STUBBED) called"); 1322 LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, connection_handle={}", unknown,
2358 1323 connection_handle.npad_id);
2359 IPC::ResponseBuilder rb{ctx, 2}; 1324 R_SUCCEED();
2360 rb.Push(ResultSuccess);
2361} 1325}
2362 1326
2363void IHidServer::SetIsPalmaAllConnectable(HLERequestContext& ctx) { 1327Result IHidServer::SetIsPalmaAllConnectable(bool is_palma_all_connectable,
2364 IPC::RequestParser rp{ctx}; 1328 ClientAppletResourceUserId aruid) {
2365 struct Parameters {
2366 bool is_palma_all_connectable;
2367 INSERT_PADDING_BYTES_NOINIT(7);
2368 u64 applet_resource_user_id;
2369 };
2370 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
2371
2372 const auto parameters{rp.PopRaw<Parameters>()};
2373
2374 LOG_WARNING(Service_HID, 1329 LOG_WARNING(Service_HID,
2375 "(STUBBED) called, is_palma_all_connectable={},applet_resource_user_id={}", 1330 "(STUBBED) called, is_palma_all_connectable={}, applet_resource_user_id={}",
2376 parameters.is_palma_all_connectable, parameters.applet_resource_user_id); 1331 is_palma_all_connectable, aruid.pid);
2377
2378 GetResourceManager()->GetPalma()->SetIsPalmaAllConnectable(parameters.is_palma_all_connectable);
2379 1332
2380 IPC::ResponseBuilder rb{ctx, 2}; 1333 GetResourceManager()->GetPalma()->SetIsPalmaAllConnectable(is_palma_all_connectable);
2381 rb.Push(ResultSuccess); 1334 R_SUCCEED();
2382} 1335}
2383 1336
2384void IHidServer::SetIsPalmaPairedConnectable(HLERequestContext& ctx) { 1337Result IHidServer::SetIsPalmaPairedConnectable(bool is_palma_paired_connectable,
2385 LOG_WARNING(Service_HID, "(STUBBED) called"); 1338 ClientAppletResourceUserId aruid) {
2386 1339 LOG_WARNING(Service_HID,
2387 IPC::ResponseBuilder rb{ctx, 2}; 1340 "(STUBBED) called, is_palma_paired_connectable={}, applet_resource_user_id={}",
2388 rb.Push(ResultSuccess); 1341 is_palma_paired_connectable, aruid.pid);
1342 R_SUCCEED();
2389} 1343}
2390 1344
2391void IHidServer::PairPalma(HLERequestContext& ctx) { 1345Result IHidServer::PairPalma(Palma::PalmaConnectionHandle connection_handle) {
2392 IPC::RequestParser rp{ctx};
2393 const auto connection_handle{rp.PopRaw<Palma::PalmaConnectionHandle>()};
2394
2395 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); 1346 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2396 1347
2397 GetResourceManager()->GetPalma()->PairPalma(connection_handle); 1348 GetResourceManager()->GetPalma()->PairPalma(connection_handle);
2398 1349 R_SUCCEED();
2399 IPC::ResponseBuilder rb{ctx, 2};
2400 rb.Push(ResultSuccess);
2401} 1350}
2402 1351
2403void IHidServer::SetPalmaBoostMode(HLERequestContext& ctx) { 1352Result IHidServer::SetPalmaBoostMode(bool is_enabled) {
2404 IPC::RequestParser rp{ctx}; 1353 LOG_WARNING(Service_HID, "(STUBBED) called, is_enabled={}", is_enabled);
2405 const auto palma_boost_mode{rp.Pop<bool>()};
2406
2407 LOG_WARNING(Service_HID, "(STUBBED) called, palma_boost_mode={}", palma_boost_mode);
2408
2409 GetResourceManager()->GetPalma()->SetPalmaBoostMode(palma_boost_mode);
2410 1354
2411 IPC::ResponseBuilder rb{ctx, 2}; 1355 GetResourceManager()->GetPalma()->SetPalmaBoostMode(is_enabled);
2412 rb.Push(ResultSuccess); 1356 R_SUCCEED();
2413} 1357}
2414 1358
2415void IHidServer::CancelWritePalmaWaveEntry(HLERequestContext& ctx) { 1359Result IHidServer::CancelWritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle) {
2416 LOG_WARNING(Service_HID, "(STUBBED) called"); 1360 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2417 1361 R_SUCCEED();
2418 IPC::ResponseBuilder rb{ctx, 2};
2419 rb.Push(ResultSuccess);
2420} 1362}
2421 1363
2422void IHidServer::EnablePalmaBoostMode(HLERequestContext& ctx) { 1364Result IHidServer::EnablePalmaBoostMode(bool is_enabled, ClientAppletResourceUserId aruid) {
2423 LOG_WARNING(Service_HID, "(STUBBED) called"); 1365 LOG_WARNING(Service_HID, "(STUBBED) called, is_enabled={}, applet_resource_user_id={}",
2424 1366 is_enabled, aruid.pid);
2425 IPC::ResponseBuilder rb{ctx, 2}; 1367 R_SUCCEED();
2426 rb.Push(ResultSuccess);
2427} 1368}
2428 1369
2429void IHidServer::GetPalmaBluetoothAddress(HLERequestContext& ctx) { 1370Result IHidServer::GetPalmaBluetoothAddress(Out<Palma::Address> out_bt_address,
2430 LOG_WARNING(Service_HID, "(STUBBED) called"); 1371 Palma::PalmaConnectionHandle connection_handle) {
2431 1372 LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id);
2432 IPC::ResponseBuilder rb{ctx, 2}; 1373 R_SUCCEED();
2433 rb.Push(ResultSuccess);
2434} 1374}
2435 1375
2436void IHidServer::SetDisallowedPalmaConnection(HLERequestContext& ctx) { 1376Result IHidServer::SetDisallowedPalmaConnection(
2437 LOG_WARNING(Service_HID, "(STUBBED) called"); 1377 ClientAppletResourceUserId aruid,
2438 1378 InArray<Palma::Address, BufferAttr_HipcPointer> disallowed_address) {
2439 IPC::ResponseBuilder rb{ctx, 2}; 1379 LOG_DEBUG(Service_HID, "(STUBBED) called, applet_resource_user_id={}", aruid.pid);
2440 rb.Push(ResultSuccess); 1380 R_SUCCEED();
2441} 1381}
2442 1382
2443void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) { 1383Result IHidServer::SetNpadCommunicationMode(ClientAppletResourceUserId aruid,
2444 IPC::RequestParser rp{ctx}; 1384 NpadCommunicationMode communication_mode) {
2445 const auto applet_resource_user_id{rp.Pop<u64>()}; 1385 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}", aruid.pid,
2446 const auto communication_mode{rp.PopEnum<NpadCommunicationMode>()}; 1386 communication_mode);
2447
2448 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, communication_mode={}",
2449 applet_resource_user_id, communication_mode);
2450 1387
2451 // This function has been stubbed since 2.0.0+ 1388 // This function has been stubbed since 2.0.0+
2452 1389 R_SUCCEED();
2453 IPC::ResponseBuilder rb{ctx, 2};
2454 rb.Push(ResultSuccess);
2455} 1390}
2456 1391
2457void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) { 1392Result IHidServer::GetNpadCommunicationMode(Out<NpadCommunicationMode> out_communication_mode,
2458 IPC::RequestParser rp{ctx}; 1393 ClientAppletResourceUserId aruid) {
2459 const auto applet_resource_user_id{rp.Pop<u64>()}; 1394 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", aruid.pid);
2460
2461 LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id);
2462 1395
2463 // This function has been stubbed since 2.0.0+ 1396 // This function has been stubbed since 2.0.0+
2464 1397 *out_communication_mode = NpadCommunicationMode::Default;
2465 IPC::ResponseBuilder rb{ctx, 4}; 1398 R_SUCCEED();
2466 rb.Push(ResultSuccess);
2467 rb.PushEnum(NpadCommunicationMode::Default);
2468} 1399}
2469 1400
2470void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) { 1401Result IHidServer::SetTouchScreenConfiguration(
2471 IPC::RequestParser rp{ctx}; 1402 Core::HID::TouchScreenConfigurationForNx touchscreen_config, ClientAppletResourceUserId aruid) {
2472 auto touchscreen_config{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()};
2473 const auto applet_resource_user_id{rp.Pop<u64>()};
2474
2475 LOG_INFO(Service_HID, "called, touchscreen_config={}, applet_resource_user_id={}", 1403 LOG_INFO(Service_HID, "called, touchscreen_config={}, applet_resource_user_id={}",
2476 touchscreen_config.mode, applet_resource_user_id); 1404 touchscreen_config.mode, aruid.pid);
2477 1405
2478 if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && 1406 if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 &&
2479 touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { 1407 touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) {
2480 touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; 1408 touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting;
2481 } 1409 }
2482 1410
2483 const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration( 1411 R_RETURN(GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration(touchscreen_config,
2484 touchscreen_config, applet_resource_user_id); 1412 aruid.pid));
2485
2486 IPC::ResponseBuilder rb{ctx, 2};
2487 rb.Push(result);
2488} 1413}
2489 1414
2490void IHidServer::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) { 1415Result IHidServer::IsFirmwareUpdateNeededForNotification(Out<bool> out_is_firmware_update_needed,
2491 IPC::RequestParser rp{ctx}; 1416 s32 unknown,
2492 struct Parameters { 1417 ClientAppletResourceUserId aruid) {
2493 s32 unknown; 1418 LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", unknown,
2494 INSERT_PADDING_WORDS_NOINIT(1); 1419 aruid.pid);
2495 u64 applet_resource_user_id;
2496 };
2497 static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size.");
2498
2499 const auto parameters{rp.PopRaw<Parameters>()};
2500 1420
2501 LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", 1421 *out_is_firmware_update_needed = false;
2502 parameters.unknown, parameters.applet_resource_user_id); 1422 R_SUCCEED();
2503
2504 IPC::ResponseBuilder rb{ctx, 3};
2505 rb.Push(ResultSuccess);
2506 rb.Push(false);
2507} 1423}
2508 1424
2509void IHidServer::SetTouchScreenResolution(HLERequestContext& ctx) { 1425Result IHidServer::SetTouchScreenResolution(u32 width, u32 height,
2510 IPC::RequestParser rp{ctx}; 1426 ClientAppletResourceUserId aruid) {
2511 const auto width{rp.Pop<u32>()};
2512 const auto height{rp.Pop<u32>()};
2513 const auto applet_resource_user_id{rp.Pop<u64>()};
2514
2515 LOG_INFO(Service_HID, "called, width={}, height={}, applet_resource_user_id={}", width, height, 1427 LOG_INFO(Service_HID, "called, width={}, height={}, applet_resource_user_id={}", width, height,
2516 applet_resource_user_id); 1428 aruid.pid);
2517
2518 GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height,
2519 applet_resource_user_id);
2520 1429
2521 IPC::ResponseBuilder rb{ctx, 2}; 1430 GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height, aruid.pid);
2522 rb.Push(ResultSuccess); 1431 R_SUCCEED();
2523} 1432}
2524 1433
2525std::shared_ptr<ResourceManager> IHidServer::GetResourceManager() { 1434std::shared_ptr<ResourceManager> IHidServer::GetResourceManager() {
diff --git a/src/core/hle/service/hid/hid_server.h b/src/core/hle/service/hid/hid_server.h
index faf775689..cfa31c2de 100755
--- a/src/core/hle/service/hid/hid_server.h
+++ b/src/core/hle/service/hid/hid_server.h
@@ -6,12 +6,20 @@
6#include "core/hle/service/cmif_types.h" 6#include "core/hle/service/cmif_types.h"
7#include "core/hle/service/service.h" 7#include "core/hle/service/service.h"
8#include "hid_core/hid_types.h" 8#include "hid_core/hid_types.h"
9#include "hid_core/resources/npad/npad_types.h"
10#include "hid_core/resources/palma/palma.h"
9 11
10namespace Core { 12namespace Core {
11class System; 13class System;
12} 14}
13 15
16namespace Kernel {
17class KReadableEvent;
18}
19
14namespace Service::HID { 20namespace Service::HID {
21class IActiveVibrationDeviceList;
22class IAppletResource;
15class ResourceManager; 23class ResourceManager;
16class HidFirmwareSettings; 24class HidFirmwareSettings;
17 25
@@ -24,128 +32,232 @@ public:
24 std::shared_ptr<ResourceManager> GetResourceManager(); 32 std::shared_ptr<ResourceManager> GetResourceManager();
25 33
26private: 34private:
27 void CreateAppletResource(HLERequestContext& ctx); 35 Result CreateAppletResource(OutInterface<IAppletResource> out_applet_resource,
28 void ActivateDebugPad(HLERequestContext& ctx); 36 ClientAppletResourceUserId aruid);
29 void ActivateTouchScreen(HLERequestContext& ctx); 37 Result ActivateDebugPad(ClientAppletResourceUserId aruid);
30 void ActivateMouse(HLERequestContext& ctx); 38 Result ActivateTouchScreen(ClientAppletResourceUserId aruid);
31 void ActivateKeyboard(HLERequestContext& ctx); 39 Result ActivateMouse(ClientAppletResourceUserId aruid);
32 void SendKeyboardLockKeyEvent(HLERequestContext& ctx); 40 Result ActivateKeyboard(ClientAppletResourceUserId aruid);
33 void AcquireXpadIdEventHandle(HLERequestContext& ctx); 41 Result SendKeyboardLockKeyEvent(u32 flags);
34 void ReleaseXpadIdEventHandle(HLERequestContext& ctx); 42 Result AcquireXpadIdEventHandle(OutCopyHandle<Kernel::KReadableEvent> out_event,
35 void ActivateXpad(HLERequestContext& ctx); 43 ClientAppletResourceUserId aruid);
36 void GetXpadIds(HLERequestContext& ctx); 44 Result ReleaseXpadIdEventHandle(ClientAppletResourceUserId aruid);
37 void ActivateJoyXpad(HLERequestContext& ctx); 45 Result ActivateXpad(u32 basic_xpad_id, ClientAppletResourceUserId aruid);
38 void GetJoyXpadLifoHandle(HLERequestContext& ctx); 46 Result GetXpadIds(Out<u64> out_count, OutArray<u32, BufferAttr_HipcPointer> out_basic_pad_ids);
39 void GetJoyXpadIds(HLERequestContext& ctx); 47 Result ActivateJoyXpad(u32 joy_xpad_id);
40 void ActivateSixAxisSensor(HLERequestContext& ctx); 48 Result GetJoyXpadLifoHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle,
41 void DeactivateSixAxisSensor(HLERequestContext& ctx); 49 u32 joy_xpad_id);
42 void GetSixAxisSensorLifoHandle(HLERequestContext& ctx); 50 Result GetJoyXpadIds(Out<s64> out_basic_xpad_id_count);
43 void ActivateJoySixAxisSensor(HLERequestContext& ctx); 51 Result ActivateSixAxisSensor(u32 joy_xpad_id);
44 void DeactivateJoySixAxisSensor(HLERequestContext& ctx); 52 Result DeactivateSixAxisSensor(u32 joy_xpad_id);
45 void GetJoySixAxisSensorLifoHandle(HLERequestContext& ctx); 53 Result GetSixAxisSensorLifoHandle(OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle,
46 void StartSixAxisSensor(HLERequestContext& ctx); 54 u32 joy_xpad_id);
47 void StopSixAxisSensor(HLERequestContext& ctx); 55 Result ActivateJoySixAxisSensor(u32 joy_xpad_id);
48 void IsSixAxisSensorFusionEnabled(HLERequestContext& ctx); 56 Result DeactivateJoySixAxisSensor(u32 joy_xpad_id);
49 void EnableSixAxisSensorFusion(HLERequestContext& ctx); 57 Result GetJoySixAxisSensorLifoHandle(
50 void SetSixAxisSensorFusionParameters(HLERequestContext& ctx); 58 OutCopyHandle<Kernel::KSharedMemory> out_shared_memory_handle, u32 joy_xpad_id);
51 void GetSixAxisSensorFusionParameters(HLERequestContext& ctx); 59 Result StartSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle,
52 void ResetSixAxisSensorFusionParameters(HLERequestContext& ctx); 60 ClientAppletResourceUserId aruid);
53 void SetGyroscopeZeroDriftMode(HLERequestContext& ctx); 61 Result StopSixAxisSensor(Core::HID::SixAxisSensorHandle sixaxis_handle,
54 void GetGyroscopeZeroDriftMode(HLERequestContext& ctx); 62 ClientAppletResourceUserId aruid);
55 void ResetGyroscopeZeroDriftMode(HLERequestContext& ctx); 63 Result IsSixAxisSensorFusionEnabled(Out<bool> out_is_enabled,
56 void IsSixAxisSensorAtRest(HLERequestContext& ctx); 64 Core::HID::SixAxisSensorHandle sixaxis_handle,
57 void IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx); 65 ClientAppletResourceUserId aruid);
58 void EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx); 66 Result EnableSixAxisSensorFusion(bool is_enabled, Core::HID::SixAxisSensorHandle sixaxis_handle,
59 void IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& ctx); 67 ClientAppletResourceUserId aruid);
60 void LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx); 68 Result SetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle,
61 void GetSixAxisSensorIcInformation(HLERequestContext& ctx); 69 Core::HID::SixAxisSensorFusionParameters sixaxis_fusion,
62 void ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx); 70 ClientAppletResourceUserId aruid);
63 void ActivateGesture(HLERequestContext& ctx); 71 Result GetSixAxisSensorFusionParameters(
64 void SetSupportedNpadStyleSet(HLERequestContext& ctx); 72 Out<Core::HID::SixAxisSensorFusionParameters> out_fusion_parameters,
65 void GetSupportedNpadStyleSet(HLERequestContext& ctx); 73 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid);
66 void SetSupportedNpadIdType(HLERequestContext& ctx); 74 Result ResetSixAxisSensorFusionParameters(Core::HID::SixAxisSensorHandle sixaxis_handle,
67 void ActivateNpad(HLERequestContext& ctx); 75 ClientAppletResourceUserId aruid);
68 void DeactivateNpad(HLERequestContext& ctx); 76 Result SetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
69 void AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx); 77 Core::HID::GyroscopeZeroDriftMode drift_mode,
70 void DisconnectNpad(HLERequestContext& ctx); 78 ClientAppletResourceUserId aruid);
79 Result GetGyroscopeZeroDriftMode(Out<Core::HID::GyroscopeZeroDriftMode> out_drift_mode,
80 Core::HID::SixAxisSensorHandle sixaxis_handle,
81 ClientAppletResourceUserId aruid);
82 Result ResetGyroscopeZeroDriftMode(Core::HID::SixAxisSensorHandle sixaxis_handle,
83 ClientAppletResourceUserId aruid);
84 Result IsSixAxisSensorAtRest(Out<bool> out_is_at_rest,
85 Core::HID::SixAxisSensorHandle sixaxis_handle,
86 ClientAppletResourceUserId aruid);
87 Result IsFirmwareUpdateAvailableForSixAxisSensor(Out<bool> out_is_firmware_available,
88 Core::HID::SixAxisSensorHandle sixaxis_handle,
89 ClientAppletResourceUserId aruid);
90 Result EnableSixAxisSensorUnalteredPassthrough(bool is_enabled,
91 Core::HID::SixAxisSensorHandle sixaxis_handle,
92 ClientAppletResourceUserId aruid);
93 Result IsSixAxisSensorUnalteredPassthroughEnabled(Out<bool> out_is_enabled,
94 Core::HID::SixAxisSensorHandle sixaxis_handle,
95 ClientAppletResourceUserId aruid);
96 Result LoadSixAxisSensorCalibrationParameter(
97 OutLargeData<Core::HID::SixAxisSensorCalibrationParameter, BufferAttr_HipcMapAlias>
98 out_calibration,
99 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid);
100 Result GetSixAxisSensorIcInformation(
101 OutLargeData<Core::HID::SixAxisSensorIcInformation, BufferAttr_HipcPointer>
102 out_ic_information,
103 Core::HID::SixAxisSensorHandle sixaxis_handle, ClientAppletResourceUserId aruid);
104 Result ResetIsSixAxisSensorDeviceNewlyAssigned(Core::HID::SixAxisSensorHandle sixaxis_handle,
105 ClientAppletResourceUserId aruid);
106 Result ActivateGesture(u32 basic_gesture_id, ClientAppletResourceUserId aruid);
107 Result SetSupportedNpadStyleSet(Core::HID::NpadStyleSet supported_style_set,
108 ClientAppletResourceUserId aruid);
109 Result GetSupportedNpadStyleSet(Out<Core::HID::NpadStyleSet> out_supported_style_set,
110 ClientAppletResourceUserId aruid);
111 Result SetSupportedNpadIdType(
112 ClientAppletResourceUserId aruid,
113 InArray<Core::HID::NpadIdType, BufferAttr_HipcPointer> supported_npad_list);
114 Result ActivateNpad(ClientAppletResourceUserId aruid);
115 Result DeactivateNpad(ClientAppletResourceUserId aruid);
116 Result AcquireNpadStyleSetUpdateEventHandle(OutCopyHandle<Kernel::KReadableEvent> out_event,
117 Core::HID::NpadIdType npad_id,
118 ClientAppletResourceUserId aruid, u64 unknown);
119 Result DisconnectNpad(Core::HID::NpadIdType npad_id, ClientAppletResourceUserId aruid);
71 Result GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern, 120 Result GetPlayerLedPattern(Out<Core::HID::LedPattern> out_led_pattern,
72 Core::HID::NpadIdType npad_id); 121 Core::HID::NpadIdType npad_id);
73 void ActivateNpadWithRevision(HLERequestContext& ctx); 122 Result ActivateNpadWithRevision(NpadRevision revision, ClientAppletResourceUserId aruid);
74 void SetNpadJoyHoldType(HLERequestContext& ctx); 123 Result SetNpadJoyHoldType(ClientAppletResourceUserId aruid, NpadJoyHoldType hold_type);
75 void GetNpadJoyHoldType(HLERequestContext& ctx); 124 Result GetNpadJoyHoldType(Out<NpadJoyHoldType> out_hold_type, ClientAppletResourceUserId aruid);
76 void SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx); 125 Result SetNpadJoyAssignmentModeSingleByDefault(Core::HID::NpadIdType npad_id,
77 void SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx); 126 ClientAppletResourceUserId aruid);
78 void SetNpadJoyAssignmentModeDual(HLERequestContext& ctx); 127 Result SetNpadJoyAssignmentModeSingle(Core::HID::NpadIdType npad_id,
79 void MergeSingleJoyAsDualJoy(HLERequestContext& ctx); 128 ClientAppletResourceUserId aruid,
80 void StartLrAssignmentMode(HLERequestContext& ctx); 129 NpadJoyDeviceType npad_joy_device_type);
81 void StopLrAssignmentMode(HLERequestContext& ctx); 130 Result SetNpadJoyAssignmentModeDual(Core::HID::NpadIdType npad_id,
82 void SetNpadHandheldActivationMode(HLERequestContext& ctx); 131 ClientAppletResourceUserId aruid);
83 void GetNpadHandheldActivationMode(HLERequestContext& ctx); 132 Result MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2,
84 void SwapNpadAssignment(HLERequestContext& ctx); 133 ClientAppletResourceUserId aruid);
85 void IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& ctx); 134 Result StartLrAssignmentMode(ClientAppletResourceUserId aruid);
86 void EnableUnintendedHomeButtonInputProtection(HLERequestContext& ctx); 135 Result StopLrAssignmentMode(ClientAppletResourceUserId aruid);
87 void SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext& ctx); 136 Result SetNpadHandheldActivationMode(ClientAppletResourceUserId aruid,
88 void SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx); 137 NpadHandheldActivationMode activation_mode);
89 void SetNpadCaptureButtonAssignment(HLERequestContext& ctx); 138 Result GetNpadHandheldActivationMode(Out<NpadHandheldActivationMode> out_activation_mode,
90 void ClearNpadCaptureButtonAssignment(HLERequestContext& ctx); 139 ClientAppletResourceUserId aruid);
91 void GetVibrationDeviceInfo(HLERequestContext& ctx); 140 Result SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2,
92 void SendVibrationValue(HLERequestContext& ctx); 141 ClientAppletResourceUserId aruid);
93 void GetActualVibrationValue(HLERequestContext& ctx); 142 Result IsUnintendedHomeButtonInputProtectionEnabled(Out<bool> out_is_enabled,
94 void CreateActiveVibrationDeviceList(HLERequestContext& ctx); 143 Core::HID::NpadIdType npad_id,
95 void PermitVibration(HLERequestContext& ctx); 144 ClientAppletResourceUserId aruid);
96 void IsVibrationPermitted(HLERequestContext& ctx); 145 Result EnableUnintendedHomeButtonInputProtection(bool is_enabled, Core::HID::NpadIdType npad_id,
97 void SendVibrationValues(HLERequestContext& ctx); 146 ClientAppletResourceUserId aruid);
98 void SendVibrationGcErmCommand(HLERequestContext& ctx); 147 Result SetNpadJoyAssignmentModeSingleWithDestination(Out<bool> out_is_reassigned,
99 void GetActualVibrationGcErmCommand(HLERequestContext& ctx); 148 Out<Core::HID::NpadIdType> out_new_npad_id,
100 void BeginPermitVibrationSession(HLERequestContext& ctx); 149 Core::HID::NpadIdType npad_id,
101 void EndPermitVibrationSession(HLERequestContext& ctx); 150 ClientAppletResourceUserId aruid,
102 void IsVibrationDeviceMounted(HLERequestContext& ctx); 151 NpadJoyDeviceType npad_joy_device_type);
103 void SendVibrationValueInBool(HLERequestContext& ctx); 152 Result SetNpadAnalogStickUseCenterClamp(bool use_center_clamp,
104 void ActivateConsoleSixAxisSensor(HLERequestContext& ctx); 153 ClientAppletResourceUserId aruid);
105 void StartConsoleSixAxisSensor(HLERequestContext& ctx); 154 Result SetNpadCaptureButtonAssignment(Core::HID::NpadStyleSet npad_styleset,
106 void StopConsoleSixAxisSensor(HLERequestContext& ctx); 155 ClientAppletResourceUserId aruid,
107 void ActivateSevenSixAxisSensor(HLERequestContext& ctx); 156 Core::HID::NpadButton button);
108 void StartSevenSixAxisSensor(HLERequestContext& ctx); 157 Result ClearNpadCaptureButtonAssignment(ClientAppletResourceUserId aruid);
109 void StopSevenSixAxisSensor(HLERequestContext& ctx); 158 Result GetVibrationDeviceInfo(Out<Core::HID::VibrationDeviceInfo> out_vibration_device_info,
110 void InitializeSevenSixAxisSensor(HLERequestContext& ctx); 159 Core::HID::VibrationDeviceHandle vibration_device_handle);
111 void FinalizeSevenSixAxisSensor(HLERequestContext& ctx); 160 Result SendVibrationValue(Core::HID::VibrationDeviceHandle vibration_device_handle,
112 void ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx); 161 Core::HID::VibrationValue vibration_value,
113 void IsUsbFullKeyControllerEnabled(HLERequestContext& ctx); 162 ClientAppletResourceUserId aruid);
114 void GetPalmaConnectionHandle(HLERequestContext& ctx); 163 Result GetActualVibrationValue(Out<Core::HID::VibrationValue> out_vibration_value,
115 void InitializePalma(HLERequestContext& ctx); 164 Core::HID::VibrationDeviceHandle vibration_device_handle,
116 void AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx); 165 ClientAppletResourceUserId aruid);
117 void GetPalmaOperationInfo(HLERequestContext& ctx); 166 Result CreateActiveVibrationDeviceList(OutInterface<IActiveVibrationDeviceList> out_interface);
118 void PlayPalmaActivity(HLERequestContext& ctx); 167 Result PermitVibration(bool can_vibrate);
119 void SetPalmaFrModeType(HLERequestContext& ctx); 168 Result IsVibrationPermitted(Out<bool> out_is_permitted);
120 void ReadPalmaStep(HLERequestContext& ctx); 169 Result SendVibrationValues(
121 void EnablePalmaStep(HLERequestContext& ctx); 170 ClientAppletResourceUserId aruid,
122 void ResetPalmaStep(HLERequestContext& ctx); 171 InArray<Core::HID::VibrationDeviceHandle, BufferAttr_HipcPointer> vibration_handles,
123 void ReadPalmaApplicationSection(HLERequestContext& ctx); 172 InArray<Core::HID::VibrationValue, BufferAttr_HipcPointer> vibration_values);
124 void WritePalmaApplicationSection(HLERequestContext& ctx); 173 Result SendVibrationGcErmCommand(Core::HID::VibrationDeviceHandle vibration_device_handle,
125 void ReadPalmaUniqueCode(HLERequestContext& ctx); 174 ClientAppletResourceUserId aruid,
126 void SetPalmaUniqueCodeInvalid(HLERequestContext& ctx); 175 Core::HID::VibrationGcErmCommand gc_erm_command);
127 void WritePalmaActivityEntry(HLERequestContext& ctx); 176 Result GetActualVibrationGcErmCommand(Out<Core::HID::VibrationGcErmCommand> out_gc_erm_command,
128 void WritePalmaRgbLedPatternEntry(HLERequestContext& ctx); 177 Core::HID::VibrationDeviceHandle vibration_device_handle,
129 void WritePalmaWaveEntry(HLERequestContext& ctx); 178 ClientAppletResourceUserId aruid);
130 void SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); 179 Result BeginPermitVibrationSession(ClientAppletResourceUserId aruid);
131 void GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx); 180 Result EndPermitVibrationSession(ClientAppletResourceUserId aruid);
132 void SuspendPalmaFeature(HLERequestContext& ctx); 181 Result IsVibrationDeviceMounted(Out<bool> out_is_mounted,
133 void GetPalmaOperationResult(HLERequestContext& ctx); 182 Core::HID::VibrationDeviceHandle vibration_device_handle,
134 void ReadPalmaPlayLog(HLERequestContext& ctx); 183 ClientAppletResourceUserId aruid);
135 void ResetPalmaPlayLog(HLERequestContext& ctx); 184 Result SendVibrationValueInBool(bool is_vibrating,
136 void SetIsPalmaAllConnectable(HLERequestContext& ctx); 185 Core::HID::VibrationDeviceHandle vibration_device_handle,
137 void SetIsPalmaPairedConnectable(HLERequestContext& ctx); 186 ClientAppletResourceUserId aruid);
138 void PairPalma(HLERequestContext& ctx); 187 Result ActivateConsoleSixAxisSensor(ClientAppletResourceUserId aruid);
139 void SetPalmaBoostMode(HLERequestContext& ctx); 188 Result StartConsoleSixAxisSensor(Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle,
140 void CancelWritePalmaWaveEntry(HLERequestContext& ctx); 189 ClientAppletResourceUserId aruid);
141 void EnablePalmaBoostMode(HLERequestContext& ctx); 190 Result StopConsoleSixAxisSensor(Core::HID::ConsoleSixAxisSensorHandle console_sixaxis_handle,
142 void GetPalmaBluetoothAddress(HLERequestContext& ctx); 191 ClientAppletResourceUserId aruid);
143 void SetDisallowedPalmaConnection(HLERequestContext& ctx); 192 Result ActivateSevenSixAxisSensor(ClientAppletResourceUserId aruid);
144 void SetNpadCommunicationMode(HLERequestContext& ctx); 193 Result StartSevenSixAxisSensor(ClientAppletResourceUserId aruid);
145 void GetNpadCommunicationMode(HLERequestContext& ctx); 194 Result StopSevenSixAxisSensor(ClientAppletResourceUserId aruid);
146 void SetTouchScreenConfiguration(HLERequestContext& ctx); 195 Result InitializeSevenSixAxisSensor(ClientAppletResourceUserId aruid, u64 t_mem_1_size,
147 void IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx); 196 u64 t_mem_2_size,
148 void SetTouchScreenResolution(HLERequestContext& ctx); 197 InCopyHandle<Kernel::KTransferMemory> t_mem_1,
198 InCopyHandle<Kernel::KTransferMemory> t_mem_2);
199 Result FinalizeSevenSixAxisSensor(ClientAppletResourceUserId aruid);
200 Result ResetSevenSixAxisSensorTimestamp(ClientAppletResourceUserId aruid);
201 Result IsUsbFullKeyControllerEnabled(Out<bool> out_is_enabled,
202 ClientAppletResourceUserId aruid);
203 Result GetPalmaConnectionHandle(Out<Palma::PalmaConnectionHandle> out_handle,
204 Core::HID::NpadIdType npad_id,
205 ClientAppletResourceUserId aruid);
206 Result InitializePalma(Palma::PalmaConnectionHandle connection_handle);
207 Result AcquirePalmaOperationCompleteEvent(OutCopyHandle<Kernel::KReadableEvent> out_event,
208 Palma::PalmaConnectionHandle connection_handle);
209 Result GetPalmaOperationInfo(Out<Palma::PalmaOperationType> out_operation_type,
210 Palma::PalmaConnectionHandle connection_handle,
211 OutBuffer<BufferAttr_HipcMapAlias> out_data);
212 Result PlayPalmaActivity(Palma::PalmaConnectionHandle connection_handle, u64 palma_activity);
213 Result SetPalmaFrModeType(Palma::PalmaConnectionHandle connection_handle,
214 Palma::PalmaFrModeType fr_mode);
215 Result ReadPalmaStep(Palma::PalmaConnectionHandle connection_handle);
216 Result EnablePalmaStep(bool is_enabled, Palma::PalmaConnectionHandle connection_handle);
217 Result ResetPalmaStep(Palma::PalmaConnectionHandle connection_handle);
218 Result ReadPalmaApplicationSection(Palma::PalmaConnectionHandle connection_handle, u64 offset,
219 u64 size);
220 Result WritePalmaApplicationSection(
221 Palma::PalmaConnectionHandle connection_handle, u64 offset, u64 size,
222 InLargeData<Palma::PalmaApplicationSection, BufferAttr_HipcPointer> data);
223 Result ReadPalmaUniqueCode(Palma::PalmaConnectionHandle connection_handle);
224 Result SetPalmaUniqueCodeInvalid(Palma::PalmaConnectionHandle connection_handle);
225 Result WritePalmaActivityEntry(Palma::PalmaConnectionHandle connection_handle,
226 Palma::PalmaActivityEntry activity_entry);
227 Result WritePalmaRgbLedPatternEntry(Palma::PalmaConnectionHandle connection_handle, u64 unknown,
228 InBuffer<BufferAttr_HipcMapAlias> led_pattern);
229 Result WritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle,
230 Palma::PalmaWaveSet wave_set, u64 unknown, u64 t_mem_size, u64 size,
231 InCopyHandle<Kernel::KTransferMemory> t_mem);
232 Result SetPalmaDataBaseIdentificationVersion(s32 database_id_version,
233 Palma::PalmaConnectionHandle connection_handle);
234 Result GetPalmaDataBaseIdentificationVersion(Palma::PalmaConnectionHandle connection_handle);
235 Result SuspendPalmaFeature(Palma::PalmaFeature feature,
236 Palma::PalmaConnectionHandle connection_handle);
237 Result GetPalmaOperationResult(Palma::PalmaConnectionHandle connection_handle);
238 Result ReadPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle);
239 Result ResetPalmaPlayLog(u16 unknown, Palma::PalmaConnectionHandle connection_handle);
240 Result SetIsPalmaAllConnectable(bool is_palma_all_connectable, ClientAppletResourceUserId arui);
241 Result SetIsPalmaPairedConnectable(bool is_palma_paired_connectable,
242 ClientAppletResourceUserId aruid);
243 Result PairPalma(Palma::PalmaConnectionHandle connection_handle);
244 Result SetPalmaBoostMode(bool is_enabled);
245 Result CancelWritePalmaWaveEntry(Palma::PalmaConnectionHandle connection_handle);
246 Result EnablePalmaBoostMode(bool is_enabled, ClientAppletResourceUserId aruid);
247 Result GetPalmaBluetoothAddress(Out<Palma::Address> out_bt_address,
248 Palma::PalmaConnectionHandle connection_handle);
249 Result SetDisallowedPalmaConnection(
250 ClientAppletResourceUserId aruid,
251 InArray<Palma::Address, BufferAttr_HipcPointer> disallowed_address);
252 Result SetNpadCommunicationMode(ClientAppletResourceUserId aruid,
253 NpadCommunicationMode communication_mode);
254 Result GetNpadCommunicationMode(Out<NpadCommunicationMode> out_communication_mode,
255 ClientAppletResourceUserId aruid);
256 Result SetTouchScreenConfiguration(Core::HID::TouchScreenConfigurationForNx touchscreen_config,
257 ClientAppletResourceUserId aruid);
258 Result IsFirmwareUpdateNeededForNotification(Out<bool> out_is_firmware_update_needed,
259 s32 unknown, ClientAppletResourceUserId aruid);
260 Result SetTouchScreenResolution(u32 width, u32 height, ClientAppletResourceUserId aruid);
149 261
150 std::shared_ptr<ResourceManager> resource_manager; 262 std::shared_ptr<ResourceManager> resource_manager;
151 std::shared_ptr<HidFirmwareSettings> firmware_settings; 263 std::shared_ptr<HidFirmwareSettings> firmware_settings;