• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #pragma once
18 
19 #include <stddef.h>
20 #include <stdint.h>
21 
22 #include <functional>
23 #include <memory>
24 #include <string_view>
25 #include <vector>
26 
27 #include "adb/pairing/pairing_connection.h"
28 
29 typedef void (*pairing_client_result_cb)(const PeerInfo*, void*);
30 
31 namespace adb {
32 namespace pairing {
33 
34 // PairingClient is the client side of the PairingConnection protocol. It will
35 // attempt to connect to a PairingServer specified at |host| and |port|, and
36 // allocate a new PairingConnection for processing.
37 //
38 // See pairing_connection_test.cpp for example usage.
39 //
40 class PairingClient {
41   public:
42     using Data = std::vector<uint8_t>;
43 
44     virtual ~PairingClient() = default;
45 
46     // Starts the pairing client. This call is non-blocking. Upon completion,
47     // if the pairing was successful, then |cb| will be called with the PeerInfo
48     // containing the info of the trusted peer. Otherwise, |cb| will be
49     // called with an empty value. Start can only be called once in the lifetime
50     // of this object. |ip_addr| requires a port to be specified.
51     //
52     // Returns true if PairingClient was successfully started. Otherwise,
53     // returns false.
54     virtual bool Start(std::string_view ip_addr, pairing_client_result_cb cb, void* opaque) = 0;
55 
56     // Creates a new PairingClient instance. May return null if unable
57     // to create an instance. |pswd|, |certificate|, |priv_key| and
58     // |ip_addr| cannot be empty. |peer_info| must contain non-empty strings for
59     // the guid and name fields.
60     static std::unique_ptr<PairingClient> Create(const Data& pswd, const PeerInfo& peer_info,
61                                                  const Data& certificate, const Data& priv_key);
62 
63   protected:
64     PairingClient() = default;
65 };  // class PairingClient
66 
67 }  // namespace pairing
68 }  // namespace adb
69