mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-08-07 07:59:27 +02:00
tio: implement SdCardObserver (finishes sysmodule)
This commit is contained in:
parent
b70fea933c
commit
65a37c60cc
@ -32,6 +32,7 @@
|
|||||||
#include <stratosphere/fs/fs_read_only_filesystem.hpp>
|
#include <stratosphere/fs/fs_read_only_filesystem.hpp>
|
||||||
#include <stratosphere/fs/fs_shared_filesystem_holder.hpp>
|
#include <stratosphere/fs/fs_shared_filesystem_holder.hpp>
|
||||||
#include <stratosphere/fs/fs_istorage.hpp>
|
#include <stratosphere/fs/fs_istorage.hpp>
|
||||||
|
#include <stratosphere/fs/fs_i_event_notifier.hpp>
|
||||||
#include <stratosphere/fs/fs_substorage.hpp>
|
#include <stratosphere/fs/fs_substorage.hpp>
|
||||||
#include <stratosphere/fs/fs_memory_storage.hpp>
|
#include <stratosphere/fs/fs_memory_storage.hpp>
|
||||||
#include <stratosphere/fs/fs_remote_storage.hpp>
|
#include <stratosphere/fs/fs_remote_storage.hpp>
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include "fs_common.hpp"
|
||||||
|
|
||||||
|
namespace ams::fs {
|
||||||
|
|
||||||
|
class IEventNotifier {
|
||||||
|
public:
|
||||||
|
virtual ~IEventNotifier() { /* ... */ }
|
||||||
|
|
||||||
|
Result BindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) {
|
||||||
|
AMS_ASSERT(out != nullptr);
|
||||||
|
return this->DoBindEvent(out, clear_mode);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
virtual Result DoBindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -18,8 +18,14 @@
|
|||||||
|
|
||||||
namespace ams::fs {
|
namespace ams::fs {
|
||||||
|
|
||||||
|
class IEventNotifier;
|
||||||
|
|
||||||
Result MountSdCard(const char *name);
|
Result MountSdCard(const char *name);
|
||||||
|
|
||||||
Result MountSdCardErrorReportDirectoryForAtmosphere(const char *name);
|
Result MountSdCardErrorReportDirectoryForAtmosphere(const char *name);
|
||||||
|
|
||||||
|
Result OpenSdCardDetectionEventNotifier(std::unique_ptr<IEventNotifier> *out);
|
||||||
|
|
||||||
|
bool IsSdCardInserted();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stratosphere/fssrv/sf/fssrv_sf_path.hpp>
|
#include <stratosphere/fssrv/sf/fssrv_sf_path.hpp>
|
||||||
#include <stratosphere/fssrv/sf/fssrv_sf_ifile.hpp>
|
#include <stratosphere/fssrv/sf/fssrv_sf_ifile.hpp>
|
||||||
|
#include <stratosphere/fssrv/sf/fssrv_sf_i_event_notifier.hpp>
|
||||||
#include <stratosphere/fssrv/fssrv_path_normalizer.hpp>
|
#include <stratosphere/fssrv/fssrv_path_normalizer.hpp>
|
||||||
#include <stratosphere/fssrv/fssrv_nca_crypto_configuration.hpp>
|
#include <stratosphere/fssrv/fssrv_nca_crypto_configuration.hpp>
|
||||||
#include <stratosphere/fssrv/fssrv_memory_resource_from_standard_allocator.hpp>
|
#include <stratosphere/fssrv/fssrv_memory_resource_from_standard_allocator.hpp>
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <vapours.hpp>
|
||||||
|
#include <stratosphere/sf.hpp>
|
||||||
|
|
||||||
|
#define AMS_FSSRV_I_EVENT_NOTIFIER_INTERFACE_INFO(C, H) \
|
||||||
|
AMS_SF_METHOD_INFO(C, H, 0, Result, GetEventHandle, (ams::sf::OutCopyHandle out), (out))
|
||||||
|
|
||||||
|
AMS_SF_DEFINE_INTERFACE(ams::fssrv::sf, IEventNotifier, AMS_FSSRV_I_EVENT_NOTIFIER_INTERFACE_INFO)
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
#include "fsa/fs_mount_utils.hpp"
|
#include "fsa/fs_mount_utils.hpp"
|
||||||
|
#include "impl/fs_event_notifier_object_adapter.hpp"
|
||||||
|
|
||||||
namespace ams::fs {
|
namespace ams::fs {
|
||||||
|
|
||||||
@ -87,4 +88,30 @@ namespace ams::fs {
|
|||||||
return fsa::Register(name, std::move(subdir_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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <stratosphere.hpp>
|
||||||
|
|
||||||
|
namespace ams::fs::impl {
|
||||||
|
|
||||||
|
class EventNotifierObjectAdapter final : public ::ams::fs::IEventNotifier, public ::ams::fs::impl::Newable {
|
||||||
|
private:
|
||||||
|
sf::SharedPointer<fssrv::sf::IEventNotifier> m_object;
|
||||||
|
public:
|
||||||
|
EventNotifierObjectAdapter(sf::SharedPointer<fssrv::sf::IEventNotifier> &&obj) : m_object(obj) { /* ... */ }
|
||||||
|
virtual ~EventNotifierObjectAdapter() { /* ... */ }
|
||||||
|
private:
|
||||||
|
virtual Result DoBindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) override {
|
||||||
|
/* Get the handle. */
|
||||||
|
sf::CopyHandle handle;
|
||||||
|
AMS_FS_R_TRY(m_object->GetEventHandle(std::addressof(handle)));
|
||||||
|
|
||||||
|
/* Create the system event. */
|
||||||
|
os::AttachReadableHandleToSystemEvent(out, handle, true, clear_mode);
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class RemoteEventNotifierObjectAdapter final : public ::ams::fs::IEventNotifier, public ::ams::fs::impl::Newable {
|
||||||
|
private:
|
||||||
|
::FsEventNotifier m_notifier;
|
||||||
|
public:
|
||||||
|
RemoteEventNotifierObjectAdapter(::FsEventNotifier &n) : m_notifier(n) { /* ... */ }
|
||||||
|
virtual ~RemoteEventNotifierObjectAdapter() { fsEventNotifierClose(std::addressof(m_notifier)); }
|
||||||
|
private:
|
||||||
|
virtual Result DoBindEvent(os::SystemEventType *out, os::EventClearMode clear_mode) override {
|
||||||
|
/* Get the handle. */
|
||||||
|
::Event e;
|
||||||
|
R_TRY(fsEventNotifierGetEventHandle(std::addressof(m_notifier), std::addressof(e), false));
|
||||||
|
|
||||||
|
/* Create the system event. */
|
||||||
|
os::AttachReadableHandleToSystemEvent(out, e.revent, true, clear_mode);
|
||||||
|
|
||||||
|
return ResultSuccess();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user