• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "host/libs/confui/server_common.h"
18 namespace cuttlefish {
19 namespace confui {
UserEvtToFsmInput(UserResponse::type user_response)20 static FsmInput UserEvtToFsmInput(UserResponse::type user_response) {
21   if (user_response == UserResponse::kConfirm) {
22     return FsmInput::kUserUnknown;
23   }
24   if (user_response == UserResponse::kCancel) {
25     return FsmInput::kUserCancel;
26   }
27   return FsmInput::kUserUnknown;
28 }
29 
ToFsmInput(const ConfUiMessage & confui_msg)30 FsmInput ToFsmInput(const ConfUiMessage& confui_msg) {
31   ConfUiCmd cmd = ToCmd(confui_msg.type_);
32   if (cmd == ConfUiCmd::kUserInputEvent) {
33     return UserEvtToFsmInput(confui_msg.msg_);
34   }
35   const auto hal_cmd = cmd;
36   switch (hal_cmd) {
37     case ConfUiCmd::kUnknown:
38       return FsmInput::kHalUnknown;
39     case ConfUiCmd::kStart:
40       return FsmInput::kHalStart;
41     case ConfUiCmd::kStop:
42       return FsmInput::kHalStop;
43     case ConfUiCmd::kSuspend:
44       return FsmInput::kHalSuspend;
45     case ConfUiCmd::kRestore:
46       return FsmInput::kHalRestore;
47     case ConfUiCmd::kAbort:
48       return FsmInput::kHalAbort;
49     case ConfUiCmd::kCliAck:
50     case ConfUiCmd::kCliRespond:
51     default:
52       ConfUiLog(FATAL) << "The" << ToString(hal_cmd)
53                        << "is not handled by Session";
54   }
55   return FsmInput::kHalUnknown;
56 }
57 
ToString(FsmInput input)58 std::string ToString(FsmInput input) {
59   switch (input) {
60     case FsmInput::kUserConfirm:
61       return {"kUserConfirm"};
62     case FsmInput::kUserCancel:
63       return {"kUserCancel"};
64     case FsmInput::kUserUnknown:
65       return {"kUserUnknown"};
66     case FsmInput::kHalStart:
67       return {"kHalStart"};
68     case FsmInput::kHalStop:
69       return {"kHalStop"};
70     case FsmInput::kHalSuspend:
71       return {"kHalSuspend"};
72     case FsmInput::kHalRestore:
73       return {"kHalRestore"};
74     case FsmInput::kHalAbort:
75       return {"kHalAbort"};
76     case FsmInput::kHalUnknown:
77     default:
78       break;
79   }
80   return {"kHalUnknown"};
81 }
82 
ToString(const MainLoopState & state)83 std::string ToString(const MainLoopState& state) {
84   switch (state) {
85     case MainLoopState::kInit:
86       return "kInit";
87     case MainLoopState::kInSession:
88       return "kInSession";
89     case MainLoopState::kWaitStop:
90       return "kWaitStop";
91     case MainLoopState::kSuspended:
92       return "kSuspended";
93     case MainLoopState::kAwaitCleanup:
94       return "kAwaitCleanup";
95     default:
96       return "kInvalid";
97   }
98 }
99 
100 }  // end of namespace confui
101 }  // end of namespace cuttlefish
102