Android-cuttlefish cvd tool
host_mode_ctrl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 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#pragma once
18
19#include <stdint.h>
20
21#include <atomic>
22#include <condition_variable>
23#include <functional>
24#include <mutex>
25
26#include "fruit/fruit.h"
27
30
31namespace cuttlefish {
40 public:
41 enum class ModeType : uint8_t { kAndroidMode = 55, kConfUI_Mode = 77 };
65 << "checking atomic Android mode";
68 << "returns as it is already Android mode";
69 return;
70 }
71 auto check = [this]() -> bool {
73 };
74 std::unique_lock<std::mutex> lock(mode_mtx_);
75 and_mode_cv_.wait(lock, check);
77 << "awakes from cond var waiting for Android mode";
78 }
79
80 void SetMode(const ModeType mode) {
82 << " tries to acquire the lock in SetMode";
83 std::lock_guard<std::mutex> lock(mode_mtx_);
85 << " acquired the lock in SetMode";
86 atomic_mode_ = mode;
89 << " signals kAndroidMode in SetMode";
90 and_mode_cv_.notify_all();
91 return;
92 }
94 << "signals kConfUI_Mode in SetMode";
95 confui_mode_cv_.notify_all();
96 }
97
98 auto GetMode() {
99 ModeType ret_val = atomic_mode_;
100 return ret_val;
101 }
102
105 }
106
108
109 static HostModeCtrl& Get() {
110 static HostModeCtrl host_mode_controller;
111 return host_mode_controller;
112 }
113
114 private:
115 std::mutex mode_mtx_;
116 std::condition_variable and_mode_cv_;
117 std::condition_variable confui_mode_cv_;
118 std::atomic<ModeType> atomic_mode_;
119};
120} // end of namespace cuttlefish
Definition: host_mode_ctrl.h:39
auto GetMode()
Definition: host_mode_ctrl.h:98
void WaitAndroidMode()
Definition: host_mode_ctrl.h:63
auto IsAndroidMode()
Definition: host_mode_ctrl.h:107
static HostModeCtrl & Get()
Definition: host_mode_ctrl.h:109
std::condition_variable confui_mode_cv_
Definition: host_mode_ctrl.h:117
void SetMode(const ModeType mode)
Definition: host_mode_ctrl.h:80
auto IsConfirmatioUiMode()
Definition: host_mode_ctrl.h:103
std::condition_variable and_mode_cv_
Definition: host_mode_ctrl.h:116
std::atomic< ModeType > atomic_mode_
Definition: host_mode_ctrl.h:118
std::mutex mode_mtx_
Definition: host_mode_ctrl.h:115
INJECT(HostModeCtrl())
Definition: host_mode_ctrl.h:42
ModeType
Definition: host_mode_ctrl.h:41
#define ConfUiLogDebug
Definition: utils.h:61
#define check(p)
Definition: fec_private.h:203
std::string GetName(const std::thread::id tid)
Definition: host_utils.cc:63
Definition: alloc_driver.h:20