2020-02-07 20:51:58 +01:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-02-07 20:51:58 +01:00
|
|
|
*
|
|
|
|
* 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 <mesosphere/kern_common.hpp>
|
|
|
|
#include <mesosphere/kern_k_auto_object.hpp>
|
|
|
|
#include <mesosphere/kern_k_light_lock.hpp>
|
|
|
|
#include <mesosphere/kern_slab_helpers.hpp>
|
|
|
|
|
|
|
|
namespace ams::kern {
|
|
|
|
|
|
|
|
class KObjectName : public KSlabAllocated<KObjectName>, public util::IntrusiveListBaseNode<KObjectName> {
|
|
|
|
public:
|
2020-03-14 07:12:47 +01:00
|
|
|
static constexpr size_t NameLengthMax = 12;
|
|
|
|
|
|
|
|
using List = util::IntrusiveListBaseTraits<KObjectName>::ListType;
|
|
|
|
private:
|
2020-12-18 02:18:47 +01:00
|
|
|
char m_name[NameLengthMax];
|
|
|
|
KAutoObject *m_object;
|
2020-03-14 07:12:47 +01:00
|
|
|
public:
|
|
|
|
static Result NewFromName(KAutoObject *obj, const char *name);
|
|
|
|
static Result Delete(KAutoObject *obj, const char *name);
|
|
|
|
|
|
|
|
static KScopedAutoObject<KAutoObject> Find(const char *name);
|
|
|
|
|
|
|
|
template<typename Derived>
|
|
|
|
static Result Delete(const char *name) {
|
|
|
|
/* Find the object. */
|
|
|
|
KScopedAutoObject obj = Find(name);
|
|
|
|
R_UNLESS(obj.IsNotNull(), svc::ResultNotFound());
|
|
|
|
|
|
|
|
/* Cast the object to the desired type. */
|
|
|
|
Derived *derived = obj->DynamicCast<Derived *>();
|
|
|
|
R_UNLESS(derived != nullptr, svc::ResultNotFound());
|
|
|
|
|
2021-04-07 23:45:38 +02:00
|
|
|
/* Check that the object is closed. */
|
|
|
|
R_UNLESS(derived->IsServerClosed(), svc::ResultInvalidState());
|
|
|
|
|
2023-03-07 05:18:00 +01:00
|
|
|
R_RETURN(Delete(obj.GetPointerUnsafe(), name));
|
2020-03-14 07:12:47 +01:00
|
|
|
}
|
2020-07-09 23:49:51 +02:00
|
|
|
|
|
|
|
template<typename Derived> requires std::derived_from<Derived, KAutoObject>
|
|
|
|
static KScopedAutoObject<Derived> Find(const char *name) {
|
|
|
|
return Find(name);
|
|
|
|
}
|
2020-03-14 07:12:47 +01:00
|
|
|
private:
|
|
|
|
static KScopedAutoObject<KAutoObject> FindImpl(const char *name);
|
|
|
|
|
|
|
|
void Initialize(KAutoObject *obj, const char *name);
|
|
|
|
|
|
|
|
bool MatchesName(const char *name) const;
|
2020-12-18 02:18:47 +01:00
|
|
|
KAutoObject *GetObject() const { return m_object; }
|
2020-02-07 20:51:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|