summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2014-05-18 21:43:29 -0400
committerGravatar bunnei2014-05-18 21:43:29 -0400
commiteab6fd01d7d2e9b7434a8c5654d424cb563c3784 (patch)
tree8fcef16c0a2d6fdc078a9c49d55a7caa6c02a755 /src
parentrenamed "UID" to "Handle" where appropriate (diff)
downloadyuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.gz
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.xz
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.zip
- updated service(s) to be KernelObject's
- various cleanups
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/kernel.h9
-rw-r--r--src/core/hle/service/apt.h2
-rw-r--r--src/core/hle/service/gsp.h2
-rw-r--r--src/core/hle/service/hid.h2
-rw-r--r--src/core/hle/service/service.cpp22
-rw-r--r--src/core/hle/service/service.h51
-rw-r--r--src/core/hle/service/srv.h2
7 files changed, 31 insertions, 59 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index d4bb28c72..8f2b7b36d 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -10,10 +10,11 @@ typedef u32 Handle;
10typedef s32 Result; 10typedef s32 Result;
11 11
12enum KernelIDType { 12enum KernelIDType {
13 KERNEL_ID_TYPE_THREAD = 1, 13 KERNEL_ID_TYPE_THREAD,
14 KERNEL_ID_TYPE_SEMAPHORE = 2, 14 KERNEL_ID_TYPE_SEMAPHORE,
15 KERNEL_ID_TYPE_MUTEX = 3, 15 KERNEL_ID_TYPE_MUTEX,
16 KERNEL_ID_TYPE_EVENT = 4, 16 KERNEL_ID_TYPE_EVENT,
17 KERNEL_ID_TYPE_SERVICE,
17}; 18};
18 19
19enum { 20enum {
diff --git a/src/core/hle/service/apt.h b/src/core/hle/service/apt.h
index 4c7dd07e7..dca3097ed 100644
--- a/src/core/hle/service/apt.h
+++ b/src/core/hle/service/apt.h
@@ -29,7 +29,7 @@ public:
29 * Gets the string port name used by CTROS for the service 29 * Gets the string port name used by CTROS for the service
30 * @return Port name of service 30 * @return Port name of service
31 */ 31 */
32 std::string GetPortName() const { 32 const char *GetPortName() const {
33 return "APT:U"; 33 return "APT:U";
34 } 34 }
35}; 35};
diff --git a/src/core/hle/service/gsp.h b/src/core/hle/service/gsp.h
index 5ba09ab70..eb5786cd1 100644
--- a/src/core/hle/service/gsp.h
+++ b/src/core/hle/service/gsp.h
@@ -23,7 +23,7 @@ public:
23 * Gets the string port name used by CTROS for the service 23 * Gets the string port name used by CTROS for the service
24 * @return Port name of service 24 * @return Port name of service
25 */ 25 */
26 std::string GetPortName() const { 26 const char *GetPortName() const {
27 return "gsp::Gpu"; 27 return "gsp::Gpu";
28 } 28 }
29 29
diff --git a/src/core/hle/service/hid.h b/src/core/hle/service/hid.h
index b17fcfa86..81c29eb2e 100644
--- a/src/core/hle/service/hid.h
+++ b/src/core/hle/service/hid.h
@@ -25,7 +25,7 @@ public:
25 * Gets the string port name used by CTROS for the service 25 * Gets the string port name used by CTROS for the service
26 * @return Port name of service 26 * @return Port name of service
27 */ 27 */
28 std::string GetPortName() const { 28 const char *GetPortName() const {
29 return "hid:USER"; 29 return "hid:USER";
30 } 30 }
31 31
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 5601e59a1..b3e414e0f 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -7,12 +7,15 @@
7#include "common/string_util.h" 7#include "common/string_util.h"
8 8
9#include "core/hle/hle.h" 9#include "core/hle/hle.h"
10
10#include "core/hle/service/service.h" 11#include "core/hle/service/service.h"
11#include "core/hle/service/apt.h" 12#include "core/hle/service/apt.h"
12#include "core/hle/service/gsp.h" 13#include "core/hle/service/gsp.h"
13#include "core/hle/service/hid.h" 14#include "core/hle/service/hid.h"
14#include "core/hle/service/srv.h" 15#include "core/hle/service/srv.h"
15 16
17#include "core/hle/kernel/kernel.h"
18
16namespace Service { 19namespace Service {
17 20
18Manager* g_manager = NULL; ///< Service manager 21Manager* g_manager = NULL; ///< Service manager
@@ -31,32 +34,21 @@ Manager::~Manager() {
31 34
32/// Add a service to the manager (does not create it though) 35/// Add a service to the manager (does not create it though)
33void Manager::AddService(Interface* service) { 36void Manager::AddService(Interface* service) {
34 int index = m_services.size(); 37 m_port_map[service->GetPortName()] = g_kernel_objects.Create(service);
35 Handle handle = GetHandleFromIndex(index);
36
37 m_services.push_back(service); 38 m_services.push_back(service);
38
39 m_port_map[service->GetPortName()] = handle;
40 service->m_handle = handle;
41} 39}
42 40
43/// Removes a service from the manager, also frees memory 41/// Removes a service from the manager, also frees memory
44void Manager::DeleteService(std::string port_name) { 42void Manager::DeleteService(std::string port_name) {
45 auto service = FetchFromPortName(port_name); 43 Interface* service = FetchFromPortName(port_name);
46 44 m_services.erase(std::remove(m_services.begin(), m_services.end(), service), m_services.end());
47 m_services.erase(m_services.begin() + GetIndexFromHandle(service->m_handle));
48 m_port_map.erase(port_name); 45 m_port_map.erase(port_name);
49
50 delete service; 46 delete service;
51} 47}
52 48
53/// Get a Service Interface from its Handle 49/// Get a Service Interface from its Handle
54Interface* Manager::FetchFromHandle(Handle handle) { 50Interface* Manager::FetchFromHandle(Handle handle) {
55 int index = GetIndexFromHandle(handle); 51 return g_kernel_objects.GetFast<Interface>(handle);
56 if (index < (int)m_services.size()) {
57 return m_services[index];
58 }
59 return NULL;
60} 52}
61 53
62/// Get a Service Interface from its port 54/// Get a Service Interface from its port
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h
index c3dbd202f..35735a00b 100644
--- a/src/core/hle/service/service.h
+++ b/src/core/hle/service/service.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <algorithm>
7#include <vector> 8#include <vector>
8#include <map> 9#include <map>
9#include <string> 10#include <string>
@@ -35,15 +36,15 @@ inline static u32* GetCommandBuffer(const int offset=0) {
35class Manager; 36class Manager;
36 37
37/// Interface to a CTROS service 38/// Interface to a CTROS service
38class Interface : NonCopyable { 39class Interface : public KernelObject {
39 friend class Manager; 40 friend class Manager;
40public: 41public:
42
43 const char *GetName() { return GetPortName(); }
44 const char *GetTypeName() { return GetPortName(); }
41 45
42 Interface() { 46 static KernelIDType GetStaticIDType() { return KERNEL_ID_TYPE_THREAD; }
43 } 47 KernelIDType GetIDType() const { return KERNEL_ID_TYPE_THREAD; }
44
45 virtual ~Interface() {
46 }
47 48
48 typedef void (*Function)(Interface*); 49 typedef void (*Function)(Interface*);
49 50
@@ -54,36 +55,23 @@ public:
54 }; 55 };
55 56
56 /** 57 /**
57 * Gets the Handle for the serice
58 * @return Handle of service in native format
59 */
60 Handle GetHandle() const {
61 return m_handle;
62 }
63
64 /**
65 * Gets the string name used by CTROS for a service 58 * Gets the string name used by CTROS for a service
66 * @return Port name of service 59 * @return Port name of service
67 */ 60 */
68 virtual std::string GetPortName() const { 61 virtual const char *GetPortName() const {
69 return "[UNKNOWN SERVICE PORT]"; 62 return "[UNKNOWN SERVICE PORT]";
70 } 63 }
71 64
72 /// Allocates a new handle for the service 65 /// Allocates a new handle for the service
73 Handle NewHandle() { 66 Handle NewHandle() {
74 Handle handle = (m_handles.size() << 16) | m_handle; 67 Handle handle = (m_handles.size() << 16) | 0;//m_handle;
75 m_handles.push_back(handle); 68 m_handles.push_back(handle);
76 return handle; 69 return handle;
77 } 70 }
78 71
79 /// Frees a handle from the service 72 /// Frees a handle from the service
80 void DeleteHandle(Handle handle) { 73 void DeleteHandle(Handle handle) {
81 for(auto iter = m_handles.begin(); iter != m_handles.end(); ++iter) { 74 m_handles.erase(std::remove(m_handles.begin(), m_handles.end(), handle), m_handles.end());
82 if(*iter == handle) {
83 m_handles.erase(iter);
84 break;
85 }
86 }
87 } 75 }
88 76
89 /** 77 /**
@@ -96,12 +84,12 @@ public:
96 84
97 if (itr == m_functions.end()) { 85 if (itr == m_functions.end()) {
98 ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", 86 ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!",
99 GetPortName().c_str(), cmd_buff[0]); 87 GetPortName(), cmd_buff[0]);
100 return -1; 88 return -1;
101 } 89 }
102 if (itr->second.func == NULL) { 90 if (itr->second.func == NULL) {
103 ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", 91 ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!",
104 GetPortName().c_str(), itr->second.name.c_str()); 92 GetPortName(), itr->second.name.c_str());
105 return -1; 93 return -1;
106 } 94 }
107 95
@@ -122,10 +110,10 @@ protected:
122 } 110 }
123 111
124private: 112private:
125 u32 m_handle; 113
126
127 std::vector<Handle> m_handles; 114 std::vector<Handle> m_handles;
128 std::map<u32, FunctionInfo> m_functions; 115 std::map<u32, FunctionInfo> m_functions;
116
129}; 117};
130 118
131/// Simple class to manage accessing services from ports and UID handles 119/// Simple class to manage accessing services from ports and UID handles
@@ -150,18 +138,9 @@ public:
150 138
151private: 139private:
152 140
153 /// Convert an index into m_services vector into a UID
154 static Handle GetHandleFromIndex(const int index) {
155 return index | 0x10000000;
156 }
157
158 /// Convert a UID into an index into m_services
159 static int GetIndexFromHandle(const Handle handle) {
160 return handle & 0x0FFFFFFF;
161 }
162
163 std::vector<Interface*> m_services; 141 std::vector<Interface*> m_services;
164 std::map<std::string, u32> m_port_map; 142 std::map<std::string, u32> m_port_map;
143
165}; 144};
166 145
167/// Initialize ServiceManager 146/// Initialize ServiceManager
diff --git a/src/core/hle/service/srv.h b/src/core/hle/service/srv.h
index f465ebc06..1e35032ba 100644
--- a/src/core/hle/service/srv.h
+++ b/src/core/hle/service/srv.h
@@ -22,7 +22,7 @@ public:
22 * Gets the string name used by CTROS for the service 22 * Gets the string name used by CTROS for the service
23 * @return Port name of service 23 * @return Port name of service
24 */ 24 */
25 std::string GetPortName() const { 25 const char *GetPortName() const {
26 return "srv:"; 26 return "srv:";
27 } 27 }
28 28