diff options
-rw-r--r-- | src/common/param_package.cpp | 19 | ||||
-rw-r--r-- | src/common/param_package.h | 2 | ||||
-rw-r--r-- | src/core/hle/ipc_helpers.h | 19 | ||||
-rw-r--r-- | src/core/hle/service/apm/interface.cpp | 17 |
4 files changed, 47 insertions, 10 deletions
diff --git a/src/common/param_package.cpp b/src/common/param_package.cpp index e0df430ab..9526ca0c6 100644 --- a/src/common/param_package.cpp +++ b/src/common/param_package.cpp @@ -3,7 +3,9 @@ // Refer to the license.txt file included. #include <array> +#include <utility> #include <vector> + #include "common/logging/log.h" #include "common/param_package.h" #include "common/string_util.h" @@ -12,10 +14,11 @@ namespace Common { constexpr char KEY_VALUE_SEPARATOR = ':'; constexpr char PARAM_SEPARATOR = ','; + constexpr char ESCAPE_CHARACTER = '$'; -const std::string KEY_VALUE_SEPARATOR_ESCAPE{ESCAPE_CHARACTER, '0'}; -const std::string PARAM_SEPARATOR_ESCAPE{ESCAPE_CHARACTER, '1'}; -const std::string ESCAPE_CHARACTER_ESCAPE{ESCAPE_CHARACTER, '2'}; +constexpr char KEY_VALUE_SEPARATOR_ESCAPE[] = "$0"; +constexpr char PARAM_SEPARATOR_ESCAPE[] = "$1"; +constexpr char ESCAPE_CHARACTER_ESCAPE[] = "$2"; ParamPackage::ParamPackage(const std::string& serialized) { std::vector<std::string> pairs; @@ -35,7 +38,7 @@ ParamPackage::ParamPackage(const std::string& serialized) { part = Common::ReplaceAll(part, ESCAPE_CHARACTER_ESCAPE, {ESCAPE_CHARACTER}); } - Set(key_value[0], key_value[1]); + Set(key_value[0], std::move(key_value[1])); } } @@ -101,16 +104,16 @@ float ParamPackage::Get(const std::string& key, float default_value) const { } } -void ParamPackage::Set(const std::string& key, const std::string& value) { - data[key] = value; +void ParamPackage::Set(const std::string& key, std::string value) { + data.insert_or_assign(key, std::move(value)); } void ParamPackage::Set(const std::string& key, int value) { - data[key] = std::to_string(value); + data.insert_or_assign(key, std::to_string(value)); } void ParamPackage::Set(const std::string& key, float value) { - data[key] = std::to_string(value); + data.insert_or_assign(key, std::to_string(value)); } bool ParamPackage::Has(const std::string& key) const { diff --git a/src/common/param_package.h b/src/common/param_package.h index c4c11b221..7842cd4ef 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h @@ -28,7 +28,7 @@ public: std::string Get(const std::string& key, const std::string& default_value) const; int Get(const std::string& key, int default_value) const; float Get(const std::string& key, float default_value) const; - void Set(const std::string& key, const std::string& value); + void Set(const std::string& key, std::string value); void Set(const std::string& key, int value); void Set(const std::string& key, float value); bool Has(const std::string& key) const; diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index 24605a273..8b5b06f31 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -175,6 +175,25 @@ public: void Push(const First& first_value, const Other&... other_values); /** + * Helper function for pushing strongly-typed enumeration values. + * + * @tparam Enum The enumeration type to be pushed + * + * @param value The value to push. + * + * @note The underlying size of the enumeration type is the size of the + * data that gets pushed. e.g. "enum class SomeEnum : u16" will + * push a u16-sized amount of data. + */ + template <typename Enum> + void PushEnum(Enum value) { + static_assert(std::is_enum_v<Enum>, "T must be an enum type within a PushEnum call."); + static_assert(!std::is_convertible_v<Enum, int>, + "enum type in PushEnum must be a strongly typed enum."); + Push(static_cast<std::underlying_type_t<Enum>>(value)); + } + + /** * @brief Copies the content of the given trivially copyable class to the buffer as a normal * param * @note: The input class must be correctly packed/padded to fit hardware layout. diff --git a/src/core/hle/service/apm/interface.cpp b/src/core/hle/service/apm/interface.cpp index 751d73f8d..ce943d829 100644 --- a/src/core/hle/service/apm/interface.cpp +++ b/src/core/hle/service/apm/interface.cpp @@ -20,6 +20,21 @@ public: } private: + enum class PerformanceConfiguration : u32 { + Config1 = 0x00010000, + Config2 = 0x00010001, + Config3 = 0x00010002, + Config4 = 0x00020000, + Config5 = 0x00020001, + Config6 = 0x00020002, + Config7 = 0x00020003, + Config8 = 0x00020004, + Config9 = 0x00020005, + Config10 = 0x00020006, + Config11 = 0x92220007, + Config12 = 0x92220008, + }; + void SetPerformanceConfiguration(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; @@ -40,7 +55,7 @@ private: IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push<u32>(0); // Performance configuration + rb.Push<u32>(static_cast<u32>(PerformanceConfiguration::Config1)); LOG_WARNING(Service_APM, "(STUBBED) called mode={}", static_cast<u32>(mode)); } |