1 /* 2 * Copyright 2017 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 #include <list> 18 #include <unordered_map> 19 #include <unordered_set> 20 #include <vector> 21 22 #include "bta_gatt_api.h" 23 24 class BtaGattServerQueue { 25 public: 26 static void Clean(uint16_t conn_id); 27 static void SendNotification(uint16_t conn_id, uint16_t handle, 28 std::vector<uint8_t> value, bool need_confirm); 29 static void NotificationCallback(uint16_t conn_id); 30 static void CongestionCallback(uint16_t conn_id, bool congested); 31 32 /* Holds pending GATT operations */ 33 struct gatts_operation { 34 uint8_t type; 35 uint16_t attr_id; 36 std::vector<uint8_t> value; 37 bool need_confirm; 38 }; 39 40 private: 41 static bool is_congested; 42 static void mark_as_not_executing(uint16_t conn_id); 43 static void gatts_execute_next_op(uint16_t conn_id); 44 45 // maps connection id to operations waiting for execution 46 static std::unordered_map<uint16_t, std::list<gatts_operation>> 47 gatts_op_queue; 48 49 // maps connection id to congestion status of each device 50 static std::unordered_map<uint16_t, bool> congestion_queue; 51 52 // contain connection ids that currently execute operations 53 static std::unordered_set<uint16_t> gatts_op_queue_executing; 54 };