buffet: Change shared ownership of types/values to exclusive
In order to support array types in Buffet's type system, PropValue
must maintain a strong reference to the underlying PropType since
the array elements will have their own type reference and the current
implementation of using raw pointer for this isn't going to work.
In order to resolve this I had to make a lot of changes to the object
ownership inside Buffet's type system. I made it possible for both
PropType and PropValue to make a deep copy of itself using their
Clone() methods. Because of this now it is possible to have exclusive
ownership of objects and I got rid of most of shared pointer usage in
ObjectSchema, PropType and PropValue.
BUG=brillo:107
TEST=`FEATURES=test emerge-link buffet`
Change-Id: I02de455dfd40d4833041b63cbb80bcb00293b5a9
Reviewed-on: https://chromium-review.googlesource.com/261336
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/commands/command_instance.h b/buffet/commands/command_instance.h
index 45cf485..c925b6c 100644
--- a/buffet/commands/command_instance.h
+++ b/buffet/commands/command_instance.h
@@ -32,10 +32,9 @@
// Construct a command instance given the full command |name| which must
// be in format "<package_name>.<command_name>", a command |category| and
// a list of parameters and their values specified in |parameters|.
- CommandInstance(
- const std::string& name,
- const std::shared_ptr<const CommandDefinition>& command_definition,
- const native_types::Object& parameters);
+ CommandInstance(const std::string& name,
+ const CommandDefinition* command_definition,
+ const native_types::Object& parameters);
~CommandInstance();
// Returns the full command ID.
@@ -49,11 +48,11 @@
// Returns the command results and their values.
const native_types::Object& GetResults() const { return results_; }
// Finds a command parameter value by parameter |name|. If the parameter
- // with given name does not exist, returns null shared_ptr.
- std::shared_ptr<const PropValue> FindParameter(const std::string& name) const;
+ // with given name does not exist, returns nullptr.
+ const PropValue* FindParameter(const std::string& name) const;
// Returns command definition.
- std::shared_ptr<const CommandDefinition> GetCommandDefinition() const {
+ const CommandDefinition* GetCommandDefinition() const {
return command_definition_;
}
@@ -117,7 +116,7 @@
// Full command name as "<package_name>.<command_name>".
std::string name_;
// Command definition.
- std::shared_ptr<const CommandDefinition> command_definition_;
+ const CommandDefinition* command_definition_;
// Command parameters and their values.
native_types::Object parameters_;
// Command results.