• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // Frontend command line interface.
18 #pragma once
19 
20 #include <memory>
21 #include <string_view>
22 #include <vector>
23 
24 #include "frontend.grpc.pb.h"
25 #include "rust/cxx.h"
26 
27 namespace netsim {
28 namespace frontend {
29 
30 enum class GrpcMethod : ::std::uint8_t;
31 struct ClientResponseReader;
32 
33 class ClientResult {
34  public:
ClientResult(bool is_ok,const std::string & err,const std::vector<unsigned char> & byte_vec)35   ClientResult(bool is_ok, const std::string &err,
36                const std::vector<unsigned char> &byte_vec)
37       : is_ok_(is_ok), err_(err), byte_vec_(byte_vec){};
38 
IsOk()39   bool IsOk() const { return is_ok_; };
Err()40   rust::String Err() const { return err_; };
ByteVec()41   const std::vector<unsigned char> &ByteVec() const { return byte_vec_; };
42 
43  private:
44   bool is_ok_;
45   std::string err_;
46   const std::vector<unsigned char> byte_vec_;
47 };
48 
49 class FrontendClient {
50  public:
~FrontendClient()51   virtual ~FrontendClient(){};
52   virtual std::unique_ptr<ClientResult> SendGrpc(
53       frontend::GrpcMethod const &grpc_method,
54       rust::Vec<rust::u8> const &request_byte_vec) const = 0;
55   virtual std::unique_ptr<ClientResult> GetVersion() const = 0;
56   virtual std::unique_ptr<ClientResult> GetDevices() const = 0;
57   virtual std::unique_ptr<ClientResult> PatchDevice(
58       rust::Vec<rust::u8> const &request_byte_vec) const = 0;
59   virtual std::unique_ptr<ClientResult> Reset() const = 0;
60   virtual std::unique_ptr<ClientResult> ListCapture() const = 0;
61   virtual std::unique_ptr<ClientResult> PatchCapture(
62       rust::Vec<rust::u8> const &request_byte_vec) const = 0;
63   virtual std::unique_ptr<ClientResult> GetCapture(
64       rust::Vec<::rust::u8> const &request_byte_vec,
65       ClientResponseReader const &client_reader) const = 0;
66 };
67 
68 std::unique_ptr<FrontendClient> NewFrontendClient();
69 
70 }  // namespace frontend
71 }  // namespace netsim
72