diff options
Diffstat (limited to 'src/core/hle/service/service.h')
| -rw-r--r-- | src/core/hle/service/service.h | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index b260a290a..fab51753f 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h | |||
| @@ -4,22 +4,22 @@ | |||
| 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> |
| 10 | 11 | ||
| 11 | #include "common/common.h" | 12 | #include "common/common.h" |
| 12 | #include "common/common_types.h" | ||
| 13 | #include "core/mem_map.h" | 13 | #include "core/mem_map.h" |
| 14 | #include "core/hle/syscall.h" | 14 | |
| 15 | #include "core/hle/kernel/kernel.h" | ||
| 16 | #include "core/hle/svc.h" | ||
| 15 | 17 | ||
| 16 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 17 | // Namespace Service | 19 | // Namespace Service |
| 18 | 20 | ||
| 19 | namespace Service { | 21 | namespace Service { |
| 20 | 22 | ||
| 21 | typedef s32 NativeUID; ///< Native handle for a service | ||
| 22 | |||
| 23 | static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters) | 23 | static const int kMaxPortSize = 0x08; ///< Maximum size of a port name (8 characters) |
| 24 | static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header | 24 | static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer of header |
| 25 | 25 | ||
| @@ -35,15 +35,15 @@ inline static u32* GetCommandBuffer(const int offset=0) { | |||
| 35 | class Manager; | 35 | class Manager; |
| 36 | 36 | ||
| 37 | /// Interface to a CTROS service | 37 | /// Interface to a CTROS service |
| 38 | class Interface : NonCopyable { | 38 | class Interface : public Kernel::Object { |
| 39 | friend class Manager; | 39 | friend class Manager; |
| 40 | public: | 40 | public: |
| 41 | |||
| 42 | const char *GetName() { return GetPortName(); } | ||
| 43 | const char *GetTypeName() { return GetPortName(); } | ||
| 41 | 44 | ||
| 42 | Interface() { | 45 | static Kernel::HandleType GetStaticHandleType() { return Kernel::HandleType::Service; } |
| 43 | } | 46 | Kernel::HandleType GetHandleType() const { return Kernel::HandleType::Service; } |
| 44 | |||
| 45 | virtual ~Interface() { | ||
| 46 | } | ||
| 47 | 47 | ||
| 48 | typedef void (*Function)(Interface*); | 48 | typedef void (*Function)(Interface*); |
| 49 | 49 | ||
| @@ -54,54 +54,43 @@ public: | |||
| 54 | }; | 54 | }; |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| 57 | * Gets the UID for the serice | ||
| 58 | * @return UID of service in native format | ||
| 59 | */ | ||
| 60 | NativeUID GetUID() const { | ||
| 61 | return (NativeUID)m_uid; | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Gets the string name used by CTROS for a service | 57 | * Gets the string name used by CTROS for a service |
| 66 | * @return Port name of service | 58 | * @return Port name of service |
| 67 | */ | 59 | */ |
| 68 | virtual std::string GetPortName() const { | 60 | virtual const char *GetPortName() const { |
| 69 | return "[UNKNOWN SERVICE PORT]"; | 61 | return "[UNKNOWN SERVICE PORT]"; |
| 70 | } | 62 | } |
| 71 | 63 | ||
| 72 | /// Allocates a new handle for the service | 64 | /// Allocates a new handle for the service |
| 73 | Syscall::Handle NewHandle() { | 65 | Handle CreateHandle(Kernel::Object *obj) { |
| 74 | Syscall::Handle handle = (m_handles.size() << 16) | m_uid; | 66 | Handle handle = Kernel::g_object_pool.Create(obj); |
| 75 | m_handles.push_back(handle); | 67 | m_handles.push_back(handle); |
| 76 | return handle; | 68 | return handle; |
| 77 | } | 69 | } |
| 78 | 70 | ||
| 79 | /// Frees a handle from the service | 71 | /// Frees a handle from the service |
| 80 | void DeleteHandle(Syscall::Handle handle) { | 72 | template <class T> |
| 81 | for(auto iter = m_handles.begin(); iter != m_handles.end(); ++iter) { | 73 | void DeleteHandle(const Handle handle) { |
| 82 | if(*iter == handle) { | 74 | Kernel::g_object_pool.Destroy<T>(handle); |
| 83 | m_handles.erase(iter); | 75 | m_handles.erase(std::remove(m_handles.begin(), m_handles.end(), handle), m_handles.end()); |
| 84 | break; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | } | 76 | } |
| 88 | 77 | ||
| 89 | /** | 78 | /** |
| 90 | * Called when svcSendSyncRequest is called, loads command buffer and executes comand | 79 | * Called when svcSendSyncRequest is called, loads command buffer and executes comand |
| 91 | * @return Return result of svcSendSyncRequest passed back to user app | 80 | * @return Return result of svcSendSyncRequest passed back to user app |
| 92 | */ | 81 | */ |
| 93 | Syscall::Result Sync() { | 82 | Result Sync() { |
| 94 | u32* cmd_buff = GetCommandBuffer(); | 83 | u32* cmd_buff = GetCommandBuffer(); |
| 95 | auto itr = m_functions.find(cmd_buff[0]); | 84 | auto itr = m_functions.find(cmd_buff[0]); |
| 96 | 85 | ||
| 97 | if (itr == m_functions.end()) { | 86 | if (itr == m_functions.end()) { |
| 98 | ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", | 87 | ERROR_LOG(OSHLE, "Unknown/unimplemented function: port = %s, command = 0x%08X!", |
| 99 | GetPortName().c_str(), cmd_buff[0]); | 88 | GetPortName(), cmd_buff[0]); |
| 100 | return -1; | 89 | return -1; |
| 101 | } | 90 | } |
| 102 | if (itr->second.func == NULL) { | 91 | if (itr->second.func == NULL) { |
| 103 | ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", | 92 | ERROR_LOG(OSHLE, "Unimplemented function: port = %s, name = %s!", |
| 104 | GetPortName().c_str(), itr->second.name.c_str()); | 93 | GetPortName(), itr->second.name.c_str()); |
| 105 | return -1; | 94 | return -1; |
| 106 | } | 95 | } |
| 107 | 96 | ||
| @@ -122,10 +111,10 @@ protected: | |||
| 122 | } | 111 | } |
| 123 | 112 | ||
| 124 | private: | 113 | private: |
| 125 | u32 m_uid; | 114 | |
| 126 | 115 | std::vector<Handle> m_handles; | |
| 127 | std::vector<Syscall::Handle> m_handles; | 116 | std::map<u32, FunctionInfo> m_functions; |
| 128 | std::map<u32, FunctionInfo> m_functions; | 117 | |
| 129 | }; | 118 | }; |
| 130 | 119 | ||
| 131 | /// Simple class to manage accessing services from ports and UID handles | 120 | /// Simple class to manage accessing services from ports and UID handles |
| @@ -143,25 +132,16 @@ public: | |||
| 143 | void DeleteService(std::string port_name); | 132 | void DeleteService(std::string port_name); |
| 144 | 133 | ||
| 145 | /// Get a Service Interface from its UID | 134 | /// Get a Service Interface from its UID |
| 146 | Interface* FetchFromUID(u32 uid); | 135 | Interface* FetchFromHandle(u32 uid); |
| 147 | 136 | ||
| 148 | /// Get a Service Interface from its port | 137 | /// Get a Service Interface from its port |
| 149 | Interface* FetchFromPortName(std::string port_name); | 138 | Interface* FetchFromPortName(std::string port_name); |
| 150 | 139 | ||
| 151 | private: | 140 | private: |
| 152 | 141 | ||
| 153 | /// Convert an index into m_services vector into a UID | ||
| 154 | static u32 GetUIDFromIndex(const int index) { | ||
| 155 | return index | 0x10000000; | ||
| 156 | } | ||
| 157 | |||
| 158 | /// Convert a UID into an index into m_services | ||
| 159 | static int GetIndexFromUID(const u32 uid) { | ||
| 160 | return uid & 0x0FFFFFFF; | ||
| 161 | } | ||
| 162 | |||
| 163 | std::vector<Interface*> m_services; | 142 | std::vector<Interface*> m_services; |
| 164 | std::map<std::string, u32> m_port_map; | 143 | std::map<std::string, u32> m_port_map; |
| 144 | |||
| 165 | }; | 145 | }; |
| 166 | 146 | ||
| 167 | /// Initialize ServiceManager | 147 | /// Initialize ServiceManager |