aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/loader/loader.h
diff options
context:
space:
mode:
authorGravatar bunnei <ericbunnie@gmail.com>2014-06-18 18:58:09 -0400
committerGravatar bunnei <ericbunnie@gmail.com>2014-06-24 19:29:58 -0400
commit7889cafc76ac99b8509fa3cd1558a09f8a7e5f91 (patch)
treee6ffea9ec1c334bfca13404c47a2191fd281554c /src/core/loader/loader.h
parent79a48082e2c7b6e61f38b442a66147a4e46f2911 (diff)
Loader: Implemented AppLoader interface for abstracting application loading.
- Various cleanups/refactorings to Loader, ELF, and NCCH modules. - Added AppLoader interface to ELF and NCCH. - Updated Qt/GLFW frontends to check AppLoader ResultStatus. NCCH: Removed extra qualification typos. Loader: Removed unnecessary #include's. NCCH: Improved readability of memcmp statements. NCCH: Added missing space. Elf: Removed unnecessary usage of unique_ptr. Loader: Removed unnecessary usage of unique_ptr.
Diffstat (limited to 'src/core/loader/loader.h')
-rw-r--r--src/core/loader/loader.h103
1 files changed, 91 insertions, 12 deletions
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 97900355..42caa29e 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -4,6 +4,8 @@
#pragma once
+#include <vector>
+
#include "common/common.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -11,16 +13,94 @@
namespace Loader {
-enum FileType {
- FILETYPE_ERROR,
+/// File types supported by CTR
+enum class FileType {
+ Error,
+ Unknown,
+ CCI,
+ CXI,
+ CIA,
+ ELF,
+};
+
+/// Return type for functions in Loader namespace
+enum class ResultStatus {
+ Success,
+ Error,
+ ErrorInvalidFormat,
+ ErrorNotImplemented,
+ ErrorNotLoaded,
+ ErrorAlreadyLoaded,
+};
+
+/// Interface for loading an application
+class AppLoader : NonCopyable {
+public:
+ AppLoader() { }
+ virtual ~AppLoader() { }
+
+ /**
+ * Load the application
+ * @return ResultStatus result of function
+ */
+ virtual const ResultStatus Load() = 0;
+
+ /**
+ * Get the code (typically .code section) of the application
+ * @param error ResultStatus result of function
+ * @return Reference to code buffer
+ */
+ virtual const std::vector<u8>& GetCode(ResultStatus& error) const {
+ error = ResultStatus::ErrorNotImplemented;
+ return code;
+ }
+
+ /**
+ * Get the icon (typically .icon section) of the application
+ * @param error ResultStatus result of function
+ * @return Reference to icon buffer
+ */
+ virtual const std::vector<u8>& GetIcon(ResultStatus& error) const {
+ error = ResultStatus::ErrorNotImplemented;
+ return icon;
+ }
+
+ /**
+ * Get the banner (typically .banner section) of the application
+ * @param error ResultStatus result of function
+ * @return Reference to banner buffer
+ */
+ virtual const std::vector<u8>& GetBanner(ResultStatus& error) const {
+ error = ResultStatus::ErrorNotImplemented;
+ return banner;
+ }
+
+ /**
+ * Get the logo (typically .logo section) of the application
+ * @param error ResultStatus result of function
+ * @return Reference to logo buffer
+ */
+ virtual const std::vector<u8>& GetLogo(ResultStatus& error) const {
+ error = ResultStatus::ErrorNotImplemented;
+ return logo;
+ }
- FILETYPE_CTR_CCI,
- FILETYPE_CTR_CIA,
- FILETYPE_CTR_CXI,
- FILETYPE_CTR_ELF,
- FILETYPE_CTR_BIN,
+ /**
+ * Get the RomFs archive of the application
+ * @param error ResultStatus result of function
+ * @return Reference to RomFs archive buffer
+ */
+ virtual const std::vector<u8>& GetRomFs(ResultStatus error) const {
+ error = ResultStatus::ErrorNotImplemented;
+ return romfs;
+ }
- FILETYPE_UNKNOWN
+protected:
+ std::vector<u8> code; ///< ExeFS .code section
+ std::vector<u8> icon; ///< ExeFS .icon section
+ std::vector<u8> banner; ///< ExeFS .banner section
+ std::vector<u8> logo; ///< ExeFS .logo section
+ std::vector<u8> romfs; ///< RomFs archive
};
/**
@@ -28,14 +108,13 @@ enum FileType {
* @param filename String filename of bootable file
* @return FileType of file
*/
-FileType IdentifyFile(std::string &filename);
+const FileType IdentifyFile(const std::string &filename);
/**
* Identifies and loads a bootable file
* @param filename String filename of bootable file
- * @param error_string Point to string to put error message if an error has occurred
- * @return True on success, otherwise false
+ * @return ResultStatus result of function
*/
-bool LoadFile(std::string &filename, std::string *error_string);
+const ResultStatus LoadFile(std::string& filename);
} // namespace