1 /* 2 * Copyright 2022 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 "grpcpp/channel.h" 20 #include "netsim/packet_streamer.pb.h" 21 22 namespace netsim::packet { 23 /* 24 25 // Example: 26 27 auto channel = CreateChannel({.no_cli_ui = false, 28 .no_web_ui = true, 29 .netsim_args = "--dev --hci-port 12345"}); 30 std::unique_ptr<PacketStreamer::Stub> stub = PacketStreamer::NewStub(channel); 31 32 ::grpc::ClientContext context; 33 // set deadline, add metadata to context 34 35 PacketsRequest initial_request; 36 Stream bt_stream = stub.StreamPackets(&context); 37 initial_request.mutable_initial_info().set_name("Pixel_XL_3"); 38 initial_request.mutable_initial_info().mutable_chip().set_kind(ChipKind::BLUETOOTH); 39 bt_stream.write(initial_request); 40 41 Stream wifi_stream = stub.StreamPackets(&context); 42 initial_request.mutable_initial_info().set_name("Pixel_XL_3"); 43 initial_request.mutable_initial_info().mutable_chip().set_kind(ChipKind::WIFI); 44 wifi_stream.write(initial_request); 45 */ 46 using Stream = std::unique_ptr< 47 ::grpc::ClientReaderWriter<packet::PacketRequest, packet::PacketResponse>>; 48 49 struct NetsimdOptions { 50 bool no_cli_ui; 51 bool no_web_ui; 52 std::string host_dns = ""; 53 std::string netsim_args; 54 }; 55 56 // Configure the endpoint for a server other than the local netsimd server. 57 void SetPacketStreamEndpoint(const std::string &endpoint); 58 59 std::shared_ptr<grpc::Channel> CreateChannel(NetsimdOptions); 60 61 // Deprecated. 62 std::shared_ptr<grpc::Channel> CreateChannel( 63 std::string rootcanal_controller_properties_file = ""); 64 65 } // namespace netsim::packet 66