aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel/KAutoObject.cs
blob: f49beaac9412c2f818ffb272aaa381557cdbd3e9 (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)
        {
            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;
        }
    }
}