From cd0664eb77e14a801fe1f15be50c3a90b98ee5ef Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 24 Apr 2014 22:16:54 -0400 Subject: - refactored how service functions are called - added option to create/delete service handles --- src/core/hle/service/service.h | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src/core/hle/service/service.h') diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index 9cbf8b6fa..9de17beab 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -25,7 +25,7 @@ static const int kCommandHeaderOffset = 0x80; ///< Offset into command buffer class Manager; /// Interface to a CTROS service -class Interface { +class Interface : NonCopyable { friend class Manager; public: @@ -35,6 +35,14 @@ public: virtual ~Interface() { } + typedef void (*Function)(Interface*); + + struct FunctionInfo { + u32 id; + Function func; + std::string name; + }; + /** * Gets the UID for the serice * @return UID of service in native format @@ -51,6 +59,23 @@ public: return "[UNKNOWN SERVICE PORT]"; } + /// Allocates a new handle for the service + Syscall::Handle NewHandle() { + Syscall::Handle handle = (m_handles.size() << 16) | m_uid; + m_handles.push_back(handle); + return handle; + } + + /// Frees a handle from the service + void DeleteHandle(Syscall::Handle handle) { + for(auto iter = m_handles.begin(); iter != m_handles.end(); ++iter) { + if(*iter == handle) { + m_handles.erase(iter); + break; + } + } + } + /** * Called when svcSendSyncRequest is called, loads command buffer and executes comand * @return Return result of svcSendSyncRequest passed back to user app @@ -70,16 +95,17 @@ public: return -1; } - itr->second.func(); + itr->second.func(this); return 0; // TODO: Implement return from actual function } protected: + /** * Registers the functions in the service */ - void Register(const HLE::FunctionDef* functions, int len) { + void Register(const FunctionInfo* functions, int len) { for (int i = 0; i < len; i++) { m_functions[functions[i].id] = functions[i]; } @@ -87,9 +113,9 @@ protected: private: u32 m_uid; - std::map m_functions; - - DISALLOW_COPY_AND_ASSIGN(Interface); + + std::vector m_handles; + std::map m_functions; }; /// Simple class to manage accessing services from ports and UID handles @@ -126,8 +152,6 @@ private: std::vector m_services; std::map m_port_map; - - DISALLOW_COPY_AND_ASSIGN(Manager); }; /// Initialize ServiceManager -- cgit v1.2.3