Home | History | Annotate | Download | only in bootstat
      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 
     20 #include <android-base/macros.h>
     21 #include <gtest/gtest_prod.h>
     22 #include <cstdint>
     23 #include <string>
     24 #include <utility>
     25 #include <vector>
     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 
     37   // Persists the boot |event| in the record store.
     38   void AddBootEvent(const std::string& event);
     39 
     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;
     47 
     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);
     56   FRIEND_TEST(BootEventRecordStoreTest, AddBootEventWithValue);
     57   FRIEND_TEST(BootEventRecordStoreTest, GetBootEvent);
     58   FRIEND_TEST(BootEventRecordStoreTest, GetBootEventNoFileContent);
     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_