diff --git a/engine/src/flutter/impeller/archivist/BUILD.gn b/engine/src/flutter/impeller/archivist/BUILD.gn index 4aabe3e7b8..6766786523 100644 --- a/engine/src/flutter/impeller/archivist/BUILD.gn +++ b/engine/src/flutter/impeller/archivist/BUILD.gn @@ -11,7 +11,10 @@ impeller_component("archivist") { public = [ "archive.h" ] sources = [ + "archivable.cc", + "archivable.h", "archive.cc", + "archive.h", "archive_class_registration.cc", "archive_class_registration.h", "archive_database.cc", diff --git a/engine/src/flutter/impeller/archivist/archivable.cc b/engine/src/flutter/impeller/archivist/archivable.cc new file mode 100644 index 0000000000..29c8a3c019 --- /dev/null +++ b/engine/src/flutter/impeller/archivist/archivable.cc @@ -0,0 +1,11 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "impeller/archivist/archivable.h" + +namespace impeller { + +// + +} // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archivable.h b/engine/src/flutter/impeller/archivist/archivable.h new file mode 100644 index 0000000000..88b766fe64 --- /dev/null +++ b/engine/src/flutter/impeller/archivist/archivable.h @@ -0,0 +1,28 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#pragma once + +#include + +namespace impeller { + +class ArchiveLocation; + +//------------------------------------------------------------------------------ +/// @brief Instances of `Archivable`s can be read from and written to a +/// persistent archive. +/// +class Archivable { + public: + using ArchiveName = uint64_t; + + virtual ArchiveName GetArchiveName() const = 0; + + virtual bool Write(ArchiveLocation& item) const = 0; + + virtual bool Read(ArchiveLocation& item) = 0; +}; + +} // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archive.cc b/engine/src/flutter/impeller/archivist/archive.cc index ad8436ed8a..0289b648a0 100644 --- a/engine/src/flutter/impeller/archivist/archive.cc +++ b/engine/src/flutter/impeller/archivist/archive.cc @@ -15,41 +15,43 @@ namespace impeller { Archive::Archive(const std::string& path, bool recreate) - : _db(std::make_unique(path, recreate)) {} + : database_(std::make_unique(path, recreate)) {} Archive::~Archive() { - FML_DCHECK(_transactionCount == 0) << "There must be no pending transactions"; + FML_DCHECK(transaction_count_ == 0) + << "There must be no pending transactions"; } -bool Archive::isReady() const { - return _db->isReady(); +bool Archive::IsReady() const { + return database_->IsReady(); } -bool Archive::archiveInstance(const ArchiveDef& definition, - const ArchiveSerializable& archivable, +bool Archive::ArchiveInstance(const ArchiveDef& definition, + const Archivable& archivable, int64_t& lastInsertIDOut) { - if (!isReady()) { + if (!IsReady()) { return false; } - auto transaction = _db->acquireTransaction(_transactionCount); + auto transaction = database_->CreateTransaction(transaction_count_); - const auto* registration = _db->registrationForDefinition(definition); + const auto* registration = + database_->GetRegistrationForDefinition(definition); if (registration == nullptr) { return false; } - auto statement = registration->insertStatement(); + auto statement = registration->GetInsertStatement(); - if (!statement.isReady() || !statement.reset()) { + if (!statement.IsReady() || !statement.Reset()) { /* * Must be able to reset the statement for a new write */ return false; } - auto itemName = archivable.archiveName(); + auto itemName = archivable.GetArchiveName(); /* * The lifecycle of the archive item is tied to this scope and there is no @@ -57,25 +59,25 @@ bool Archive::archiveInstance(const ArchiveDef& definition, * for its members to be references. It does not manage the lifetimes of * anything. */ - ArchiveItem item(*this, statement, *registration, itemName); + ArchiveLocation item(*this, statement, *registration, itemName); /* * We need to bind the primary key only if the item does not provide its own */ if (!definition.autoAssignName && - !statement.bind(ArchiveClassRegistration::NameIndex, itemName)) { + !statement.WriteValue(ArchiveClassRegistration::NameIndex, itemName)) { return false; } - if (!archivable.serialize(item)) { + if (!archivable.Write(item)) { return false; } - if (statement.run() != ArchiveStatement::Result::Done) { + if (statement.Run() != ArchiveStatement::Result::kDone) { return false; } - int64_t lastInsert = _db->lastInsertRowID(); + int64_t lastInsert = database_->GetLastInsertRowID(); if (!definition.autoAssignName && lastInsert != static_cast(itemName)) { @@ -88,30 +90,31 @@ bool Archive::archiveInstance(const ArchiveDef& definition, * If any of the nested calls fail, we would have already checked for the * failure and returned. */ - transaction.markWritesSuccessful(); + transaction.MarkWritesAsReadyForCommit(); return true; } -bool Archive::unarchiveInstance(const ArchiveDef& definition, - ArchiveSerializable::ArchiveName name, - ArchiveSerializable& archivable) { - UnarchiveStep stepper = [&archivable](ArchiveItem& item) { - archivable.deserialize(item); +bool Archive::UnarchiveInstance(const ArchiveDef& definition, + Archivable::ArchiveName name, + Archivable& archivable) { + UnarchiveStep stepper = [&archivable](ArchiveLocation& item) { + archivable.Read(item); return false /* no-more after single read */; }; - return unarchiveInstances(definition, stepper, name) == 1; + return UnarchiveInstances(definition, stepper, name) == 1; } -size_t Archive::unarchiveInstances(const ArchiveDef& definition, +size_t Archive::UnarchiveInstances(const ArchiveDef& definition, Archive::UnarchiveStep stepper, - ArchiveSerializable::ArchiveName name) { - if (!isReady()) { + Archivable::ArchiveName name) { + if (!IsReady()) { return 0; } - const auto* registration = _db->registrationForDefinition(definition); + const auto* registration = + database_->GetRegistrationForDefinition(definition); if (registration == nullptr) { return 0; @@ -119,9 +122,9 @@ size_t Archive::unarchiveInstances(const ArchiveDef& definition, const bool isQueryingSingle = name != ArchiveNameAuto; - auto statement = registration->queryStatement(isQueryingSingle); + auto statement = registration->GetQueryStatement(isQueryingSingle); - if (!statement.isReady() || !statement.reset()) { + if (!statement.IsReady() || !statement.Reset()) { return 0; } @@ -130,13 +133,13 @@ size_t Archive::unarchiveInstances(const ArchiveDef& definition, * If a single statement is being queried for, bind the name as a statement * argument. */ - if (!statement.bind(ArchiveClassRegistration::NameIndex, name)) { + if (!statement.WriteValue(ArchiveClassRegistration::NameIndex, name)) { return 0; } } - if (statement.columnCount() != - registration->memberCount() + 1 /* primary key */) { + if (statement.GetColumnCount() != + registration->GetMemberCount() + 1 /* primary key */) { return 0; } @@ -144,17 +147,17 @@ size_t Archive::unarchiveInstances(const ArchiveDef& definition, * Acquire a transaction but never mark it successful since we will never * be committing any writes to the database during unarchiving. */ - auto transaction = _db->acquireTransaction(_transactionCount); + auto transaction = database_->CreateTransaction(transaction_count_); size_t itemsRead = 0; - while (statement.run() == ArchiveStatement::Result::Row) { + while (statement.Run() == ArchiveStatement::Result::kRow) { itemsRead++; /* * Prepare a fresh archive item for the given statement */ - ArchiveItem item(*this, statement, *registration, name); + ArchiveLocation item(*this, statement, *registration, name); if (!stepper(item)) { break; @@ -168,47 +171,45 @@ size_t Archive::unarchiveInstances(const ArchiveDef& definition, return itemsRead; } -ArchiveItem::ArchiveItem(Archive& context, - ArchiveStatement& statement, - const ArchiveClassRegistration& registration, - ArchiveSerializable::ArchiveName name) - : _context(context), - _statement(statement), - _registration(registration), - _name(name), - _currentClass(registration.className()) {} +ArchiveLocation::ArchiveLocation(Archive& context, + ArchiveStatement& statement, + const ArchiveClassRegistration& registration, + Archivable::ArchiveName name) + : context_(context), + statement_(statement), + registration_(registration), + name_(name), + current_class_(registration.GetClassName()) {} -ArchiveSerializable::ArchiveName ArchiveItem::name() const { - return _name; +Archivable::ArchiveName ArchiveLocation::Name() const { + return name_; } -bool ArchiveItem::encode(ArchiveSerializable::Member member, - const std::string& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.bind(found.first, item) : false; +bool ArchiveLocation::Write(ArchiveDef::Member member, + const std::string& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.WriteValue(found.first, item) : false; } -bool ArchiveItem::encodeIntegral(ArchiveSerializable::Member member, - int64_t item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.bind(found.first, item) : false; +bool ArchiveLocation::WriteIntegral(ArchiveDef::Member member, int64_t item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.WriteValue(found.first, item) : false; } -bool ArchiveItem::encode(ArchiveSerializable::Member member, double item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.bind(found.first, item) : false; +bool ArchiveLocation::Write(ArchiveDef::Member member, double item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.WriteValue(found.first, item) : false; } -bool ArchiveItem::encode(ArchiveSerializable::Member member, - const Allocation& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.bind(found.first, item) : false; +bool ArchiveLocation::Write(ArchiveDef::Member member, const Allocation& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.WriteValue(found.first, item) : false; } -bool ArchiveItem::encode(ArchiveSerializable::Member member, - const ArchiveDef& otherDef, - const ArchiveSerializable& other) { - auto found = _registration.findColumn(_currentClass, member); +bool ArchiveLocation::Write(ArchiveDef::Member member, + const ArchiveDef& otherDef, + const Archivable& other) { + auto found = registration_.FindColumn(current_class_, member); if (!found.second) { return false; @@ -220,25 +221,25 @@ bool ArchiveItem::encode(ArchiveSerializable::Member member, * archival (via `other.archiveName()`). */ int64_t lastInsert = 0; - if (!_context.archiveInstance(otherDef, other, lastInsert)) { + if (!context_.ArchiveInstance(otherDef, other, lastInsert)) { return false; } /* * Bind the name of the serialiable */ - if (!_statement.bind(found.first, lastInsert)) { + if (!statement_.WriteValue(found.first, lastInsert)) { return false; } return true; } -std::pair ArchiveItem::encodeVectorKeys( +std::pair ArchiveLocation::WriteVectorKeys( std::vector&& members) { ArchiveVector vector(std::move(members)); int64_t vectorID = 0; - if (!_context.archiveInstance(ArchiveVector::ArchiveDefinition, // + if (!context_.ArchiveInstance(ArchiveVector::ArchiveDefinition, // vector, // vectorID)) { return {false, 0}; @@ -246,11 +247,11 @@ std::pair ArchiveItem::encodeVectorKeys( return {true, vectorID}; } -bool ArchiveItem::decodeVectorKeys(ArchiveSerializable::ArchiveName name, - std::vector& members) { +bool ArchiveLocation::ReadVectorKeys(Archivable::ArchiveName name, + std::vector& members) { ArchiveVector vector; - if (!_context.unarchiveInstance(ArchiveVector::ArchiveDefinition, name, + if (!context_.UnarchiveInstance(ArchiveVector::ArchiveDefinition, name, vector)) { return false; } @@ -262,32 +263,30 @@ bool ArchiveItem::decodeVectorKeys(ArchiveSerializable::ArchiveName name, return true; } -bool ArchiveItem::decode(ArchiveSerializable::Member member, - std::string& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.column(found.first, item) : false; +bool ArchiveLocation::Read(ArchiveDef::Member member, std::string& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.ReadValue(found.first, item) : false; } -bool ArchiveItem::decodeIntegral(ArchiveSerializable::Member member, - int64_t& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.column(found.first, item) : false; +bool ArchiveLocation::ReadIntegral(ArchiveDef::Member member, int64_t& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.ReadValue(found.first, item) : false; } -bool ArchiveItem::decode(ArchiveSerializable::Member member, double& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.column(found.first, item) : false; +bool ArchiveLocation::Read(ArchiveDef::Member member, double& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.ReadValue(found.first, item) : false; } -bool ArchiveItem::decode(ArchiveSerializable::Member member, Allocation& item) { - auto found = _registration.findColumn(_currentClass, member); - return found.second ? _statement.column(found.first, item) : false; +bool ArchiveLocation::Read(ArchiveDef::Member member, Allocation& item) { + auto found = registration_.FindColumn(current_class_, member); + return found.second ? statement_.ReadValue(found.first, item) : false; } -bool ArchiveItem::decode(ArchiveSerializable::Member member, - const ArchiveDef& otherDef, - ArchiveSerializable& other) { - auto found = _registration.findColumn(_currentClass, member); +bool ArchiveLocation::Read(ArchiveDef::Member member, + const ArchiveDef& otherDef, + Archivable& other) { + auto found = registration_.FindColumn(current_class_, member); /* * Make sure a member is present at that column @@ -300,14 +299,14 @@ bool ArchiveItem::decode(ArchiveSerializable::Member member, * Try to find the foreign key in the current items row */ int64_t foreignKey = 0; - if (!_statement.column(found.first, foreignKey)) { + if (!statement_.ReadValue(found.first, foreignKey)) { return false; } /* * Find the other item and unarchive by this foreign key */ - if (!_context.unarchiveInstance(otherDef, foreignKey, other)) { + if (!context_.UnarchiveInstance(otherDef, foreignKey, other)) { return false; } diff --git a/engine/src/flutter/impeller/archivist/archive.h b/engine/src/flutter/impeller/archivist/archive.h index aa3ae54989..97ebd6593c 100644 --- a/engine/src/flutter/impeller/archivist/archive.h +++ b/engine/src/flutter/impeller/archivist/archive.h @@ -10,36 +10,27 @@ #include #include "flutter/fml/macros.h" +#include "impeller/archivist/archivable.h" #include "impeller/base/allocation.h" namespace impeller { -class ArchiveItem; +class ArchiveLocation; class ArchiveClassRegistration; class ArchiveDatabase; class ArchiveStatement; -class ArchiveSerializable { - public: +struct ArchiveDef { using Member = uint64_t; using Members = std::vector; - using ArchiveName = uint64_t; - virtual ArchiveName archiveName() const = 0; - - virtual bool serialize(ArchiveItem& item) const = 0; - - virtual bool deserialize(ArchiveItem& item) = 0; -}; - -struct ArchiveDef { const ArchiveDef* superClass; const std::string className; const bool autoAssignName; - const ArchiveSerializable::Members members; + const Members members; }; -static const ArchiveSerializable::ArchiveName ArchiveNameAuto = 0; +static const Archivable::ArchiveName ArchiveNameAuto = 0; class Archive { public: @@ -47,84 +38,79 @@ class Archive { ~Archive(); - bool isReady() const; + bool IsReady() const; - template < - class T, - class = std::enable_if::value>> - bool archive(const T& archivable) { + template ::value>> + bool Write(const T& archivable) { const ArchiveDef& def = T::ArchiveDefinition; - int64_t unusedLast = 0; - return archiveInstance(def, archivable, unusedLast); + int64_t unused_last = 0; + return ArchiveInstance(def, archivable, unused_last); } - template < - class T, - class = std::enable_if::value>> - bool unarchive(ArchiveSerializable::ArchiveName name, T& archivable) { + template ::value>> + bool Read(Archivable::ArchiveName name, T& archivable) { const ArchiveDef& def = T::ArchiveDefinition; - return unarchiveInstance(def, name, archivable); + return UnarchiveInstance(def, name, archivable); } - using UnarchiveStep = std::function; + using UnarchiveStep = std::function; - template < - class T, - class = std::enable_if::value>> - size_t unarchive(UnarchiveStep stepper) { + template ::value>> + size_t Read(UnarchiveStep stepper) { const ArchiveDef& def = T::ArchiveDefinition; - return unarchiveInstances(def, stepper, ArchiveNameAuto); + return UnarchiveInstances(def, stepper, ArchiveNameAuto); } private: - std::unique_ptr _db; - int64_t _transactionCount = 0; + std::unique_ptr database_; + int64_t transaction_count_ = 0; - friend class ArchiveItem; + friend class ArchiveLocation; - bool archiveInstance(const ArchiveDef& definition, - const ArchiveSerializable& archivable, + bool ArchiveInstance(const ArchiveDef& definition, + const Archivable& archivable, int64_t& lastInsertID); - bool unarchiveInstance(const ArchiveDef& definition, - ArchiveSerializable::ArchiveName name, - ArchiveSerializable& archivable); - size_t unarchiveInstances(const ArchiveDef& definition, + bool UnarchiveInstance(const ArchiveDef& definition, + Archivable::ArchiveName name, + Archivable& archivable); + size_t UnarchiveInstances(const ArchiveDef& definition, UnarchiveStep stepper, - ArchiveSerializable::ArchiveName optionalName); + Archivable::ArchiveName optionalName); FML_DISALLOW_COPY_AND_ASSIGN(Archive); }; -class ArchiveItem { +class ArchiveLocation { public: template ::value>> - bool encode(ArchiveSerializable::Member member, T item) { - return encodeIntegral(member, static_cast(item)); + bool Write(ArchiveDef::Member member, T item) { + return WriteIntegral(member, static_cast(item)); } - bool encode(ArchiveSerializable::Member member, double item); + bool Write(ArchiveDef::Member member, double item); - bool encode(ArchiveSerializable::Member member, const std::string& item); + bool Write(ArchiveDef::Member member, const std::string& item); - bool encode(ArchiveSerializable::Member member, const Allocation& allocation); + bool Write(ArchiveDef::Member member, const Allocation& allocation); - template < - class T, - class = std::enable_if::value>> - bool encodeArchivable(ArchiveSerializable::Member member, const T& other) { + template ::value>> + bool WriteArchivable(ArchiveDef::Member member, const T& other) { const ArchiveDef& otherDef = T::ArchiveDefinition; - return encode(member, otherDef, other); + return Write(member, otherDef, other); } template ::value>> - bool encodeEnum(ArchiveSerializable::Member member, const T& item) { - return encodeIntegral(member, static_cast(item)); + bool WriteEnum(ArchiveDef::Member member, const T& item) { + return WriteIntegral(member, static_cast(item)); } - template < - class T, - class = std::enable_if::value>> - bool encode(ArchiveSerializable::Member member, const std::vector& items) { + template ::value>> + bool Write(ArchiveDef::Member member, const std::vector& items) { /* * All items in the vector are individually encoded and their keys noted */ @@ -134,7 +120,7 @@ class ArchiveItem { const ArchiveDef& itemDefinition = T::ArchiveDefinition; for (const auto& item : items) { int64_t added = 0; - bool result = _context.archiveInstance(itemDefinition, item, added); + bool result = context_.ArchiveInstance(itemDefinition, item, added); if (!result) { return false; } @@ -144,69 +130,66 @@ class ArchiveItem { /* * The keys are flattened into the vectors table. Write to that table */ - auto vectorInsert = encodeVectorKeys(std::move(members)); + auto vectorInsert = WriteVectorKeys(std::move(members)); if (!vectorInsert.first) { return false; } - return encodeIntegral(member, vectorInsert.second); + return WriteIntegral(member, vectorInsert.second); } template ::value && - std::is_base_of::value>> - bool encodeSuper(const Current& thiz) { - std::string oldClass = _currentClass; - _currentClass = Super::ArchiveDefinition.className; + class = std::enable_if::value && + std::is_base_of::value>> + bool WriteSuper(const Current& thiz) { + std::string oldClass = current_class_; + current_class_ = Super::ArchiveDefinition.className; auto success = thiz.Super::serialize(*this); - _currentClass = oldClass; + current_class_ = oldClass; return success; } template ::value>> - bool decode(ArchiveSerializable::Member member, T& item) { + bool Read(ArchiveDef::Member member, T& item) { int64_t decoded = 0; - auto result = decodeIntegral(member, decoded); + auto result = ReadIntegral(member, decoded); item = static_cast(decoded); return result; } - bool decode(ArchiveSerializable::Member member, double& item); + bool Read(ArchiveDef::Member member, double& item); - bool decode(ArchiveSerializable::Member member, std::string& item); + bool Read(ArchiveDef::Member member, std::string& item); - bool decode(ArchiveSerializable::Member member, Allocation& allocation); + bool Read(ArchiveDef::Member member, Allocation& allocation); - template < - class T, - class = std::enable_if::value>> - bool decodeArchivable(ArchiveSerializable::Member member, T& other) { + template ::value>> + bool ReadArchivable(ArchiveDef::Member member, T& other) { const ArchiveDef& otherDef = T::ArchiveDefinition; return decode(member, otherDef, other); } template ::value>> - bool decodeEnum(ArchiveSerializable::Member member, T& item) { + bool ReadEnum(ArchiveDef::Member member, T& item) { int64_t desugared = 0; - if (decodeIntegral(member, desugared)) { + if (ReadIntegral(member, desugared)) { item = static_cast(desugared); return true; } return false; } - template < - class T, - class = std::enable_if::value>> - bool decode(ArchiveSerializable::Member member, std::vector& items) { + template ::value>> + bool Read(ArchiveDef::Member member, std::vector& items) { /* * From the member, find the foreign key of the vector */ int64_t vectorForeignKey = 0; - if (!decodeIntegral(member, vectorForeignKey)) { + if (!ReadIntegral(member, vectorForeignKey)) { return false; } @@ -214,7 +197,7 @@ class ArchiveItem { * Get vector keys */ std::vector keys; - if (!decodeVectorKeys(vectorForeignKey, keys)) { + if (!ReadVectorKeys(vectorForeignKey, keys)) { return false; } @@ -222,7 +205,7 @@ class ArchiveItem { for (const auto& key : keys) { items.emplace_back(); - if (!_context.unarchiveInstance(otherDef, key, items.back())) { + if (!context_.UnarchiveInstance(otherDef, key, items.back())) { return false; } } @@ -232,51 +215,50 @@ class ArchiveItem { template ::value && - std::is_base_of::value>> - bool decodeSuper(Current& thiz) { - std::string oldClass = _currentClass; - _currentClass = Super::ArchiveDefinition.className; + class = std::enable_if::value && + std::is_base_of::value>> + bool ReadSuper(Current& thiz) { + std::string oldClass = current_class_; + current_class_ = Super::ArchiveDefinition.className; auto success = thiz.Super::deserialize(*this); - _currentClass = oldClass; + current_class_ = oldClass; return success; } - ArchiveSerializable::ArchiveName name() const; + Archivable::ArchiveName Name() const; private: - Archive& _context; - ArchiveStatement& _statement; - const ArchiveClassRegistration& _registration; - ArchiveSerializable::ArchiveName _name; - std::string _currentClass; + Archive& context_; + ArchiveStatement& statement_; + const ArchiveClassRegistration& registration_; + Archivable::ArchiveName name_; + std::string current_class_; friend class Archive; - ArchiveItem(Archive& context, - ArchiveStatement& statement, - const ArchiveClassRegistration& registration, - ArchiveSerializable::ArchiveName name); + ArchiveLocation(Archive& context, + ArchiveStatement& statement, + const ArchiveClassRegistration& registration, + Archivable::ArchiveName name); - bool encodeIntegral(ArchiveSerializable::Member member, int64_t item); + bool WriteIntegral(ArchiveDef::Member member, int64_t item); - bool decodeIntegral(ArchiveSerializable::Member member, int64_t& item); + bool ReadIntegral(ArchiveDef::Member member, int64_t& item); - std::pair encodeVectorKeys(std::vector&& members); + std::pair WriteVectorKeys(std::vector&& members); - bool decodeVectorKeys(ArchiveSerializable::ArchiveName name, - std::vector& members); + bool ReadVectorKeys(Archivable::ArchiveName name, + std::vector& members); - bool encode(ArchiveSerializable::Member member, - const ArchiveDef& otherDef, - const ArchiveSerializable& other); + bool Write(ArchiveDef::Member member, + const ArchiveDef& otherDef, + const Archivable& other); - bool decode(ArchiveSerializable::Member member, - const ArchiveDef& otherDef, - ArchiveSerializable& other); + bool Read(ArchiveDef::Member member, + const ArchiveDef& otherDef, + Archivable& other); - FML_DISALLOW_COPY_AND_ASSIGN(ArchiveItem); + FML_DISALLOW_COPY_AND_ASSIGN(ArchiveLocation); }; } // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archive_class_registration.cc b/engine/src/flutter/impeller/archivist/archive_class_registration.cc index cc797f6202..e672759042 100644 --- a/engine/src/flutter/impeller/archivist/archive_class_registration.cc +++ b/engine/src/flutter/impeller/archivist/archive_class_registration.cc @@ -17,7 +17,7 @@ static const char* const ArchiveTablePrefix = "RL_"; ArchiveClassRegistration::ArchiveClassRegistration(ArchiveDatabase& database, ArchiveDef definition) - : _database(database), _className(definition.className), _memberCount(0) { + : database_(database), class_name_(definition.className) { /* * Each class in the archive class hierarchy is assigned an entry in the * class map. @@ -26,36 +26,36 @@ ArchiveClassRegistration::ArchiveClassRegistration(ArchiveDatabase& database, size_t currentMember = 1; while (current != nullptr) { auto membersInCurrent = current->members.size(); - _memberCount += membersInCurrent; + member_count_ += membersInCurrent; MemberColumnMap map; for (const auto& member : current->members) { map[member] = currentMember++; } - _classMap[current->className] = map; + class_map_[current->className] = map; current = current->superClass; } - _isReady = createTable(definition.autoAssignName); + is_ready_ = CreateTable(definition.autoAssignName); } -const std::string& ArchiveClassRegistration::className() const { - return _className; +const std::string& ArchiveClassRegistration::GetClassName() const { + return class_name_; } -size_t ArchiveClassRegistration::memberCount() const { - return _memberCount; +size_t ArchiveClassRegistration::GetMemberCount() const { + return member_count_; } -bool ArchiveClassRegistration::isReady() const { - return _isReady; +bool ArchiveClassRegistration::IsReady() const { + return is_ready_; } -ArchiveClassRegistration::ColumnResult ArchiveClassRegistration::findColumn( +ArchiveClassRegistration::ColumnResult ArchiveClassRegistration::FindColumn( const std::string& className, - ArchiveSerializable::Member member) const { - auto found = _classMap.find(className); + ArchiveDef::Member member) const { + auto found = class_map_.find(className); - if (found == _classMap.end()) { + if (found == class_map_.end()) { return {0, false}; } @@ -70,8 +70,8 @@ ArchiveClassRegistration::ColumnResult ArchiveClassRegistration::findColumn( return {foundColumn->second, true}; } -bool ArchiveClassRegistration::createTable(bool autoIncrement) { - if (_className.size() == 0 || _memberCount == 0) { +bool ArchiveClassRegistration::CreateTable(bool autoIncrement) { + if (class_name_.size() == 0 || member_count_ == 0) { return false; } @@ -82,14 +82,14 @@ bool ArchiveClassRegistration::createTable(bool autoIncrement) { * a statement and check its validity before running. */ stream << "CREATE TABLE IF NOT EXISTS " << ArchiveTablePrefix - << _className.c_str() << " (" << ArchivePrimaryKeyColumnName; + << class_name_.c_str() << " (" << ArchivePrimaryKeyColumnName; if (autoIncrement) { stream << " INTEGER PRIMARY KEY AUTOINCREMENT, "; } else { stream << " INTEGER PRIMARY KEY, "; } - for (size_t i = 0, columns = _memberCount; i < columns; i++) { + for (size_t i = 0, columns = member_count_; i < columns; i++) { stream << ArchiveColumnPrefix << std::to_string(i + 1); if (i != columns - 1) { stream << ", "; @@ -97,29 +97,30 @@ bool ArchiveClassRegistration::createTable(bool autoIncrement) { } stream << ");"; - auto statement = _database.acquireStatement(stream.str()); + auto statement = database_.CreateStatement(stream.str()); - if (!statement.isReady()) { + if (!statement.IsReady()) { return false; } - if (!statement.reset()) { + if (!statement.Reset()) { return false; } - return statement.run() == ArchiveStatement::Result::Done; + return statement.Run() == ArchiveStatement::Result::kDone; } -ArchiveStatement ArchiveClassRegistration::queryStatement(bool single) const { +ArchiveStatement ArchiveClassRegistration::GetQueryStatement( + bool single) const { std::stringstream stream; stream << "SELECT " << ArchivePrimaryKeyColumnName << ", "; - for (size_t i = 0, members = _memberCount; i < members; i++) { + for (size_t i = 0, members = member_count_; i < members; i++) { stream << ArchiveColumnPrefix << std::to_string(i + 1); if (i != members - 1) { stream << ","; } } - stream << " FROM " << ArchiveTablePrefix << _className; + stream << " FROM " << ArchiveTablePrefix << class_name_; if (single) { stream << " WHERE " << ArchivePrimaryKeyColumnName << " = ?"; @@ -129,22 +130,22 @@ ArchiveStatement ArchiveClassRegistration::queryStatement(bool single) const { stream << ";"; - return _database.acquireStatement(stream.str()); + return database_.CreateStatement(stream.str()); } -ArchiveStatement ArchiveClassRegistration::insertStatement() const { +ArchiveStatement ArchiveClassRegistration::GetInsertStatement() const { std::stringstream stream; - stream << "INSERT OR REPLACE INTO " << ArchiveTablePrefix << _className + stream << "INSERT OR REPLACE INTO " << ArchiveTablePrefix << class_name_ << " VALUES ( ?, "; - for (size_t i = 0; i < _memberCount; i++) { + for (size_t i = 0; i < member_count_; i++) { stream << "?"; - if (i != _memberCount - 1) { + if (i != member_count_ - 1) { stream << ", "; } } stream << ");"; - return _database.acquireStatement(stream.str()); + return database_.CreateStatement(stream.str()); } } // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archive_class_registration.h b/engine/src/flutter/impeller/archivist/archive_class_registration.h index 22b8231c1e..94bfddf8bd 100644 --- a/engine/src/flutter/impeller/archivist/archive_class_registration.h +++ b/engine/src/flutter/impeller/archivist/archive_class_registration.h @@ -12,36 +12,36 @@ namespace impeller { class ArchiveClassRegistration { public: using ColumnResult = std::pair; - ColumnResult findColumn(const std::string& className, - ArchiveSerializable::Member member) const; + ColumnResult FindColumn(const std::string& className, + ArchiveDef::Member member) const; - const std::string& className() const; + const std::string& GetClassName() const; - size_t memberCount() const; + size_t GetMemberCount() const; - bool isReady() const; + bool IsReady() const; - ArchiveStatement insertStatement() const; + ArchiveStatement GetInsertStatement() const; - ArchiveStatement queryStatement(bool single) const; + ArchiveStatement GetQueryStatement(bool single) const; static const size_t NameIndex = 0; private: - using MemberColumnMap = std::map; + using MemberColumnMap = std::map; using ClassMap = std::map; friend class ArchiveDatabase; ArchiveClassRegistration(ArchiveDatabase& database, ArchiveDef definition); - bool createTable(bool autoIncrement); + bool CreateTable(bool autoIncrement); - ArchiveDatabase& _database; - ClassMap _classMap; - std::string _className; - size_t _memberCount; - bool _isReady; + ArchiveDatabase& database_; + ClassMap class_map_; + std::string class_name_; + size_t member_count_ = 0; + bool is_ready_ = false; FML_DISALLOW_COPY_AND_ASSIGN(ArchiveClassRegistration); }; diff --git a/engine/src/flutter/impeller/archivist/archive_database.cc b/engine/src/flutter/impeller/archivist/archive_database.cc index a99707a513..75b13d7e55 100644 --- a/engine/src/flutter/impeller/archivist/archive_database.cc +++ b/engine/src/flutter/impeller/archivist/archive_database.cc @@ -16,7 +16,7 @@ namespace impeller { -#define DB_HANDLE reinterpret_cast(_db) +#define DB_HANDLE reinterpret_cast(database_) ArchiveDatabase::ArchiveDatabase(const std::string& filename, bool recreate) { if (recreate) { @@ -30,45 +30,45 @@ ArchiveDatabase::ArchiveDatabase(const std::string& filename, bool recreate) { sqlite3* db = nullptr; auto res = ::sqlite3_open(filename.c_str(), &db); - _db = db; + database_ = db; - if (res != SQLITE_OK || _db == nullptr) { + if (res != SQLITE_OK || database_ == nullptr) { return; } - _beginTransaction = std::unique_ptr( - new ArchiveStatement(_db, "BEGIN TRANSACTION;")); + begin_transaction_stmt_ = std::unique_ptr( + new ArchiveStatement(database_, "BEGIN TRANSACTION;")); - if (!_beginTransaction->isReady()) { + if (!begin_transaction_stmt_->IsReady()) { return; } - _endTransaction = std::unique_ptr( - new ArchiveStatement(_db, "END TRANSACTION;")); + end_transaction_stmt_ = std::unique_ptr( + new ArchiveStatement(database_, "END TRANSACTION;")); - if (!_endTransaction->isReady()) { + if (!end_transaction_stmt_->IsReady()) { return; } - _rollbackTransaction = std::unique_ptr( - new ArchiveStatement(_db, "ROLLBACK TRANSACTION;")); + rollback_transaction_stmt_ = std::unique_ptr( + new ArchiveStatement(database_, "ROLLBACK TRANSACTION;")); - if (!_rollbackTransaction->isReady()) { + if (!rollback_transaction_stmt_->IsReady()) { return; } - _ready = true; + ready_ = true; } ArchiveDatabase::~ArchiveDatabase() { ::sqlite3_close(DB_HANDLE); } -bool ArchiveDatabase::isReady() const { - return _ready; +bool ArchiveDatabase::IsReady() const { + return ready_; } -int64_t ArchiveDatabase::lastInsertRowID() { +int64_t ArchiveDatabase::GetLastInsertRowID() { return ::sqlite3_last_insert_rowid(DB_HANDLE); } @@ -77,13 +77,13 @@ static inline const ArchiveClassRegistration* RegistrationIfReady( if (registration == nullptr) { return nullptr; } - return registration->isReady() ? registration : nullptr; + return registration->IsReady() ? registration : nullptr; } -const ArchiveClassRegistration* ArchiveDatabase::registrationForDefinition( +const ArchiveClassRegistration* ArchiveDatabase::GetRegistrationForDefinition( const ArchiveDef& definition) { - auto found = _registrations.find(definition.className); - if (found != _registrations.end()) { + auto found = registrations_.find(definition.className); + if (found != registrations_.end()) { /* * This class has already been registered. */ @@ -96,7 +96,7 @@ const ArchiveClassRegistration* ArchiveDatabase::registrationForDefinition( auto registration = std::unique_ptr( new ArchiveClassRegistration(*this, definition)); auto res = - _registrations.emplace(definition.className, std::move(registration)); + registrations_.emplace(definition.className, std::move(registration)); /* * If the new class registation is ready, return it to the caller. @@ -105,17 +105,17 @@ const ArchiveClassRegistration* ArchiveDatabase::registrationForDefinition( : nullptr; } -ArchiveStatement ArchiveDatabase::acquireStatement( +ArchiveStatement ArchiveDatabase::CreateStatement( const std::string& statementString) const { - return ArchiveStatement{_db, statementString}; + return ArchiveStatement{database_, statementString}; } -ArchiveTransaction ArchiveDatabase::acquireTransaction( +ArchiveTransaction ArchiveDatabase::CreateTransaction( int64_t& transactionCount) { - return ArchiveTransaction{transactionCount, // - *_beginTransaction, // - *_endTransaction, // - *_rollbackTransaction}; + return ArchiveTransaction{transactionCount, // + *begin_transaction_stmt_, // + *end_transaction_stmt_, // + *rollback_transaction_stmt_}; } } // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archive_database.h b/engine/src/flutter/impeller/archivist/archive_database.h index aa368b85a9..6092c3e231 100644 --- a/engine/src/flutter/impeller/archivist/archive_database.h +++ b/engine/src/flutter/impeller/archivist/archive_database.h @@ -22,27 +22,27 @@ class ArchiveDatabase { ~ArchiveDatabase(); - bool isReady() const; + bool IsReady() const; - int64_t lastInsertRowID(); + int64_t GetLastInsertRowID(); - const ArchiveClassRegistration* registrationForDefinition( + const ArchiveClassRegistration* GetRegistrationForDefinition( const ArchiveDef& definition); - ArchiveTransaction acquireTransaction(int64_t& transactionCount); + ArchiveTransaction CreateTransaction(int64_t& transactionCount); private: - void* _db = nullptr; - bool _ready = false; + void* database_ = nullptr; + bool ready_ = false; std::map> - _registrations; - std::unique_ptr _beginTransaction; - std::unique_ptr _endTransaction; - std::unique_ptr _rollbackTransaction; + registrations_; + std::unique_ptr begin_transaction_stmt_; + std::unique_ptr end_transaction_stmt_; + std::unique_ptr rollback_transaction_stmt_; friend class ArchiveClassRegistration; - ArchiveStatement acquireStatement(const std::string& statementString) const; + ArchiveStatement CreateStatement(const std::string& statementString) const; FML_DISALLOW_COPY_AND_ASSIGN(ArchiveDatabase); }; diff --git a/engine/src/flutter/impeller/archivist/archive_statement.cc b/engine/src/flutter/impeller/archivist/archive_statement.cc index 69f143580b..de4bec087a 100644 --- a/engine/src/flutter/impeller/archivist/archive_statement.cc +++ b/engine/src/flutter/impeller/archivist/archive_statement.cc @@ -11,7 +11,7 @@ namespace impeller { -#define STATEMENT_HANDLE reinterpret_cast<::sqlite3_stmt*>(_statement) +#define STATEMENT_HANDLE reinterpret_cast<::sqlite3_stmt*>(statement_handle_) ArchiveStatement::ArchiveStatement(void* db, const std::string& statememt) { ::sqlite3_stmt* statementHandle = nullptr; @@ -20,28 +20,28 @@ ArchiveStatement::ArchiveStatement(void* db, const std::string& statememt) { static_cast(statememt.size()), // &statementHandle, // nullptr); - _statement = statementHandle; - _ready = res == SQLITE_OK && _statement != nullptr; + statement_handle_ = statementHandle; + ready_ = res == SQLITE_OK && statement_handle_ != nullptr; } ArchiveStatement::ArchiveStatement(ArchiveStatement&& other) - : _statement(other._statement), _ready(other._ready) { - other._statement = nullptr; - other._ready = false; + : statement_handle_(other.statement_handle_), ready_(other.ready_) { + other.statement_handle_ = nullptr; + other.ready_ = false; } ArchiveStatement::~ArchiveStatement() { - if (_statement != nullptr) { + if (statement_handle_ != nullptr) { auto res = ::sqlite3_finalize(STATEMENT_HANDLE); FML_CHECK(res == SQLITE_OK) << "Unable to finalize the archive."; } } -bool ArchiveStatement::isReady() const { - return _ready; +bool ArchiveStatement::IsReady() const { + return ready_; } -bool ArchiveStatement::reset() { +bool ArchiveStatement::Reset() { if (::sqlite3_reset(STATEMENT_HANDLE) != SQLITE_OK) { return false; } @@ -67,14 +67,14 @@ static constexpr int ToColumn(size_t index) { return static_cast(index); } -size_t ArchiveStatement::columnCount() { +size_t ArchiveStatement::GetColumnCount() { return ::sqlite3_column_count(STATEMENT_HANDLE); } /* * Bind Variants */ -bool ArchiveStatement::bind(size_t index, const std::string& item) { +bool ArchiveStatement::WriteValue(size_t index, const std::string& item) { return ::sqlite3_bind_text(STATEMENT_HANDLE, // ToParam(index), // item.data(), // @@ -82,19 +82,19 @@ bool ArchiveStatement::bind(size_t index, const std::string& item) { SQLITE_TRANSIENT) == SQLITE_OK; } -bool ArchiveStatement::bindIntegral(size_t index, int64_t item) { +bool ArchiveStatement::BindIntegral(size_t index, int64_t item) { return ::sqlite3_bind_int64(STATEMENT_HANDLE, // ToParam(index), // item) == SQLITE_OK; } -bool ArchiveStatement::bind(size_t index, double item) { +bool ArchiveStatement::WriteValue(size_t index, double item) { return ::sqlite3_bind_double(STATEMENT_HANDLE, // ToParam(index), // item) == SQLITE_OK; } -bool ArchiveStatement::bind(size_t index, const Allocation& item) { +bool ArchiveStatement::WriteValue(size_t index, const Allocation& item) { return ::sqlite3_bind_blob(STATEMENT_HANDLE, // ToParam(index), // item.GetBuffer(), // @@ -105,12 +105,12 @@ bool ArchiveStatement::bind(size_t index, const Allocation& item) { /* * Column Variants */ -bool ArchiveStatement::columnIntegral(size_t index, int64_t& item) { +bool ArchiveStatement::ColumnIntegral(size_t index, int64_t& item) { item = ::sqlite3_column_int64(STATEMENT_HANDLE, ToColumn(index)); return true; } -bool ArchiveStatement::column(size_t index, double& item) { +bool ArchiveStatement::ReadValue(size_t index, double& item) { item = ::sqlite3_column_double(STATEMENT_HANDLE, ToColumn(index)); return true; } @@ -123,7 +123,7 @@ bool ArchiveStatement::column(size_t index, double& item) { * TL;DR: Access blobs then bytes. */ -bool ArchiveStatement::column(size_t index, std::string& item) { +bool ArchiveStatement::ReadValue(size_t index, std::string& item) { /* * Get the character data */ @@ -142,7 +142,7 @@ bool ArchiveStatement::column(size_t index, std::string& item) { return true; } -bool ArchiveStatement::column(size_t index, Allocation& item) { +bool ArchiveStatement::ReadValue(size_t index, Allocation& item) { /* * Get a blob pointer */ @@ -165,14 +165,14 @@ bool ArchiveStatement::column(size_t index, Allocation& item) { return true; } -ArchiveStatement::Result ArchiveStatement::run() { +ArchiveStatement::Result ArchiveStatement::Run() { switch (::sqlite3_step(STATEMENT_HANDLE)) { case SQLITE_DONE: - return Result::Done; + return Result::kDone; case SQLITE_ROW: - return Result::Row; + return Result::kRow; default: - return Result::Failure; + return Result::kFailure; } } diff --git a/engine/src/flutter/impeller/archivist/archive_statement.h b/engine/src/flutter/impeller/archivist/archive_statement.h index 0110d853b2..d60be1b4be 100644 --- a/engine/src/flutter/impeller/archivist/archive_statement.h +++ b/engine/src/flutter/impeller/archivist/archive_statement.h @@ -17,53 +17,53 @@ class ArchiveStatement { ArchiveStatement(ArchiveStatement&& message); - bool isReady() const; + bool IsReady() const; - bool reset(); + bool Reset(); - bool bind(size_t index, const std::string& item); + bool WriteValue(size_t index, const std::string& item); template ::value>> - bool bind(size_t index, T item) { - return bindIntegral(index, static_cast(item)); + bool WriteValue(size_t index, T item) { + return BindIntegral(index, static_cast(item)); } - bool bind(size_t index, double item); + bool WriteValue(size_t index, double item); - bool bind(size_t index, const Allocation& item); + bool WriteValue(size_t index, const Allocation& item); template ::value>> - bool column(size_t index, T& item) { - return columnIntegral(index, item); + bool ReadValue(size_t index, T& item) { + return ColumnIntegral(index, item); } - bool column(size_t index, double& item); + bool ReadValue(size_t index, double& item); - bool column(size_t index, std::string& item); + bool ReadValue(size_t index, std::string& item); - bool column(size_t index, Allocation& item); + bool ReadValue(size_t index, Allocation& item); - size_t columnCount(); + size_t GetColumnCount(); enum class Result { - Done, - Row, - Failure, + kDone, + kRow, + kFailure, }; - Result run(); + [[nodiscard]] Result Run(); private: - void* _statement = nullptr; - bool _ready = false; + void* statement_handle_ = nullptr; + bool ready_ = false; friend class ArchiveDatabase; ArchiveStatement(void* db, const std::string& statememt); - bool bindIntegral(size_t index, int64_t item); + bool BindIntegral(size_t index, int64_t item); - bool columnIntegral(size_t index, int64_t& item); + bool ColumnIntegral(size_t index, int64_t& item); FML_DISALLOW_COPY_AND_ASSIGN(ArchiveStatement); }; diff --git a/engine/src/flutter/impeller/archivist/archive_transaction.cc b/engine/src/flutter/impeller/archivist/archive_transaction.cc index 6fe7f03e25..18d00bff96 100644 --- a/engine/src/flutter/impeller/archivist/archive_transaction.cc +++ b/engine/src/flutter/impeller/archivist/archive_transaction.cc @@ -13,40 +13,40 @@ ArchiveTransaction::ArchiveTransaction(int64_t& transactionCount, ArchiveStatement& beginStatement, ArchiveStatement& endStatement, ArchiveStatement& rollbackStatement) - : _endStatement(endStatement), - _rollbackStatement(rollbackStatement), - _transactionCount(transactionCount) { - if (_transactionCount == 0) { - _cleanup = beginStatement.run() == ArchiveStatement::Result::Done; + : end_stmt_(endStatement), + rollback_stmt_(rollbackStatement), + transaction_count_(transactionCount) { + if (transaction_count_ == 0) { + cleanup_ = beginStatement.Run() == ArchiveStatement::Result::kDone; } - _transactionCount++; + transaction_count_++; } ArchiveTransaction::ArchiveTransaction(ArchiveTransaction&& other) - : _endStatement(other._endStatement), - _rollbackStatement(other._rollbackStatement), - _transactionCount(other._transactionCount), - _cleanup(other._cleanup), - _successful(other._successful) { - other._abandoned = true; + : end_stmt_(other.end_stmt_), + rollback_stmt_(other.rollback_stmt_), + transaction_count_(other.transaction_count_), + cleanup_(other.cleanup_), + successful_(other.successful_) { + other.abandoned_ = true; } ArchiveTransaction::~ArchiveTransaction() { - if (_abandoned) { + if (abandoned_) { return; } - FML_CHECK(_transactionCount != 0); - if (_transactionCount == 1 && _cleanup) { - auto res = _successful ? _endStatement.run() : _rollbackStatement.run(); - FML_CHECK(res == ArchiveStatement::Result::Done) + FML_CHECK(transaction_count_ != 0); + if (transaction_count_ == 1 && cleanup_) { + auto res = successful_ ? end_stmt_.Run() : rollback_stmt_.Run(); + FML_CHECK(res == ArchiveStatement::Result::kDone) << "Must be able to commit the nested transaction"; } - _transactionCount--; + transaction_count_--; } -void ArchiveTransaction::markWritesSuccessful() { - _successful = true; +void ArchiveTransaction::MarkWritesAsReadyForCommit() { + successful_ = true; } } // namespace impeller diff --git a/engine/src/flutter/impeller/archivist/archive_transaction.h b/engine/src/flutter/impeller/archivist/archive_transaction.h index ed54c2281e..74fe132d7d 100644 --- a/engine/src/flutter/impeller/archivist/archive_transaction.h +++ b/engine/src/flutter/impeller/archivist/archive_transaction.h @@ -11,21 +11,30 @@ namespace impeller { class ArchiveStatement; +//------------------------------------------------------------------------------ +/// @brief All writes made to the archive within a transaction that is not +/// marked as ready for commit will be rolled back with the +/// transaction ends. +/// +/// All transactions are obtained from the `ArchiveDatabase`. +/// +/// @see `ArchiveDatabase` +/// class ArchiveTransaction { public: ArchiveTransaction(ArchiveTransaction&& transaction); ~ArchiveTransaction(); - void markWritesSuccessful(); + void MarkWritesAsReadyForCommit(); private: - ArchiveStatement& _endStatement; - ArchiveStatement& _rollbackStatement; - int64_t& _transactionCount; - bool _cleanup = false; - bool _successful = false; - bool _abandoned = false; + ArchiveStatement& end_stmt_; + ArchiveStatement& rollback_stmt_; + int64_t& transaction_count_; + bool cleanup_ = false; + bool successful_ = false; + bool abandoned_ = false; friend class ArchiveDatabase; diff --git a/engine/src/flutter/impeller/archivist/archive_vector.cc b/engine/src/flutter/impeller/archivist/archive_vector.cc index 6b99cda8c8..e642db06a7 100644 --- a/engine/src/flutter/impeller/archivist/archive_vector.cc +++ b/engine/src/flutter/impeller/archivist/archive_vector.cc @@ -9,7 +9,7 @@ namespace impeller { ArchiveVector::ArchiveVector(std::vector&& keys) - : _keys(std::move(keys)) {} + : keys_(std::move(keys)) {} ArchiveVector::ArchiveVector() {} @@ -20,35 +20,35 @@ const ArchiveDef ArchiveVector::ArchiveDefinition = { /* .members = */ {0}, }; -ArchiveSerializable::ArchiveName ArchiveVector::archiveName() const { +Archivable::ArchiveName ArchiveVector::GetArchiveName() const { return ArchiveNameAuto; } const std::vector ArchiveVector::keys() const { - return _keys; + return keys_; } -bool ArchiveVector::serialize(ArchiveItem& item) const { +bool ArchiveVector::Write(ArchiveLocation& item) const { std::stringstream stream; - for (size_t i = 0, count = _keys.size(); i < count; i++) { - stream << _keys[i]; + for (size_t i = 0, count = keys_.size(); i < count; i++) { + stream << keys_[i]; if (i != count - 1) { stream << ","; } } - return item.encode(0, stream.str()); + return item.Write(0, stream.str()); } -bool ArchiveVector::deserialize(ArchiveItem& item) { +bool ArchiveVector::Read(ArchiveLocation& item) { std::string flattened; - if (!item.decode(0, flattened)) { + if (!item.Read(0, flattened)) { return false; } std::stringstream stream(flattened); int64_t single = 0; while (stream >> single) { - _keys.emplace_back(single); + keys_.emplace_back(single); stream.ignore(); } diff --git a/engine/src/flutter/impeller/archivist/archive_vector.h b/engine/src/flutter/impeller/archivist/archive_vector.h index 99d23c02f0..e186d6f9d3 100644 --- a/engine/src/flutter/impeller/archivist/archive_vector.h +++ b/engine/src/flutter/impeller/archivist/archive_vector.h @@ -9,22 +9,22 @@ namespace impeller { -class ArchiveVector : public ArchiveSerializable { +class ArchiveVector : public Archivable { public: static const ArchiveDef ArchiveDefinition; - ArchiveName archiveName() const override; + ArchiveName GetArchiveName() const override; const std::vector keys() const; - bool serialize(ArchiveItem& item) const override; + bool Write(ArchiveLocation& item) const override; - bool deserialize(ArchiveItem& item) override; + bool Read(ArchiveLocation& item) override; private: - std::vector _keys; + std::vector keys_; - friend class ArchiveItem; + friend class ArchiveLocation; ArchiveVector(); diff --git a/engine/src/flutter/impeller/archivist/archivist_unittests.cc b/engine/src/flutter/impeller/archivist/archivist_unittests.cc index e1e44497b9..96d47d6467 100644 --- a/engine/src/flutter/impeller/archivist/archivist_unittests.cc +++ b/engine/src/flutter/impeller/archivist/archivist_unittests.cc @@ -12,30 +12,33 @@ namespace impeller { namespace testing { -static ArchiveSerializable::ArchiveName LastSample = 0; +static Archivable::ArchiveName LastSample = 0; -class Sample : public ArchiveSerializable { +class Sample : public Archivable { public: - Sample(uint64_t count = 42) : _someData(count), _name(++LastSample) {} + Sample(uint64_t count = 42) : some_data_(count) {} - uint64_t someData() const { return _someData; } + uint64_t GetSomeData() const { return some_data_; } - ArchiveName archiveName() const override { return _name; } + // |Archivable| + ArchiveName GetArchiveName() const override { return name_; } - bool serialize(ArchiveItem& item) const override { - return item.encode(999, _someData); + // |Archivable| + bool Write(ArchiveLocation& item) const override { + return item.Write(999, some_data_); }; - bool deserialize(ArchiveItem& item) override { - _name = item.name(); - return item.decode(999, _someData); + // |Archivable| + bool Read(ArchiveLocation& item) override { + name_ = item.Name(); + return item.Read(999, some_data_); }; static const ArchiveDef ArchiveDefinition; private: - uint64_t _someData; - ArchiveName _name; + uint64_t some_data_; + ArchiveName name_ = ++LastSample; FML_DISALLOW_COPY_AND_ASSIGN(Sample); }; @@ -51,7 +54,7 @@ TEST(ArchiveTest, SimpleInitialization) { auto name = "/tmp/sample.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); } ASSERT_EQ(::remove(name), 0); } @@ -60,7 +63,7 @@ TEST(ArchiveTest, AddStorageClass) { auto name = "/tmp/sample2.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); } ASSERT_EQ(::remove(name), 0); } @@ -69,9 +72,9 @@ TEST(ArchiveTest, AddData) { auto name = "/tmp/sample3.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); Sample sample; - ASSERT_TRUE(archive.archive(sample)); + ASSERT_TRUE(archive.Write(sample)); } ASSERT_EQ(::remove(name), 0); } @@ -80,11 +83,11 @@ TEST(ArchiveTest, AddDataMultiple) { auto name = "/tmp/sample4.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); for (size_t i = 0; i < 100; i++) { Sample sample(i + 1); - ASSERT_TRUE(archive.archive(sample)); + ASSERT_TRUE(archive.Write(sample)); } } ASSERT_EQ(::remove(name), 0); @@ -94,27 +97,24 @@ TEST(ArchiveTest, ReadData) { auto name = "/tmp/sample5.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); size_t count = 50; - std::vector keys; + std::vector keys; std::vector values; - keys.reserve(count); - values.reserve(count); - for (size_t i = 0; i < count; i++) { Sample sample(i + 1); - keys.push_back(sample.archiveName()); - values.push_back(sample.someData()); - ASSERT_TRUE(archive.archive(sample)); + keys.push_back(sample.GetArchiveName()); + values.push_back(sample.GetSomeData()); + ASSERT_TRUE(archive.Write(sample)); } for (size_t i = 0; i < count; i++) { Sample sample; - ASSERT_TRUE(archive.unarchive(keys[i], sample)); - ASSERT_EQ(values[i], sample.someData()); + ASSERT_TRUE(archive.Read(keys[i], sample)); + ASSERT_EQ(values[i], sample.GetSomeData()); } } ASSERT_EQ(::remove(name), 0); @@ -127,11 +127,11 @@ TEST(ArchiveTest, ReadDataWithNames) { auto name = "/tmp/sample6.db"; { Archive archive(name, true); - ASSERT_TRUE(archive.isReady()); + ASSERT_TRUE(archive.IsReady()); size_t count = 8; - std::vector keys; + std::vector keys; std::vector values; keys.reserve(count); @@ -139,16 +139,16 @@ TEST(ArchiveTest, ReadDataWithNames) { for (size_t i = 0; i < count; i++) { Sample sample(i + 1); - keys.push_back(sample.archiveName()); - values.push_back(sample.someData()); - ASSERT_TRUE(archive.archive(sample)); + keys.push_back(sample.GetArchiveName()); + values.push_back(sample.GetSomeData()); + ASSERT_TRUE(archive.Write(sample)); } for (size_t i = 0; i < count; i++) { Sample sample; - ASSERT_TRUE(archive.unarchive(keys[i], sample)); - ASSERT_EQ(values[i], sample.someData()); - ASSERT_EQ(keys[i], sample.archiveName()); + ASSERT_TRUE(archive.Read(keys[i], sample)); + ASSERT_EQ(values[i], sample.GetSomeData()); + ASSERT_EQ(keys[i], sample.GetArchiveName()); } } ASSERT_EQ(::remove(name), 0);