1 /*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "storage/mutation.h"
18
19 namespace bluetooth {
20 namespace storage {
21
Mutation(ConfigCache * config,ConfigCache * memory_only_config)22 Mutation::Mutation(ConfigCache* config, ConfigCache* memory_only_config)
23 : config_(config), memory_only_config_(memory_only_config) {
24 log::assert_that(config_ != nullptr, "assert failed: config_ != nullptr");
25 log::assert_that(memory_only_config_ != nullptr, "assert failed: memory_only_config_ != nullptr");
26 }
27
Add(MutationEntry entry)28 void Mutation::Add(MutationEntry entry) {
29 switch (entry.property_type) {
30 case MutationEntry::PropertyType::NORMAL:
31 if (entry.entry_type != MutationEntry::EntryType::SET) {
32 // When an item is removed from normal config, it must be removed from temp config as well
33 memory_only_config_entries_.emplace(entry);
34 }
35 normal_config_entries_.emplace(std::move(entry));
36 break;
37 case MutationEntry::PropertyType::MEMORY_ONLY:
38 memory_only_config_entries_.emplace(std::move(entry));
39 break;
40 // do not write a default case so that when a new enum is defined, compilation would fail
41 // automatically
42 }
43 }
44
Commit()45 void Mutation::Commit() {
46 config_->Commit(normal_config_entries_);
47 memory_only_config_->Commit(memory_only_config_entries_);
48 }
49
50 } // namespace storage
51 } // namespace bluetooth
52