xref: /aosp_15_r20/tools/netsim/src/netsim-packet-streamer-client.cc (revision cf78ab8cffb8fc9207af348f23af247fb04370a6)
1 // Copyright 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <iostream>
16 
17 #include "backend/packet_streamer_client.h"
18 #include "netsim/packet_streamer.grpc.pb.h"
19 
20 using netsim::common::ChipKind;
21 
main(int argc,char * argv[])22 int main(int argc, char *argv[]) {
23   // Finding the netsimd binary requires this env variable when run
24   // interactively export ANDROID_EMULATOR_LAUNCHER_DIR=./objs
25 
26   auto channel = netsim::packet::CreateChannel("");
27 
28   std::unique_ptr<netsim::packet::PacketStreamer::Stub> stub =
29       netsim::packet::PacketStreamer::NewStub(channel);
30 
31   grpc::ClientContext context;
32 
33   netsim::packet::PacketRequest initial_request;
34   netsim::packet::Stream bt_stream = stub->StreamPackets(&context);
35   initial_request.mutable_initial_info()->set_name("emulator-5554");
36   initial_request.mutable_initial_info()->mutable_chip()->set_kind(
37       ChipKind::BLUETOOTH);
38   bt_stream->Write(initial_request);
39 
40   std::cout << "Press enter to close the connection...";
41   std::string s;
42   getline(std::cin, s);
43 
44   return (0);
45 }
46