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