apt: Implement additional applet state management. (#6303)

* apt: Implement additional library applet state management.

* kernel: Clear process handle table on exit.

* apt: Implement system applet commands.

* apt: Pop MediaType from command buffers with correct size.

* apt: Improve accuracy of parameters and HLE applet lifecycle.

* apt: General cleanup.

* file_sys: Make system save data open error code more correct.

Not sure if this is the exact right error code, but it's at least
more correct than before as Game Notes will now create its system
save data instead of throwing a fatal error.

* apt: Fix launching New 3DS Internet Browser.

* frd: Correct fix to GetMyScreenName response.
This commit is contained in:
Steveice10 2023-02-28 04:09:54 -08:00 committed by GitHub
parent 8b116aaa04
commit 3c15398f9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 966 additions and 705 deletions

View file

@ -18,10 +18,12 @@ public:
* Creates an instance of the Applet subclass identified by the parameter.
* and stores it in a global map.
* @param id Id of the applet to create.
* @param parent Id of the applet's parent.
* @param preload Whether the applet is being preloaded.
* @returns ResultCode Whether the operation was successful or not.
*/
static ResultCode Create(Service::APT::AppletId id,
std::weak_ptr<Service::APT::AppletManager> manager);
static ResultCode Create(Service::APT::AppletId id, Service::APT::AppletId parent, bool preload,
const std::shared_ptr<Service::APT::AppletManager>& manager);
/**
* Retrieves the Applet instance identified by the specified id.
@ -35,19 +37,12 @@ public:
* @param parameter Parameter data to handle.
* @returns ResultCode Whether the operation was successful or not.
*/
virtual ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) = 0;
/**
* Handles the Applet start event, triggered from the application.
* @param parameter Parameter data to handle.
* @returns ResultCode Whether the operation was successful or not.
*/
ResultCode Start(const Service::APT::AppletStartupParameter& parameter);
ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter);
/**
* Whether the applet is currently executing instead of the host application or not.
*/
bool IsRunning() const;
[[nodiscard]] bool IsRunning() const;
/**
* Handles an update tick for the Applet, lets it update the screen, send commands, etc.
@ -55,31 +50,45 @@ public:
virtual void Update() = 0;
protected:
Applet(Service::APT::AppletId id, std::weak_ptr<Service::APT::AppletManager> manager)
: id(id), manager(std::move(manager)) {}
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;
/**
* Handles the Applet start event, triggered from the application.
* @param parameter Parameter data to handle.
* @returns ResultCode Whether the operation was successful or not.
*/
virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0;
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;
Service::APT::AppletId id; ///< Id of this Applet
Service::APT::AppletId parent; ///< Id of this Applet's parent
bool preload; ///< Whether the Applet is being preloaded.
std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
/// Whether this applet is currently running instead of the host application or not.
bool is_running = false;
void SendParameter(const Service::APT::MessageParameter& parameter);
void CloseApplet(std::shared_ptr<Kernel::Object> object, const std::vector<u8>& buffer);
private:
std::weak_ptr<Service::APT::AppletManager> manager;
};
/// Returns whether a library applet is currently running
bool IsLibraryAppletRunning();
/// Initializes the HLE applets
void Init();