applet.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include "core/hle/result.h"
  7. #include "core/hle/service/apt/apt.h"
  8. namespace HLE {
  9. namespace Applets {
  10. class Applet {
  11. public:
  12. virtual ~Applet() { }
  13. Applet(Service::APT::AppletId id) : id(id) { }
  14. /**
  15. * Creates an instance of the Applet subclass identified by the parameter.
  16. * and stores it in a global map.
  17. * @param id Id of the applet to create.
  18. * @returns ResultCode Whether the operation was successful or not.
  19. */
  20. static ResultCode Create(Service::APT::AppletId id);
  21. /**
  22. * Retrieves the Applet instance identified by the specified id.
  23. * @param id Id of the Applet to retrieve.
  24. * @returns Requested Applet or nullptr if not found.
  25. */
  26. static std::shared_ptr<Applet> Get(Service::APT::AppletId id);
  27. /**
  28. * Handles a parameter from the application.
  29. * @param parameter Parameter data to handle.
  30. * @returns ResultCode Whether the operation was successful or not.
  31. */
  32. virtual ResultCode ReceiveParameter(const Service::APT::MessageParameter& parameter) = 0;
  33. /**
  34. * Handles the Applet start event, triggered from the application.
  35. * @param parameter Parameter data to handle.
  36. * @returns ResultCode Whether the operation was successful or not.
  37. */
  38. ResultCode Start(const Service::APT::AppletStartupParameter& parameter);
  39. /**
  40. * Whether the applet is currently executing instead of the host application or not.
  41. */
  42. virtual bool IsRunning() const = 0;
  43. /**
  44. * Handles an update tick for the Applet, lets it update the screen, send commands, etc.
  45. */
  46. virtual void Update() = 0;
  47. protected:
  48. /**
  49. * Handles the Applet start event, triggered from the application.
  50. * @param parameter Parameter data to handle.
  51. * @returns ResultCode Whether the operation was successful or not.
  52. */
  53. virtual ResultCode StartImpl(const Service::APT::AppletStartupParameter& parameter) = 0;
  54. Service::APT::AppletId id; ///< Id of this Applet
  55. std::shared_ptr<std::vector<u8>> heap_memory; ///< Heap memory for this Applet
  56. };
  57. /// Returns whether a library applet is currently running
  58. bool IsLibraryAppletRunning();
  59. /// Initializes the HLE applets
  60. void Init();
  61. /// Shuts down the HLE applets
  62. void Shutdown();
  63. }
  64. } // namespace