Android-cuttlefish cvd tool
channel_monitor.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 <thread>
19#include <vector>
20
24
26
27namespace cuttlefish {
28
33};
34
36 public:
39
42
43 ClientId SetRemoteClient(SharedFD client, bool is_accepted);
44 void SendRemoteCommand(ClientId client, std::string& response);
46
47 // For modem services to send unsolicited commands
48 void SendUnsolicitedCommand(std::string& response);
49
50 private:
52 std::thread monitor_thread_;
56 std::vector<std::unique_ptr<Client>> clients_;
57 std::vector<std::unique_ptr<Client>> remote_clients_;
58
60 void OnClientSocketClosed(int sock);
61 void ReadCommand(Client& client);
62
63 void MonitorLoop();
64 static void removeInvalidClients(
65 std::vector<std::unique_ptr<Client>>& clients);
66};
67
68} // namespace cuttlefish
Definition: service_test.cpp:38
Definition: channel_monitor.h:35
ChannelMonitor(const ChannelMonitor &)=delete
void ReadCommand(Client &client)
Definition: channel_monitor.cpp:83
~ChannelMonitor()
Definition: channel_monitor.cpp:183
void CloseRemoteConnection(ClientId client)
Definition: channel_monitor.cpp:162
void OnClientSocketClosed(int sock)
void SendRemoteCommand(ClientId client, std::string &response)
Definition: channel_monitor.cpp:151
ClientId SetRemoteClient(SharedFD client, bool is_accepted)
Definition: channel_monitor.cpp:42
void MonitorLoop()
Definition: channel_monitor.cpp:207
void SendUnsolicitedCommand(std::string &response)
Definition: channel_monitor.cpp:141
cuttlefish::SharedFD read_pipe_
Definition: channel_monitor.h:54
std::vector< std::unique_ptr< Client > > clients_
Definition: channel_monitor.h:56
void AcceptIncomingConnection()
Definition: channel_monitor.cpp:68
cuttlefish::SharedFD write_pipe_
Definition: channel_monitor.h:55
std::vector< std::unique_ptr< Client > > remote_clients_
Definition: channel_monitor.h:57
VirtualModemSimulator & modem_
Definition: channel_monitor.h:51
std::thread monitor_thread_
Definition: channel_monitor.h:52
cuttlefish::SharedFD server_
Definition: channel_monitor.h:53
ChannelMonitor & operator=(const ChannelMonitor &)=delete
static void removeInvalidClients(std::vector< std::unique_ptr< Client > > &clients)
Definition: channel_monitor.cpp:194
ChannelMonitor(VirtualModemSimulator &modem, cuttlefish::SharedFD server)
Definition: channel_monitor.cpp:31
Definition: client.h:30
Definition: client.h:47
Definition: shared_fd.h:129
Definition: virtual_modem_simulator.h:22
Definition: alloc_utils.cpp:23
ModemSimulatorExitCodes
Definition: channel_monitor.h:29
@ kSelectError
Definition: channel_monitor.h:31
@ kServerError
Definition: channel_monitor.h:32
@ kSuccess
Definition: channel_monitor.h:30