aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/KAutoObject.cs
blob: a91bf9a84289e900da1380e490e311e7790466ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace Ryujinx.HLE.HOS.Kernel
{
    class KAutoObject
    {
        protected Horizon System;

        public KAutoObject(Horizon System)
        {
            this.System = System;
        }

        public virtual KernelResult SetName(string Name)
        {
            if (!System.AutoObjectNames.TryAdd(Name, this))
            {
                return KernelResult.InvalidState;
            }

            return KernelResult.Success;
        }

        public static KernelResult RemoveName(Horizon System, string Name)
        {
            if (!System.AutoObjectNames.TryRemove(Name, out _))
            {
                return KernelResult.NotFound;
            }

            return KernelResult.Success;
        }

        public static KAutoObject FindNamedObject(Horizon System, string Name)
        {
            if (System.AutoObjectNames.TryGetValue(Name, out KAutoObject Obj))
            {
                return Obj;
            }

            return null;
        }
    }
}