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 { ToFsmInput(const ConfUiMessage & msg)20FsmInput ToFsmInput(const ConfUiMessage& msg) { 21 const auto cmd = msg.GetType(); 22 switch (cmd) { 23 case ConfUiCmd::kUserInputEvent: 24 return FsmInput::kUserEvent; 25 case ConfUiCmd::kUnknown: 26 return FsmInput::kHalUnknown; 27 case ConfUiCmd::kStart: 28 return FsmInput::kHalStart; 29 case ConfUiCmd::kStop: 30 return FsmInput::kHalStop; 31 case ConfUiCmd::kAbort: 32 return FsmInput::kHalAbort; 33 case ConfUiCmd::kCliAck: 34 case ConfUiCmd::kCliRespond: 35 default: 36 ConfUiLog(FATAL) << "The" << ToString(cmd) 37 << "is not handled by the Session FSM but " 38 << "directly calls Abort()"; 39 } 40 return FsmInput::kHalUnknown; 41 } 42 ToString(FsmInput input)43std::string ToString(FsmInput input) { 44 switch (input) { 45 case FsmInput::kUserEvent: 46 return {"kUserEvent"}; 47 case FsmInput::kHalStart: 48 return {"kHalStart"}; 49 case FsmInput::kHalStop: 50 return {"kHalStop"}; 51 case FsmInput::kHalAbort: 52 return {"kHalAbort"}; 53 case FsmInput::kHalUnknown: 54 default: 55 break; 56 } 57 return {"kHalUnknown"}; 58 } 59 ToString(const MainLoopState & state)60std::string ToString(const MainLoopState& state) { 61 switch (state) { 62 case MainLoopState::kInit: 63 return "kInit"; 64 case MainLoopState::kInSession: 65 return "kInSession"; 66 case MainLoopState::kWaitStop: 67 return "kWaitStop"; 68 case MainLoopState::kAwaitCleanup: 69 return "kAwaitCleanup"; 70 case MainLoopState::kTerminated: 71 return "kTerminated"; 72 default: 73 return "kInvalid"; 74 } 75 } 76 77 } // end of namespace confui 78 } // end of namespace cuttlefish 79