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::transport {
24
34struct RawMessage {
35 uint32_t command : 31;
36 bool is_response : 1;
37 uint32_t payload_size;
38 uint8_t payload[0];
39};
40
47 public:
48 void operator()(RawMessage* ptr);
49};
50
52using ManagedMessage = std::unique_ptr<RawMessage, MessageDestroyer>;
53
58Result<ManagedMessage> CreateMessage(uint32_t command, bool is_response,
59 size_t payload_size);
60Result<ManagedMessage> CreateMessage(uint32_t command, size_t payload_size);
61
62/*
63 * Interface for communication channels that synchronously communicate
64 * HAL IPC/RPC calls.
65 */
66class Channel {
67 public:
68 virtual Result<void> SendRequest(RawMessage& message) = 0;
69 virtual Result<void> SendResponse(RawMessage& message) = 0;
72 virtual ~Channel() {}
73};
74
75} // namespace cuttlefish::transport
Definition: channel.h:66
virtual ~Channel()
Definition: channel.h:72
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:29
Definition: channel.cpp:27
Result< ManagedMessage > CreateMessage(uint32_t command, bool is_response, size_t payload_size)
Definition: channel.cpp:38
std::unique_ptr< RawMessage, MessageDestroyer > ManagedMessage
Definition: channel.h:52
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
Definition: channel.h:34
uint32_t payload_size
Definition: channel.h:37
uint8_t payload[0]
Definition: channel.h:38
uint32_t command
Definition: channel.h:35
bool is_response
Definition: channel.h:36