Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 ANDROID_APEXD_APEXD_SESSION_H_ |
| 18 | #define ANDROID_APEXD_APEXD_SESSION_H_ |
| 19 | |
Andreas Gampe | f35e179 | 2019-04-01 15:58:03 -0700 | [diff] [blame] | 20 | #include "apex_constants.h" |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 21 | #include "status_or.h" |
| 22 | |
| 23 | #include "session_state.pb.h" |
| 24 | |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 25 | #include <optional> |
| 26 | |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 27 | namespace android { |
| 28 | namespace apex { |
| 29 | |
Martijn Coenen | c11b68b | 2019-01-15 11:28:11 +0100 | [diff] [blame] | 30 | static const std::string kApexSessionsDir = |
Nikita Ioffe | a8453da | 2019-01-30 21:29:13 +0000 | [diff] [blame] | 31 | std::string(kApexDataDir) + "/sessions"; |
Martijn Coenen | c11b68b | 2019-01-15 11:28:11 +0100 | [diff] [blame] | 32 | |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 33 | class ApexSession { |
| 34 | public: |
| 35 | static StatusOr<ApexSession> CreateSession(int session_id); |
| 36 | static StatusOr<ApexSession> GetSession(int session_id); |
| 37 | static std::vector<ApexSession> GetSessions(); |
| 38 | static std::vector<ApexSession> GetSessionsInState( |
| 39 | ::apex::proto::SessionState::State state); |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 40 | static StatusOr<std::optional<ApexSession>> GetActiveSession(); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 41 | ApexSession() = delete; |
| 42 | |
Dario Freni | 6dd4dd6 | 2019-01-18 12:45:44 +0000 | [diff] [blame] | 43 | const google::protobuf::RepeatedField<int> GetChildSessionIds() const; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 44 | ::apex::proto::SessionState::State GetState() const; |
| 45 | int GetId() const; |
Gavin Corkery | a41373a | 2019-09-26 12:53:45 +0100 | [diff] [blame] | 46 | std::string GetBuildFingerprint() const; |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 47 | bool IsFinalized() const; |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 48 | |
Dario Freni | 6dd4dd6 | 2019-01-18 12:45:44 +0000 | [diff] [blame] | 49 | void SetChildSessionIds(const std::vector<int>& child_session_ids); |
Gavin Corkery | a41373a | 2019-09-26 12:53:45 +0100 | [diff] [blame] | 50 | void SetBuildFingerprint(const std::string& fingerprint); |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 51 | Status UpdateStateAndCommit(const ::apex::proto::SessionState::State& state); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 52 | |
Nikita Ioffe | 463d4e8 | 2019-02-10 18:46:20 +0000 | [diff] [blame] | 53 | Status DeleteSession() const; |
Nikita Ioffe | 53c3dcd | 2019-02-08 17:39:00 +0000 | [diff] [blame] | 54 | |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 55 | private: |
Martijn Coenen | d32d1cb | 2019-02-13 12:43:57 +0100 | [diff] [blame] | 56 | ApexSession(const ::apex::proto::SessionState& state); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 57 | ::apex::proto::SessionState state_; |
Martijn Coenen | d32d1cb | 2019-02-13 12:43:57 +0100 | [diff] [blame] | 58 | |
| 59 | static StatusOr<ApexSession> GetSessionFromFile(const std::string& path); |
Martijn Coenen | 610909b | 2019-01-18 13:49:38 +0100 | [diff] [blame] | 60 | }; |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 61 | |
Nikita Ioffe | a0c0ccb | 2019-02-12 22:00:41 +0000 | [diff] [blame] | 62 | std::ostream& operator<<(std::ostream& out, const ApexSession& session); |
| 63 | |
Martijn Coenen | cabc92f | 2019-01-11 10:50:35 +0100 | [diff] [blame] | 64 | } // namespace apex |
| 65 | } // namespace android |
| 66 | |
| 67 | #endif // ANDROID_APEXD_APEXD_SESSION_H |