2015-05-26 04:30:20 +00:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-07-12 21:10:37 +00:00
|
|
|
#include <memory>
|
|
|
|
#include "core/hle/result.h"
|
2018-01-25 13:39:54 +00:00
|
|
|
#include "core/hle/service/apt/applet_manager.h"
|
2015-05-26 04:30:20 +00:00
|
|
|
|
2019-02-19 01:34:18 +00:00
|
|
|
namespace HLE::Applets {
|
2015-05-26 04:30:20 +00:00
|
|
|
|
2015-05-27 20:21:06 +00:00
|
|
|
class Applet {
|
2015-05-26 04:30:20 +00:00
|
|
|
public:
|
2016-12-07 22:04:14 +00:00
|
|
|
virtual ~Applet() = default;
|
2015-05-26 04:30:20 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-26 16:00:26 +00:00
|
|
|
* Creates an instance of the Applet subclass identified by the parameter.
|
2015-05-26 04:30:20 +00:00
|
|
|
* and stores it in a global map.
|
2015-05-26 16:00:26 +00:00
|
|
|
* @param id Id of the applet to create.
|
2023-02-28 12:09:54 +00:00
|
|
|
* @param parent Id of the applet's parent.
|
|
|
|
* @param preload Whether the applet is being preloaded.
|
2015-05-26 16:00:26 +00:00
|
|
|
* @returns ResultCode Whether the operation was successful or not.
|
2015-05-26 04:30:20 +00:00
|
|
|
*/
|
2023-02-28 12:09:54 +00:00
|
|
|
static ResultCode Create(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
|
|
|
const std::shared_ptr<Service::APT::AppletManager>& manager);
|
2015-05-26 04:30:20 +00:00
|
|
|
|
|
|
|
/**
|
2015-05-26 16:00:26 +00:00
|
|
|
* Retrieves the Applet instance identified by the specified id.
|
|
|
|
* @param id Id of the Applet to retrieve.
|
|
|
|
* @returns Requested Applet or nullptr if not found.
|
2015-05-26 04:30:20 +00:00
|
|
|
*/
|
|
|
|
static std::shared_ptr<Applet> Get(Service::APT::AppletId id);
|
|
|
|
|
|
|
|
/**
|
2015-05-26 16:00:26 +00:00
|
|
|
* Handles a parameter from the application.
|
|
|
|
* @param parameter Parameter data to handle.
|
|
|
|
* @returns ResultCode Whether the operation was successful or not.
|
2015-05-26 04:30:20 +00:00
|
|
|
*/
|
2023-02-28 12:09:54 +00:00
|
|
|
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter);
|
2015-05-26 04:30:20 +00:00
|
|
|
|
2015-05-26 16:00:26 +00:00
|
|
|
/**
|
2023-03-25 21:36:14 +00:00
|
|
|
* Whether the applet is currently running.
|
2015-05-26 16:00:26 +00:00
|
|
|
*/
|
2023-02-28 12:09:54 +00:00
|
|
|
[[nodiscard]] bool IsRunning() const;
|
2015-05-26 16:00:26 +00:00
|
|
|
|
2023-03-25 21:36:14 +00:00
|
|
|
/**
|
|
|
|
* Whether the applet is currently active instead of the host application or not.
|
|
|
|
*/
|
|
|
|
[[nodiscard]] bool IsActive() const;
|
|
|
|
|
2015-05-26 16:00:26 +00:00
|
|
|
/**
|
|
|
|
* Handles an update tick for the Applet, lets it update the screen, send commands, etc.
|
|
|
|
*/
|
|
|
|
virtual void Update() = 0;
|
|
|
|
|
2015-05-27 20:21:06 +00:00
|
|
|
protected:
|
2023-02-28 12:09:54 +00:00
|
|
|
Applet(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
|
|
|
|
std::weak_ptr<Service::APT::AppletManager> manager)
|
|
|
|
: id(id), parent(parent), preload(preload), manager(std::move(manager)) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles a parameter from the application.
|
|
|
|
* @param parameter Parameter data to handle.
|
|
|
|
* @returns ResultCode Whether the operation was successful or not.
|
|
|
|
*/
|
|
|
|
virtual ResultCode ReceiveParameterImpl(const Service::APT::MessageParameter& parameter) = 0;
|
2016-12-07 21:50:28 +00:00
|
|
|
|
2015-05-27 20:21:06 +00:00
|
|
|
/**
|
|
|
|
* Handles the Applet start event, triggered from the application.
|
|
|
|
* @param parameter Parameter data to handle.
|
|
|
|
* @returns ResultCode Whether the operation was successful or not.
|
|
|
|
*/
|
2023-02-28 12:09:54 +00:00
|
|
|
virtual ResultCode Start(const Service::APT::MessageParameter& parameter) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the LibAppletClosing signal to the application,
|
|
|
|
* along with the relevant data buffers.
|
|
|
|
*/
|
|
|
|
virtual ResultCode Finalize() = 0;
|
2015-05-27 20:21:06 +00:00
|
|
|
|
2016-09-18 00:38:01 +00:00
|
|
|
Service::APT::AppletId id; ///< Id of this Applet
|
2023-02-28 12:09:54 +00:00
|
|
|
Service::APT::AppletId parent; ///< Id of this Applet's parent
|
|
|
|
bool preload; ///< Whether the Applet is being preloaded.
|
2016-05-08 22:10:53 +00:00
|
|
|
std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
|
2016-12-07 22:11:39 +00:00
|
|
|
|
2023-03-25 21:36:14 +00:00
|
|
|
/// Whether this applet is running.
|
|
|
|
bool is_running = true;
|
|
|
|
|
|
|
|
/// Whether this applet is currently active instead of the host application or not.
|
|
|
|
bool is_active = false;
|
2018-01-25 13:39:54 +00:00
|
|
|
|
|
|
|
void SendParameter(const Service::APT::MessageParameter& parameter);
|
2023-02-28 12:09:54 +00:00
|
|
|
void CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer);
|
2018-01-25 13:39:54 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::weak_ptr<Service::APT::AppletManager> manager;
|
2015-05-26 04:30:20 +00:00
|
|
|
};
|
|
|
|
|
2015-05-26 16:00:26 +00:00
|
|
|
/// Initializes the HLE applets
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
/// Shuts down the HLE applets
|
|
|
|
void Shutdown();
|
2019-02-19 01:34:18 +00:00
|
|
|
} // namespace HLE::Applets
|