From 93bb3e8cf9ef789b5fdbf321815ed6108291786c Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Fri, 2 Aug 2019 22:05:36 -0400 Subject: Refactor settings system to be reference counted. --- binaryninjaapi.h | 81 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'binaryninjaapi.h') diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 02dc26c2..68eee4db 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -544,6 +544,7 @@ namespace BinaryNinja class Architecture; class BackgroundTask; class Platform; + class Settings; class Type; class DataBuffer; class MainThreadAction; @@ -1672,8 +1673,8 @@ namespace BinaryNinja std::vector GetRawMetadata(const std::string& key); uint64_t GetUIntMetadata(const std::string& key); - std::string GetLoadSettings(std::string typeName); - void SetLoadSettings(std::string typeName, std::string loadSettings); + Ref GetLoadSettings(std::string typeName); + void SetLoadSettings(std::string typeName, Ref settings); BNAnalysisParameters GetParametersForAnalysis(); void SetParametersForAnalysis(BNAnalysisParameters params); @@ -1723,7 +1724,7 @@ namespace BinaryNinja static BNBinaryView* CreateCallback(void* ctxt, BNBinaryView* data); static bool IsValidCallback(void* ctxt, BNBinaryView* data); - static char* GetSettingsCallback(void* ctxt, BNBinaryView* data); + static BNSettings* GetSettingsCallback(void* ctxt, BNBinaryView* data); BinaryViewType(BNBinaryViewType* type); @@ -1751,7 +1752,7 @@ namespace BinaryNinja virtual BinaryView* Create(BinaryView* data) = 0; virtual bool IsTypeValidForData(BinaryView* data) = 0; - virtual std::string GetLoadSettingsForData(BinaryView* data) = 0; + virtual Ref GetLoadSettingsForData(BinaryView* data) = 0; }; class CoreBinaryViewType: public BinaryViewType @@ -1760,7 +1761,7 @@ namespace BinaryNinja CoreBinaryViewType(BNBinaryViewType* type); virtual BinaryView* Create(BinaryView* data) override; virtual bool IsTypeValidForData(BinaryView* data) override; - virtual std::string GetLoadSettingsForData(BinaryView* data) override; + virtual Ref GetLoadSettingsForData(BinaryView* data) override; }; class ReadException: public std::exception @@ -4493,57 +4494,63 @@ namespace BinaryNinja Ref GetDefaultRepository(); }; - class Settings + class Settings: public CoreRefCountObject { - std::string m_registry; + std::string m_instanceId; + + Settings() = delete; + Settings(const std::string& m_instanceId); public: - Settings(const std::string& registry = "default") : m_registry(registry) { } + Settings(BNSettings* settings); + static Ref Instance(const std::string& schemaId = ""); + virtual ~Settings() {} bool RegisterGroup(const std::string& group, const std::string& title); - bool RegisterSetting(const std::string& id, const std::string& properties); + bool RegisterSetting(const std::string& key, const std::string& properties); + bool Contains(const std::string& key); - template T QueryProperty(const std::string& id, const std::string& property); + template T QueryProperty(const std::string& key, const std::string& property); - bool UpdateProperty(const std::string& id, const std::string& property); - bool UpdateProperty(const std::string& id, const std::string& property, bool value); - bool UpdateProperty(const std::string& id, const std::string& property, double value); - bool UpdateProperty(const std::string& id, const std::string& property, int value); - bool UpdateProperty(const std::string& id, const std::string& property, int64_t value); - bool UpdateProperty(const std::string& id, const std::string& property, uint64_t value); - bool UpdateProperty(const std::string& id, const std::string& property, const char* value); - bool UpdateProperty(const std::string& id, const std::string& property, const std::string& value); - bool UpdateProperty(const std::string& id, const std::string& property, const std::vector& value); + bool UpdateProperty(const std::string& key, const std::string& property); + bool UpdateProperty(const std::string& key, const std::string& property, bool value); + bool UpdateProperty(const std::string& key, const std::string& property, double value); + bool UpdateProperty(const std::string& key, const std::string& property, int value); + bool UpdateProperty(const std::string& key, const std::string& property, int64_t value); + bool UpdateProperty(const std::string& key, const std::string& property, uint64_t value); + bool UpdateProperty(const std::string& key, const std::string& property, const char* value); + bool UpdateProperty(const std::string& key, const std::string& property, const std::string& value); + bool UpdateProperty(const std::string& key, const std::string& property, const std::vector& value); bool DeserializeSchema(const std::string& schema); std::string SerializeSchema(); bool DeserializeSettings(const std::string& contents, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); std::string SerializeSettings(Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool CopyValue(const std::string& destRegistry, const std::string& id); - bool Reset(const std::string& id, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool CopyValuesFrom(Ref source, BNSettingsScope scope = SettingsAutoScope); + bool Reset(const std::string& key, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); bool ResetAll(Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - template T Get(const std::string& id, Ref view = nullptr, BNSettingsScope* scope = nullptr); + template T Get(const std::string& key, Ref view = nullptr, BNSettingsScope* scope = nullptr); - bool Set(const std::string& id, bool value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, double value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, int value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, int64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, uint64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, const char* value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, const std::string& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); - bool Set(const std::string& id, const std::vector& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, bool value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, double value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, int value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, int64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, uint64_t value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, const char* value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, const std::string& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); + bool Set(const std::string& key, const std::vector& value, Ref view = nullptr, BNSettingsScope scope = SettingsAutoScope); }; // explicit specializations - template<> std::vector Settings::QueryProperty>(const std::string& id, const std::string& property); - template<> bool Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); - template<> double Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); - template<> int64_t Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); - template<> uint64_t Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); - template<> std::string Settings::Get(const std::string& id, Ref view, BNSettingsScope* scope); - template<> std::vector Settings::Get>(const std::string& id, Ref view, BNSettingsScope* scope); + template<> std::vector Settings::QueryProperty>(const std::string& key, const std::string& property); + template<> bool Settings::Get(const std::string& key, Ref view, BNSettingsScope* scope); + template<> double Settings::Get(const std::string& key, Ref view, BNSettingsScope* scope); + template<> int64_t Settings::Get(const std::string& key, Ref view, BNSettingsScope* scope); + template<> uint64_t Settings::Get(const std::string& key, Ref view, BNSettingsScope* scope); + template<> std::string Settings::Get(const std::string& key, Ref view, BNSettingsScope* scope); + template<> std::vector Settings::Get>(const std::string& key, Ref view, BNSettingsScope* scope); typedef BNMetadataType MetadataType; -- cgit v1.3.1