Android-cuttlefish cvd tool
channel.h
Go to the documentation of this file.
1/*
2 * Copyright 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 <memory>
20
22
23namespace cuttlefish {
24namespace transport {
25
35struct RawMessage {
36 uint32_t command : 31;
37 bool is_response : 1;
38 uint32_t payload_size;
39 uint8_t payload[0];
40};
41
48 public:
49 void operator()(RawMessage* ptr);
50};
51
53using ManagedMessage = std::unique_ptr<RawMessage, MessageDestroyer>;
54
59Result<ManagedMessage> CreateMessage(uint32_t command, bool is_response,
60 size_t payload_size);
61Result<ManagedMessage> CreateMessage(uint32_t command, size_t payload_size);
62
63/*
64 * Interface for communication channels that synchronously communicate
65 * HAL IPC/RPC calls.
66 */
67class Channel {
68 public:
69 virtual Result<void> SendRequest(RawMessage& message) = 0;
70 virtual Result<void> SendResponse(RawMessage& message) = 0;
73 virtual ~Channel() {}
74};
75
76} // namespace transport
77} // namespace cuttlefish
Definition: expected.h:86
Definition: channel.h:67
virtual ~Channel()
Definition: channel.h:73
virtual Result< void > SendRequest(RawMessage &message)=0
virtual Result< int > WaitForMessage()=0
virtual Result< void > SendResponse(RawMessage &message)=0
virtual Result< ManagedMessage > ReceiveMessage()=0
void operator()(RawMessage *ptr)
Definition: channel.cpp:22
Result< ManagedMessage > CreateMessage(uint32_t command, bool is_response, size_t payload_size)
Definition: channel.cpp:31
std::unique_ptr< RawMessage, MessageDestroyer > ManagedMessage
Definition: channel.h:53
Definition: alloc_utils.cpp:23
Definition: channel.h:35
uint32_t payload_size
Definition: channel.h:38
uint8_t payload[0]
Definition: channel.h:39
uint32_t command
Definition: channel.h:36
bool is_response
Definition: channel.h:37