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