diff --git a/src/lib/libkrbn/include/libkrbn/libkrbn.h b/src/lib/libkrbn/include/libkrbn/libkrbn.h index b3bc1b35c..9e6ca79d2 100644 --- a/src/lib/libkrbn/include/libkrbn/libkrbn.h +++ b/src/lib/libkrbn/include/libkrbn/libkrbn.h @@ -140,6 +140,10 @@ void libkrbn_core_configuration_replace_selected_profile_fn_function_key(libkrbn size_t libkrbn_core_configuration_get_selected_profile_complex_modifications_rules_size(libkrbn_core_configuration* p); const char* libkrbn_core_configuration_get_selected_profile_complex_modifications_rule_description(libkrbn_core_configuration* p, size_t index); +bool libkrbn_core_configuration_get_selected_profile_complex_modifications_rule_json_string(libkrbn_core_configuration* p, + size_t index, + char* buffer, + size_t length); void libkrbn_core_configuration_erase_selected_profile_complex_modifications_rule(libkrbn_core_configuration* p, size_t index); void libkrbn_core_configuration_swap_selected_profile_complex_modifications_rules(libkrbn_core_configuration* p, size_t index1, size_t index2); void libkrbn_core_configuration_move_selected_profile_complex_modifications_rule(libkrbn_core_configuration* p, size_t source_index, size_t destination_index); diff --git a/src/lib/libkrbn/src/libkrbn_configuration.cpp b/src/lib/libkrbn/src/libkrbn_configuration.cpp index 8f2334a36..17079259d 100644 --- a/src/lib/libkrbn/src/libkrbn_configuration.cpp +++ b/src/lib/libkrbn/src/libkrbn_configuration.cpp @@ -337,6 +337,24 @@ const char* _Nullable libkrbn_core_configuration_get_selected_profile_complex_mo return 0; } +bool libkrbn_core_configuration_get_selected_profile_complex_modifications_rule_json_string(libkrbn_core_configuration* p, + size_t index, + char* buffer, + size_t length) { + if (auto c = reinterpret_cast(p)) { + const auto& rules = c->get_core_configuration().get_selected_profile().get_complex_modifications().get_rules(); + if (index < rules.size()) { + auto json_string = krbn::json_utility::dump(rules[index].get_json()); + // Return false if no enough space. + if (json_string.length() < length) { + strlcpy(buffer, json_string.c_str(), length); + return true; + } + } + } + return false; +} + int libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(libkrbn_core_configuration* p, const char* name) { if (auto c = reinterpret_cast(p)) {