/* * 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 . */ #pragma once #include #include #include #include namespace ams::kern { class KObjectName : public KSlabAllocated, public util::IntrusiveListBaseNode { public: static constexpr size_t NameLengthMax = 12; using List = util::IntrusiveListBaseTraits::ListType; private: char m_name[NameLengthMax]; KAutoObject *m_object; public: constexpr KObjectName() : m_name(), m_object() { /* ... */ } public: static Result NewFromName(KAutoObject *obj, const char *name); static Result Delete(KAutoObject *obj, const char *name); static KScopedAutoObject Find(const char *name); template 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(); R_UNLESS(derived != nullptr, svc::ResultNotFound()); return Delete(obj.GetPointerUnsafe(), name); } template requires std::derived_from static KScopedAutoObject Find(const char *name) { return Find(name); } private: static KScopedAutoObject FindImpl(const char *name); void Initialize(KAutoObject *obj, const char *name); bool MatchesName(const char *name) const; KAutoObject *GetObject() const { return m_object; } }; }