blob: f872c85c8b3a3869f409647064acf7d5866070c6 [file] [log] [blame]
James Hawkinsabd73e62016-01-19 15:10:38 -08001/*
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 Salyzyn14b1e6d2017-09-18 10:41:14 -070020#include <android-base/macros.h>
21#include <gtest/gtest_prod.h>
James Hawkinsabd73e62016-01-19 15:10:38 -080022#include <cstdint>
23#include <string>
24#include <utility>
25#include <vector>
James Hawkinsabd73e62016-01-19 15:10:38 -080026
27// BootEventRecordStore manages the persistence of boot events to the record
28// store and the retrieval of all boot event records from the store.
29class 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 Hawkins500d7152016-02-16 15:05:54 -080037 // Persists the boot |event| in the record store.
38 void AddBootEvent(const std::string& event);
James Hawkinsabd73e62016-01-19 15:10:38 -080039
James Hawkins500d7152016-02-16 15:05:54 -080040 // 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 Hawkinsa4a1a4a2016-02-09 15:32:38 -080047
James Hawkinsabd73e62016-01-19 15:10:38 -080048 // 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 Hawkinsa4a1a4a2016-02-09 15:32:38 -080056 FRIEND_TEST(BootEventRecordStoreTest, AddBootEventWithValue);
James Hawkins500d7152016-02-16 15:05:54 -080057 FRIEND_TEST(BootEventRecordStoreTest, GetBootEvent);
James Hawkinsc0dc1392016-03-25 12:49:23 -070058 FRIEND_TEST(BootEventRecordStoreTest, GetBootEventNoFileContent);
James Hawkinsabd73e62016-01-19 15:10:38 -080059
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_