summaryrefslogtreecommitdiff
path: root/src/core/hle/applets/applet.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/applets/applet.cpp')
-rw-r--r--src/core/hle/applets/applet.cpp130
1 files changed, 0 insertions, 130 deletions
diff --git a/src/core/hle/applets/applet.cpp b/src/core/hle/applets/applet.cpp
deleted file mode 100644
index 9c43ed2fd..000000000
--- a/src/core/hle/applets/applet.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
1// Copyright 2015 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <cstddef>
6#include <memory>
7#include <type_traits>
8#include <unordered_map>
9#include "common/assert.h"
10#include "common/common_types.h"
11#include "core/core_timing.h"
12#include "core/hle/applets/applet.h"
13#include "core/hle/applets/erreula.h"
14#include "core/hle/applets/mii_selector.h"
15#include "core/hle/applets/mint.h"
16#include "core/hle/applets/swkbd.h"
17#include "core/hle/result.h"
18#include "core/hle/service/apt/apt.h"
19
20////////////////////////////////////////////////////////////////////////////////////////////////////
21
22// Specializes std::hash for AppletId, so that we can use it in std::unordered_map.
23// Workaround for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
24namespace std {
25template <>
26struct hash<Service::APT::AppletId> {
27 typedef Service::APT::AppletId argument_type;
28 typedef std::size_t result_type;
29
30 result_type operator()(const argument_type& id_code) const {
31 typedef std::underlying_type<argument_type>::type Type;
32 return std::hash<Type>()(static_cast<Type>(id_code));
33 }
34};
35}
36
37namespace HLE {
38namespace Applets {
39
40static std::unordered_map<Service::APT::AppletId, std::shared_ptr<Applet>> applets;
41static u32 applet_update_event =
42 -1; ///< The CoreTiming event identifier for the Applet update callback.
43/// The interval at which the Applet update callback will be called, 16.6ms
44static const u64 applet_update_interval_us = 16666;
45
46ResultCode Applet::Create(Service::APT::AppletId id) {
47 switch (id) {
48 case Service::APT::AppletId::SoftwareKeyboard1:
49 case Service::APT::AppletId::SoftwareKeyboard2:
50 applets[id] = std::make_shared<SoftwareKeyboard>(id);
51 break;
52 case Service::APT::AppletId::Ed1:
53 case Service::APT::AppletId::Ed2:
54 applets[id] = std::make_shared<MiiSelector>(id);
55 break;
56 case Service::APT::AppletId::Error:
57 case Service::APT::AppletId::Error2:
58 applets[id] = std::make_shared<ErrEula>(id);
59 break;
60 case Service::APT::AppletId::Mint:
61 case Service::APT::AppletId::Mint2:
62 applets[id] = std::make_shared<Mint>(id);
63 break;
64 default:
65 LOG_ERROR(Service_APT, "Could not create applet %u", id);
66 // TODO(Subv): Find the right error code
67 return ResultCode(ErrorDescription::NotFound, ErrorModule::Applet,
68 ErrorSummary::NotSupported, ErrorLevel::Permanent);
69 }
70
71 return RESULT_SUCCESS;
72}
73
74std::shared_ptr<Applet> Applet::Get(Service::APT::AppletId id) {
75 auto itr = applets.find(id);
76 if (itr != applets.end())
77 return itr->second;
78 return nullptr;
79}
80
81/// Handles updating the current Applet every time it's called.
82static void AppletUpdateEvent(u64 applet_id, int cycles_late) {
83 Service::APT::AppletId id = static_cast<Service::APT::AppletId>(applet_id);
84 std::shared_ptr<Applet> applet = Applet::Get(id);
85 ASSERT_MSG(applet != nullptr, "Applet doesn't exist! applet_id=%08X", id);
86
87 applet->Update();
88
89 // If the applet is still running after the last update, reschedule the event
90 if (applet->IsRunning()) {
91 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us) - cycles_late,
92 applet_update_event, applet_id);
93 } else {
94 // Otherwise the applet has terminated, in which case we should clean it up
95 applets[id] = nullptr;
96 }
97}
98
99ResultCode Applet::Start(const Service::APT::AppletStartupParameter& parameter) {
100 ResultCode result = StartImpl(parameter);
101 if (result.IsError())
102 return result;
103 // Schedule the update event
104 CoreTiming::ScheduleEvent(usToCycles(applet_update_interval_us), applet_update_event,
105 static_cast<u64>(id));
106 return result;
107}
108
109bool Applet::IsRunning() const {
110 return is_running;
111}
112
113bool IsLibraryAppletRunning() {
114 // Check the applets map for instances of any applet
115 for (auto itr = applets.begin(); itr != applets.end(); ++itr)
116 if (itr->second != nullptr)
117 return true;
118 return false;
119}
120
121void Init() {
122 // Register the applet update callback
123 applet_update_event = CoreTiming::RegisterEvent("HLE Applet Update Event", AppletUpdateEvent);
124}
125
126void Shutdown() {
127 CoreTiming::RemoveEvent(applet_update_event);
128}
129}
130} // namespace