1 /*
2  * Copyright (C) 2023 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 <cstdint>
20 
21 #include "common/libs/fs/shared_fd.h"
22 #include "common/libs/utils/result.h"
23 
24 namespace cuttlefish {
25 namespace process_monitor_impl {
26 
27 enum class ParentToChildMessageType : std::uint8_t {
28   kStop = 1,
29   kHostResume = 2,
30   kHostSuspend = 3,
31   kError = 4,
32 };
33 
34 enum class ChildToParentResponseType : std::uint8_t {
35   kSuccess = 0,
36   kFailure = 1,
37 };
38 
39 class ParentToChildMessage {
40  public:
41   ParentToChildMessage(const ParentToChildMessageType type);
42   Result<void> Write(const SharedFD& fd);
43   static Result<ParentToChildMessage> Read(const SharedFD& fd);
Stop()44   bool Stop() const { return type_ == ParentToChildMessageType::kStop; }
Type()45   auto Type() const { return type_; }
46 
47  private:
48   ParentToChildMessageType type_;
49 };
50 
51 class ChildToParentResponse {
52  public:
53   ChildToParentResponse(const ChildToParentResponseType type);
54   Result<void> Write(const SharedFD& fd);
55   static Result<ChildToParentResponse> Read(const SharedFD& fd);
Success()56   bool Success() const { return type_ == ChildToParentResponseType::kSuccess; }
57 
58  private:
59   ChildToParentResponseType type_;
60 };
61 
62 }  // namespace process_monitor_impl
63 }  // namespace cuttlefish
64