Android-cuttlefish cvd tool
client.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 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 <compare>
19#include <mutex>
20#include <vector>
21
23
25
26namespace cuttlefish {
27
28class ChannelMonitor;
29class ModemSimulator;
30
31class ClientId {
32 public:
33 ClientId();
34
35 auto operator<=>(const ClientId&) const = default;
36
37 private:
38 static size_t next_id_;
39 size_t id_;
40};
41
48class Client {
49 public:
51
52 Client() = default;
53 ~Client() = default;
54 Client(SharedFD fd);
56 Client(SharedFD fd, ClientType client_type);
58 Client(const Client& client) = delete;
59 Client(Client&& client) = delete;
60
61 Client& operator=(Client&& other) = delete;
62
63 bool operator==(const Client& other) const;
64
65 void SendCommandResponse(std::string response) const;
66 void SendCommandResponse(const std::vector<std::string>& responses) const;
67
68 ClientId Id() const { return id_; }
69 ClientType Type() const { return type; }
70
71 private:
72 friend class ChannelMonitor;
73 friend class ::ModemServiceTest;
74
79 std::string incomplete_command;
80 mutable std::mutex write_mutex;
81 bool first_read_command_; // Only used when ClientType::REMOTE
82 bool is_valid = true;
83};
84
85} // namespace cuttlefish
Definition: service_test.cpp:39
Definition: channel_monitor.h:35
Definition: client.h:31
ClientId()
Definition: client.cc:27
auto operator<=>(const ClientId &) const =default
static size_t next_id_
Definition: client.h:38
size_t id_
Definition: client.h:39
Definition: client.h:48
ClientId Id() const
Definition: client.h:68
bool operator==(const Client &other) const
Definition: client.cc:45
ClientType
Definition: client.h:50
@ REMOTE
Definition: client.h:50
@ RIL
Definition: client.h:50
ClientType type
Definition: client.h:76
void SendCommandResponse(std::string response) const
Definition: client.cc:50
bool is_valid
Definition: client.h:82
bool first_read_command_
Definition: client.h:81
std::string incomplete_command
Definition: client.h:79
Client & operator=(Client &&other)=delete
SharedFD client_write_fd_
Definition: client.h:78
ClientType Type() const
Definition: client.h:69
ClientId id_
Definition: client.h:75
std::mutex write_mutex
Definition: client.h:80
Client(const Client &client)=delete
Client(Client &&client)=delete
SharedFD client_read_fd_
Definition: client.h:77
Definition: shared_fd.h:124
Definition: alloc_driver.h:20
Result< std::optional< MonitorCommand > > ModemSimulator(const CuttlefishConfig::InstanceSpecific &instance)
Definition: modem.cpp:66
#define read
Definition: sysdeps.h:543
#define write
Definition: sysdeps.h:560