tio: implement SdCardObserver (finishes sysmodule)

This commit is contained in:
Michael Scire 2021-02-24 09:57:41 -08:00 committed by SciresM
parent 3cbd99a709
commit 0da3b2b273
10 changed files with 268 additions and 2 deletions

View file

@ -15,6 +15,7 @@
*/
#include <stratosphere.hpp>
#include "fsa/fs_mount_utils.hpp"
#include "impl/fs_event_notifier_object_adapter.hpp"
namespace ams::fs {
@ -87,4 +88,30 @@ namespace ams::fs {
return fsa::Register(name, std::move(subdir_fs));
}
Result OpenSdCardDetectionEventNotifier(std::unique_ptr<IEventNotifier> *out) {
/* Try to open an event notifier. */
FsEventNotifier notifier;
AMS_FS_R_TRY(fsOpenSdCardDetectionEventNotifier(std::addressof(notifier)));
/* Create an event notifier adapter. */
auto adapter = std::make_unique<impl::RemoteEventNotifierObjectAdapter>(notifier);
R_UNLESS(adapter != nullptr, fs::ResultAllocationFailureInSdCardB());
*out = std::move(adapter);
return ResultSuccess();
}
bool IsSdCardInserted() {
/* Open device operator. */
FsDeviceOperator device_operator;
AMS_FS_R_ABORT_UNLESS(::fsOpenDeviceOperator(std::addressof(device_operator)));
ON_SCOPE_EXIT { ::fsDeviceOperatorClose(std::addressof(device_operator)); };
/* Get SD card inserted. */
bool inserted;
AMS_FS_R_ABORT_UNLESS(::fsDeviceOperatorIsSdCardInserted(std::addressof(device_operator), std::addressof(inserted)));
return inserted;
}
}