diff options
Diffstat (limited to 'src/core/hle/service/service.cpp')
| -rw-r--r-- | src/core/hle/service/service.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp new file mode 100644 index 000000000..e6605a398 --- /dev/null +++ b/src/core/hle/service/service.cpp | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/common.h" | ||
| 6 | #include "common/log.h" | ||
| 7 | #include "common/string_util.h" | ||
| 8 | |||
| 9 | #include "core/hle/hle.h" | ||
| 10 | #include "core/hle/service/service.h" | ||
| 11 | #include "core/hle/service/apt.h" | ||
| 12 | #include "core/hle/service/gsp.h" | ||
| 13 | #include "core/hle/service/hid.h" | ||
| 14 | #include "core/hle/service/srv.h" | ||
| 15 | |||
| 16 | namespace Service { | ||
| 17 | |||
| 18 | Manager* g_manager = NULL; ///< Service manager | ||
| 19 | |||
| 20 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 21 | // Service Manager class | ||
| 22 | |||
| 23 | Manager::Manager() { | ||
| 24 | } | ||
| 25 | |||
| 26 | Manager::~Manager() { | ||
| 27 | for(Interface* service : m_services) { | ||
| 28 | DeleteService(service->GetPortName()); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | /// Add a service to the manager (does not create it though) | ||
| 33 | void Manager::AddService(Interface* service) { | ||
| 34 | int index = m_services.size(); | ||
| 35 | u32 new_uid = GetUIDFromIndex(index); | ||
| 36 | |||
| 37 | m_services.push_back(service); | ||
| 38 | |||
| 39 | m_port_map[service->GetPortName()] = new_uid; | ||
| 40 | service->m_uid = new_uid; | ||
| 41 | } | ||
| 42 | |||
| 43 | /// Removes a service from the manager, also frees memory | ||
| 44 | void Manager::DeleteService(std::string port_name) { | ||
| 45 | auto service = FetchFromPortName(port_name); | ||
| 46 | |||
| 47 | m_services.erase(m_services.begin() + GetIndexFromUID(service->m_uid)); | ||
| 48 | m_port_map.erase(port_name); | ||
| 49 | |||
| 50 | delete service; | ||
| 51 | } | ||
| 52 | |||
| 53 | /// Get a Service Interface from its UID | ||
| 54 | Interface* Manager::FetchFromUID(u32 uid) { | ||
| 55 | int index = GetIndexFromUID(uid); | ||
| 56 | if (index < (int)m_services.size()) { | ||
| 57 | return m_services[index]; | ||
| 58 | } | ||
| 59 | return NULL; | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Get a Service Interface from its port | ||
| 63 | Interface* Manager::FetchFromPortName(std::string port_name) { | ||
| 64 | auto itr = m_port_map.find(port_name); | ||
| 65 | if (itr == m_port_map.end()) { | ||
| 66 | return NULL; | ||
| 67 | } | ||
| 68 | return FetchFromUID(itr->second); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 73 | // Module interface | ||
| 74 | |||
| 75 | /// Initialize ServiceManager | ||
| 76 | void Init() { | ||
| 77 | g_manager = new Manager; | ||
| 78 | |||
| 79 | g_manager->AddService(new SRV::Interface); | ||
| 80 | g_manager->AddService(new APT_U::Interface); | ||
| 81 | g_manager->AddService(new GSP_GPU::Interface); | ||
| 82 | g_manager->AddService(new HID_User::Interface); | ||
| 83 | |||
| 84 | NOTICE_LOG(HLE, "Services initialized OK"); | ||
| 85 | } | ||
| 86 | |||
| 87 | /// Shutdown ServiceManager | ||
| 88 | void Shutdown() { | ||
| 89 | delete g_manager; | ||
| 90 | NOTICE_LOG(HLE, "Services shutdown OK"); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | } | ||