1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci#ifndef OHOS_HDI_BLUETOOTH_HCI_V1_0_VENDOR_INTERFACE_H
17094332d3Sopenharmony_ci#define OHOS_HDI_BLUETOOTH_HCI_V1_0_VENDOR_INTERFACE_H
18094332d3Sopenharmony_ci
19094332d3Sopenharmony_ci#include <functional>
20094332d3Sopenharmony_ci#include <vector>
21094332d3Sopenharmony_ci
22094332d3Sopenharmony_ci#include "singleton.h"
23094332d3Sopenharmony_ci
24094332d3Sopenharmony_ci#include "hci_internal.h"
25094332d3Sopenharmony_ci#include "hci_protocol.h"
26094332d3Sopenharmony_ci#include "hci_watcher.h"
27094332d3Sopenharmony_ci#include "ohos_bt_vendor_lib.h"
28094332d3Sopenharmony_ci
29094332d3Sopenharmony_cinamespace OHOS {
30094332d3Sopenharmony_cinamespace HDI {
31094332d3Sopenharmony_cinamespace Bluetooth {
32094332d3Sopenharmony_cinamespace Hci {
33094332d3Sopenharmony_cinamespace V1_0 {
34094332d3Sopenharmony_ciclass VendorInterface : public DelayedSingleton<VendorInterface> {
35094332d3Sopenharmony_cipublic:
36094332d3Sopenharmony_ci    using InitializeCompleteCallback = std::function<void(bool isSuccess)>;
37094332d3Sopenharmony_ci    using ReceiveDataCallback = Hci::HciProtocol::HciDataCallback;
38094332d3Sopenharmony_ci    struct ReceiveCallback {
39094332d3Sopenharmony_ci        ReceiveDataCallback onAclReceive;
40094332d3Sopenharmony_ci        ReceiveDataCallback onScoReceive;
41094332d3Sopenharmony_ci        ReceiveDataCallback onEventReceive;
42094332d3Sopenharmony_ci    };
43094332d3Sopenharmony_ci
44094332d3Sopenharmony_ci    bool Initialize(InitializeCompleteCallback initializeCompleteCallback, const ReceiveCallback &receiveCallback);
45094332d3Sopenharmony_ci    void CleanUp();
46094332d3Sopenharmony_ci    size_t SendPacket(Hci::HciPacketType type, const std::vector<uint8_t> &packet);
47094332d3Sopenharmony_ci
48094332d3Sopenharmony_ciprivate:
49094332d3Sopenharmony_ci    static void OnInitCallback(BtOpResultT result);
50094332d3Sopenharmony_ci    static void* OnMallocCallback(int size);
51094332d3Sopenharmony_ci    static void OnFreeCallback(void* buf);
52094332d3Sopenharmony_ci    static size_t OnCmdXmitCallback(uint16_t opcode, void* buf);
53094332d3Sopenharmony_ci
54094332d3Sopenharmony_ci    void OnEventReceived(const std::vector<uint8_t> &data);
55094332d3Sopenharmony_ci    bool WatchHciChannel(const ReceiveCallback &receiveCallback);
56094332d3Sopenharmony_ci    void WatcherTimeout();
57094332d3Sopenharmony_ci
58094332d3Sopenharmony_ciprivate:
59094332d3Sopenharmony_ci    InitializeCompleteCallback initializeCompleteCallback_;
60094332d3Sopenharmony_ci    ReceiveDataCallback eventDataCallback_;
61094332d3Sopenharmony_ci    void* vendorHandle_ = nullptr;
62094332d3Sopenharmony_ci    BtVendorInterfaceT *vendorInterface_ = nullptr;
63094332d3Sopenharmony_ci    static BtVendorCallbacksT vendorCallbacks_;
64094332d3Sopenharmony_ci    HciWatcher watcher_;
65094332d3Sopenharmony_ci    std::shared_ptr<Hci::HciProtocol> hci_ = nullptr;
66094332d3Sopenharmony_ci    uint16_t vendorSentOpcode_ = 0;
67094332d3Sopenharmony_ci    uint32_t lpmTimer_ = 0;
68094332d3Sopenharmony_ci    std::mutex wakeupMutex_;
69094332d3Sopenharmony_ci    bool wakeupLock_ = false;
70094332d3Sopenharmony_ci    bool activity_ = false;
71094332d3Sopenharmony_ci    std::mutex initAndCleanupProcessMutex_;
72094332d3Sopenharmony_ci
73094332d3Sopenharmony_ci    DECLARE_DELAYED_SINGLETON(VendorInterface);
74094332d3Sopenharmony_ci    DISALLOW_COPY_AND_MOVE(VendorInterface);
75094332d3Sopenharmony_ci};
76094332d3Sopenharmony_ci}  // namespace V1_0
77094332d3Sopenharmony_ci}  // namespace Hci
78094332d3Sopenharmony_ci}  // namespace Bluetooth
79094332d3Sopenharmony_ci}  // namespace HDI
80094332d3Sopenharmony_ci}  // namespace OHOS
81094332d3Sopenharmony_ci#endif /* OHOS_HDI_BLUETOOTH_HCI_V1_0_VENDOR_INTERFACE_H */