summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorbunnei <ericbunnie@gmail.com>2014-05-19 03:43:29 +0200
committerbunnei <ericbunnie@gmail.com>2014-05-19 03:43:29 +0200
commiteab6fd01d7d2e9b7434a8c5654d424cb563c3784 (patch)
tree8fcef16c0a2d6fdc078a9c49d55a7caa6c02a755 /src/core
parentrenamed "UID" to "Handle" where appropriate (diff)
downloadyuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.gz
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.bz2
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.lz
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.xz
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.tar.zst
yuzu-eab6fd01d7d2e9b7434a8c5654d424cb563c3784.zip
Diffstat (limited to 'src/core')
-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;
typedef s32 Result;
enum KernelIDType {
- KERNEL_ID_TYPE_THREAD = 1,
- KERNEL_ID_TYPE_SEMAPHORE = 2,
- KERNEL_ID_TYPE_MUTEX = 3,
- KERNEL_ID_TYPE_EVENT = 4,
+ KERNEL_ID_TYPE_THREAD,
+ KERNEL_ID_TYPE_SEMAPHORE,
+ KERNEL_ID_TYPE_MUTEX,
+ KERNEL_ID_TYPE_EVENT,
+ KERNEL_ID_TYPE_SERVICE,
};
enum {
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:
* Gets the string port name used by CTROS for the service
* @return Port name of service
*/
- std::string GetPortName() const {
+ const char *GetPortName() const {
return "APT:U";
}
};
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:
* Gets the string port name used by CTROS for the service
* @return Port name of service
*/
- std::string GetPortName() const {
+ const char *GetPortName() const {
return "gsp::Gpu";
}
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:
* Gets the string port name used by CTROS for the service
* @return Port name of service
*/
- std::string GetPortName() const {
+ const char *GetPortName() const {
return "hid:USER";
}
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 @@
#include "common/string_util.h"
#include "core/hle/hle.h"
+
#include "core/hle/service/service.h"
#include "core/hle/service/apt.h"
#include "core/hle/service/gsp.h"
#include "core/hle/service/hid.h"
#include "core/hle/service/srv.h"
+#include "core/hle/kernel/kernel.h"
+
namespace Service {
Manager* g_manager = NULL; ///< Service manager
@@ -31,32 +34,21 @@ Manager::~Manager() {
/// Add a service to the manager (does not create it though)
void Manager::AddService(Interface* service) {
- int index = m_services.size();
- Handle handle = GetHandleFromIndex(index);
-
+ m_port_map[service->GetPortName()] = g_kernel_objects.Create(service);
m_services.push_back(service);
-
- m_port_map[service->GetPortName()] = handle;
- service->m_handle = handle;
}
/// Removes a service from the manager, also frees memory
void Manager::DeleteService(std::string port_name) {
- auto service = FetchFromPortName(port_name);
-
- m_services.erase(m_services.begin() + GetIndexFromHandle(service->m_handle));
+ Interface* service = FetchFromPortName(port_name);
+ m_services.erase(std::remove(m_services.begin(), m_services.end(), service), m_services.end());
m_port_map.erase(port_name);
-
delete service;
}
/// Get a Service Interface from its Handle
Interface* Manager::FetchFromHandle(Handle handle) {
- int index = GetIndexFromHandle(handle);
- if (index < (int)m_services.size()) {
- return m_services[index];
- }
- return NULL;
+ return g_kernel_objects.GetFast<Interface>(handle);
}
/// 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 @@
#pragma once
+#include <algorithm>
#include <vector>
#include <map>
#include <string>
@@ -35,15 +36,15 @@ inline static u32* GetCommandBuffer(const int offset=0) {
class Manager;
/// Interface to a CTROS service
-class Interface : NonCopyable {
+class Interface : public KernelObject {
friend class Manager;
public:
+
+ const char *GetName() { return GetPortName(); }
+ const char *GetTypeName() { return GetPortName(); }
- Interface() {
- }
-
- virtual ~Interface() {
- }
+ static KernelIDType GetStaticIDType() { return KERNEL_ID_TYPE_THREAD; }
+ KernelIDType GetIDType() const { return KERNEL_ID_TYPE_THREAD; }
typedef void (*Function)(Interface*);
@@ -54,36 +55,23 @@ public:
};
/**
- * Gets the Handle for the serice
- * @return Handle of service in native format
- */
- Handle GetHandle() const {
- return m_handle;
- }
-
- /**
* Gets the string name used by CTROS for a service
* @return Port name of service
*/
- virtual std::string GetPortName() const {
+ virtual const char *GetPortName() const {
return "[UNKNOWN SERVICE PORT]";
}
/// Allocates a new handle for the service
Handle NewHandle() {
- Handle handle = (m_handles.size() << 16) | m_handle;
+ Handle handle = (m_handles.size() << 16) | 0;//m_handle;
m_handles.push_back(handle);
return handle;
}
/// Frees a handle from the service
void DeleteHandle(Handle handle) {
- for(auto iter = m_handles.begin(); iter != m_handles.end(); ++iter) {
- if(*iter == handle) {
- m_handles.erase(iter);
- break;
- }
- }
+ m_handles.erase(std::remove(m_handles.begin(), m_handles.end(), handle), m_handles.end());
}
/**
@@ -96,12 +84,12 @@ public:
if (itr == m_functions.end()) {
ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!",
- GetPortName().c_str(), cmd_buff[0]);
+ GetPortName(), cmd_buff[0]);
return -1;
}
if (itr->second.func == NULL) {
ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!",
- GetPortName().c_str(), itr->second.name.c_str());
+ GetPortName(), itr->second.name.c_str());
return -1;
}
@@ -122,10 +110,10 @@ protected:
}
private:
- u32 m_handle;
-
+
std::vector<Handle> m_handles;
std::map<u32, FunctionInfo> m_functions;
+
};
/// Simple class to manage accessing services from ports and UID handles
@@ -150,18 +138,9 @@ public:
private:
- /// Convert an index into m_services vector into a UID
- static Handle GetHandleFromIndex(const int index) {
- return index | 0x10000000;
- }
-
- /// Convert a UID into an index into m_services
- static int GetIndexFromHandle(const Handle handle) {
- return handle & 0x0FFFFFFF;
- }
-
std::vector<Interface*> m_services;
std::map<std::string, u32> m_port_map;
+
};
/// 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:
* Gets the string name used by CTROS for the service
* @return Port name of service
*/
- std::string GetPortName() const {
+ const char *GetPortName() const {
return "srv:";
}