mirror of https://git.suyu.dev/suyu/suyu
- refactored how service functions are called
- added option to create/delete service handles
This commit is contained in:
parent
15dacc4d3f
commit
cd0664eb77
|
@ -13,16 +13,16 @@
|
|||
|
||||
namespace APT_U {
|
||||
|
||||
void Initialize() {
|
||||
void Initialize(Service::Interface* self) {
|
||||
NOTICE_LOG(OSHLE, "APT_U::Sync - Initialize");
|
||||
}
|
||||
|
||||
void GetLockHandle() {
|
||||
void GetLockHandle(Service::Interface* self) {
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
|
||||
cmd_buff[5] = 0x00000000; // TODO: This should be an actual mutex handle
|
||||
}
|
||||
|
||||
const HLE::FunctionDef FunctionTable[] = {
|
||||
const Interface::FunctionInfo FunctionTable[] = {
|
||||
{0x00010040, GetLockHandle, "GetLockHandle"},
|
||||
{0x00020080, Initialize, "Initialize"},
|
||||
{0x00030040, NULL, "Enable"},
|
||||
|
|
|
@ -32,10 +32,6 @@ public:
|
|||
std::string GetPortName() const {
|
||||
return "APT:U";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Interface);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
namespace HID_User {
|
||||
|
||||
const HLE::FunctionDef FunctionTable[] = {
|
||||
const Interface::FunctionInfo FunctionTable[] = {
|
||||
{0x000A0000, NULL, "GetIPCHandles"},
|
||||
{0x00110000, NULL, "EnableAccelerometer"},
|
||||
{0x00130000, NULL, "EnableGyroscopeLow"},
|
||||
|
|
|
@ -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<u32, HLE::FunctionDef> m_functions;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Interface);
|
||||
std::vector<Syscall::Handle> m_handles;
|
||||
std::map<u32, FunctionInfo> m_functions;
|
||||
};
|
||||
|
||||
/// Simple class to manage accessing services from ports and UID handles
|
||||
|
@ -126,8 +152,6 @@ private:
|
|||
|
||||
std::vector<Interface*> m_services;
|
||||
std::map<std::string, u32> m_port_map;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Manager);
|
||||
};
|
||||
|
||||
/// Initialize ServiceManager
|
||||
|
|
|
@ -12,11 +12,11 @@
|
|||
|
||||
namespace SRV {
|
||||
|
||||
void Initialize() {
|
||||
void Initialize(Service::Interface* self) {
|
||||
NOTICE_LOG(OSHLE, "SRV::Sync - Initialize");
|
||||
}
|
||||
|
||||
void GetServiceHandle() {
|
||||
void GetServiceHandle(Service::Interface* self) {
|
||||
Syscall::Result res = 0;
|
||||
u32* cmd_buff = (u32*)HLE::GetPointer(HLE::CMD_BUFFER_ADDR + Service::kCommandHeaderOffset);
|
||||
|
||||
|
@ -37,7 +37,7 @@ void GetServiceHandle() {
|
|||
//return res;
|
||||
}
|
||||
|
||||
const HLE::FunctionDef FunctionTable[] = {
|
||||
const Interface::FunctionInfo FunctionTable[] = {
|
||||
{0x00010002, Initialize, "Initialize"},
|
||||
{0x00020000, NULL, "GetProcSemaphore"},
|
||||
{0x00030100, NULL, "RegisterService"},
|
||||
|
|
Loading…
Reference in New Issue