• 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 #pragma once
17 
18 #include <cstdint>
19 #include <string>
20 
21 namespace cuttlefish {
22 namespace confui {
23 // When you update this, please update all the utility functions
24 // in conf.cpp: e.g. ToString, etc
25 enum class ConfUiCmd : std::uint32_t {
26   kUnknown = 100,
27   kStart = 111,   // start rendering, send confirmation msg, & wait respond
28   kStop = 112,    // start rendering, send confirmation msg, & wait respond
29   kCliAck = 113,  // client acknowledged. "error:err_msg" or "success:command"
30   kCliRespond = 114,  //  with "confirm" or "cancel"
31   kAbort = 115,       // to abort the current session
32   kSuspend = 116,     // to suspend, so do save the context
33   kRestore = 117,
34   kUserInputEvent = 200
35 };
36 
37 std::string ToString(const ConfUiCmd& cmd);
38 std::string ToDebugString(const ConfUiCmd& cmd, const bool is_debug);
39 ConfUiCmd ToCmd(const std::string& cmd_str);
40 ConfUiCmd ToCmd(std::uint32_t i);
41 
42 struct UserResponse {
43   using type = std::string;
44   constexpr static const auto kConfirm = "user_confirm";
45   constexpr static const auto kCancel = "user_cancel";
46   constexpr static const auto kUnknown = "user_unknown";
47 };
48 
49 // invalid/ignored session id
50 constexpr char SESSION_ANY[] = "";
51 
52 std::string ToCliAckMessage(const bool is_success, const std::string& message);
53 std::string ToCliAckErrorMsg(const std::string& message);
54 std::string ToCliAckSuccessMsg(const std::string& message);
55 
56 struct ConfUiMessage {
57   std::string session_id_;
58   std::string type_;  // cmd, which cmd? ack, response, etc
59   std::string msg_;
60 };
61 
62 }  // end of namespace confui
63 }  // end of namespace cuttlefish
64