James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | #ifndef BOOT_EVENT_RECORD_STORE_H_ |
| 18 | #define BOOT_EVENT_RECORD_STORE_H_ |
| 19 | |
Mark Salyzyn | 14b1e6d | 2017-09-18 10:41:14 -0700 | [diff] [blame] | 20 | #include <android-base/macros.h> |
| 21 | #include <gtest/gtest_prod.h> |
James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 22 | #include <cstdint> |
| 23 | #include <string> |
| 24 | #include <utility> |
| 25 | #include <vector> |
James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 26 | |
| 27 | // BootEventRecordStore manages the persistence of boot events to the record |
| 28 | // store and the retrieval of all boot event records from the store. |
| 29 | class BootEventRecordStore { |
| 30 | public: |
| 31 | // A BootEventRecord consists of the event name and the timestamp the event |
| 32 | // occurred. |
| 33 | typedef std::pair<std::string, int32_t> BootEventRecord; |
| 34 | |
| 35 | BootEventRecordStore(); |
| 36 | |
James Hawkins | 500d715 | 2016-02-16 15:05:54 -0800 | [diff] [blame] | 37 | // Persists the boot |event| in the record store. |
| 38 | void AddBootEvent(const std::string& event); |
James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 39 | |
James Hawkins | 500d715 | 2016-02-16 15:05:54 -0800 | [diff] [blame] | 40 | // Persists the boot |event| with the associated |value| in the record store. |
| 41 | void AddBootEventWithValue(const std::string& event, int32_t value); |
| 42 | |
| 43 | // Queries the named boot |event|. |record| must be non-null. |record| |
| 44 | // contains the boot event data on success. Returns true iff the query is |
| 45 | // successful. |
| 46 | bool GetBootEvent(const std::string& event, BootEventRecord* record) const; |
James Hawkins | a4a1a4a | 2016-02-09 15:32:38 -0800 | [diff] [blame] | 47 | |
James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 48 | // Returns a list of all of the boot events persisted in the record store. |
| 49 | std::vector<BootEventRecord> GetAllBootEvents() const; |
| 50 | |
| 51 | private: |
| 52 | // The tests call SetStorePath to override the default store location with a |
| 53 | // more test-friendly path. |
| 54 | FRIEND_TEST(BootEventRecordStoreTest, AddSingleBootEvent); |
| 55 | FRIEND_TEST(BootEventRecordStoreTest, AddMultipleBootEvents); |
James Hawkins | a4a1a4a | 2016-02-09 15:32:38 -0800 | [diff] [blame] | 56 | FRIEND_TEST(BootEventRecordStoreTest, AddBootEventWithValue); |
James Hawkins | 500d715 | 2016-02-16 15:05:54 -0800 | [diff] [blame] | 57 | FRIEND_TEST(BootEventRecordStoreTest, GetBootEvent); |
James Hawkins | c0dc139 | 2016-03-25 12:49:23 -0700 | [diff] [blame] | 58 | FRIEND_TEST(BootEventRecordStoreTest, GetBootEventNoFileContent); |
James Hawkins | abd73e6 | 2016-01-19 15:10:38 -0800 | [diff] [blame] | 59 | |
| 60 | // Sets the filesystem path of the record store. |
| 61 | void SetStorePath(const std::string& path); |
| 62 | |
| 63 | // Constructs the full path of the given boot |event|. |
| 64 | std::string GetBootEventPath(const std::string& event) const; |
| 65 | |
| 66 | // The filesystem path of the record store. |
| 67 | std::string store_path_; |
| 68 | |
| 69 | DISALLOW_COPY_AND_ASSIGN(BootEventRecordStore); |
| 70 | }; |
| 71 | |
| 72 | #endif // BOOT_EVENT_RECORD_STORE_H_ |