1 /*
2  * Copyright (C) 2021 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 #ifndef __BT_VENDOR_H__
18 #define __BT_VENDOR_H__
19 
20 #include "bt_vendor_lib.h"
21 
22 class BtVendor {
23  public:
getInstance()24   static BtVendor* getInstance() {
25     if (!mInstance) {
26       mInstance = new BtVendor;
27     }
28     return mInstance;
29   }
30 
setVendorCback(bt_vendor_callbacks_t * cb,bt_vendor_opcode_t opcode)31   void setVendorCback(bt_vendor_callbacks_t* cb, bt_vendor_opcode_t opcode) {
32     mCbacks = cb;
33     mOpcode = opcode;
34   }
35 
queryFdList()36   int32_t* queryFdList() { return fdList; }
queryFdCount()37   size_t queryFdCount() { return fdCount; }
38   void callRemainingCbacks();
39   void populateFdList(int32_t list[], size_t count);
40 
41  private:
42   BtVendor() = default;
43 
~BtVendor()44   ~BtVendor() {
45     if (mInstance) {
46       delete mInstance;
47       mInstance = nullptr;
48     }
49     mCbacks = nullptr;
50   }
51 
52   static BtVendor* mInstance;
53   bt_vendor_callbacks_t* mCbacks = nullptr;
54   bt_vendor_opcode_t mOpcode;
55   int32_t fdCount;
56   int32_t fdList[CH_MAX] = {0};
57 };
58 
59 BtVendor* BtVendor::mInstance = nullptr;
60 #endif  // __BT_VENDOR_H__
61