summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel/object.h')
-rw-r--r--src/core/hle/kernel/object.h98
1 files changed, 0 insertions, 98 deletions
diff --git a/src/core/hle/kernel/object.h b/src/core/hle/kernel/object.h
deleted file mode 100644
index 03443b947..000000000
--- a/src/core/hle/kernel/object.h
+++ /dev/null
@@ -1,98 +0,0 @@
1// Copyright 2018 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <atomic>
8#include <memory>
9#include <string>
10
11#include "common/common_types.h"
12
13namespace Kernel {
14
15class KernelCore;
16
17using Handle = u32;
18
19enum class HandleType : u32 {
20 Unknown,
21 Event,
22 WritableEvent,
23 ReadableEvent,
24 SharedMemory,
25 TransferMemory,
26 Thread,
27 Process,
28 ResourceLimit,
29 ClientPort,
30 ServerPort,
31 ClientSession,
32 ServerSession,
33 Session,
34};
35
36class Object : NonCopyable, public std::enable_shared_from_this<Object> {
37public:
38 explicit Object(KernelCore& kernel_);
39 explicit Object(KernelCore& kernel_, std::string&& name_);
40 virtual ~Object();
41
42 /// Returns a unique identifier for the object. For debugging purposes only.
43 u32 GetObjectId() const {
44 return object_id.load(std::memory_order_relaxed);
45 }
46
47 virtual std::string GetTypeName() const {
48 return "[BAD KERNEL OBJECT TYPE]";
49 }
50 virtual std::string GetName() const {
51 return name;
52 }
53 virtual HandleType GetHandleType() const = 0;
54
55 void Close() {
56 // TODO(bunnei): This is a placeholder to decrement the reference count, which we will use
57 // when we implement KAutoObject instead of using shared_ptr.
58 }
59
60 /**
61 * Check if a thread can wait on the object
62 * @return True if a thread can wait on the object, otherwise false
63 */
64 bool IsWaitable() const;
65
66 virtual void Finalize() = 0;
67
68protected:
69 /// The kernel instance this object was created under.
70 KernelCore& kernel;
71
72private:
73 std::atomic<u32> object_id{0};
74
75protected:
76 std::string name;
77};
78
79template <typename T>
80std::shared_ptr<T> SharedFrom(T* raw) {
81 if (raw == nullptr)
82 return nullptr;
83 return std::static_pointer_cast<T>(raw->shared_from_this());
84}
85
86/**
87 * Attempts to downcast the given Object pointer to a pointer to T.
88 * @return Derived pointer to the object, or `nullptr` if `object` isn't of type T.
89 */
90template <typename T>
91inline T* DynamicObjectCast(Object* object) {
92 if (object != nullptr && object->GetHandleType() == T::HANDLE_TYPE) {
93 return reinterpret_cast<T*>(object);
94 }
95 return nullptr;
96}
97
98} // namespace Kernel