1 /* 2 * Copyright 2018 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 <cstdint> 20 #include <set> 21 #include <unordered_map> 22 23 #include "acl_connection.h" 24 #include "include/acl.h" 25 #include "types/address.h" 26 27 namespace test_vendor_lib { 28 29 class AclConnectionHandler { 30 public: max_pending_connections_(max_pending_connections)31 AclConnectionHandler(size_t max_pending_connections = 1) : max_pending_connections_(max_pending_connections) {} 32 33 virtual ~AclConnectionHandler() = default; 34 35 bool CreatePendingConnection(const Address& addr); 36 bool HasPendingConnection(const Address& addr); 37 bool CancelPendingConnection(const Address& addr); 38 39 uint16_t CreateConnection(const Address& addr); 40 bool Disconnect(uint16_t handle); 41 bool HasHandle(uint16_t handle) const; 42 43 uint16_t GetHandle(const Address& addr) const; 44 const Address& GetAddress(uint16_t handle) const; 45 46 void SetConnected(uint16_t handle, bool connected); 47 bool IsConnected(uint16_t handle) const; 48 49 void Encrypt(uint16_t handle); 50 bool IsEncrypted(uint16_t handle) const; 51 52 void SetAddress(uint16_t handle, const Address& address); 53 54 private: 55 std::unordered_map<uint16_t, AclConnection> acl_connections_; 56 size_t max_pending_connections_; 57 std::set<Address> pending_connections_; 58 uint16_t GetUnusedHandle(); 59 }; 60 61 } // namespace test_vendor_lib 62