• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bluetooth_ble_impl.h"
17 
18 namespace OHOS {
19 namespace CJSystemapi {
20 namespace CJBluetoothBle {
21 using Bluetooth::AdvertisingState;
22 
FfiBluetoothBleAdvertiseCallback()23 FfiBluetoothBleAdvertiseCallback::FfiBluetoothBleAdvertiseCallback()
24 {
25 }
26 
GetInstance(void)27 std::shared_ptr<FfiBluetoothBleAdvertiseCallback> FfiBluetoothBleAdvertiseCallback::GetInstance(void)
28 {
29     static std::shared_ptr<FfiBluetoothBleAdvertiseCallback> instance =
30         std::make_shared<FfiBluetoothBleAdvertiseCallback>();
31     return instance;
32 }
33 
RegisterAdvertisingStateChangeFunc(std::function<void (CAdvertisingStateChangeInfo)> cjCallback)34 void FfiBluetoothBleAdvertiseCallback::RegisterAdvertisingStateChangeFunc(
35     std::function<void(CAdvertisingStateChangeInfo)> cjCallback)
36 {
37     advertisingStateChangeFunc = cjCallback;
38 }
39 
OnStartResultEvent(int result,int advHandle)40 void FfiBluetoothBleAdvertiseCallback::OnStartResultEvent(int result, int advHandle)
41 {
42     CAdvertisingStateChangeInfo info{0};
43     info.advertisingId = advHandle;
44     info.state = static_cast<int>(AdvertisingState::STARTED);
45     if (advertisingStateChangeFunc != nullptr) {
46         advertisingStateChangeFunc(info);
47     }
48     return;
49 }
50 
OnEnableResultEvent(int result,int advHandle)51 void FfiBluetoothBleAdvertiseCallback::OnEnableResultEvent(int result, int advHandle)
52 {
53     CAdvertisingStateChangeInfo info{0};
54     info.advertisingId = advHandle;
55     info.state = static_cast<int>(AdvertisingState::ENABLED);
56     if (advertisingStateChangeFunc != nullptr) {
57         advertisingStateChangeFunc(info);
58     }
59     return;
60 }
61 
OnDisableResultEvent(int result,int advHandle)62 void FfiBluetoothBleAdvertiseCallback::OnDisableResultEvent(int result, int advHandle)
63 {
64     CAdvertisingStateChangeInfo info{0};
65     info.advertisingId = advHandle;
66     info.state = static_cast<int>(AdvertisingState::DISABLED);
67     if (advertisingStateChangeFunc != nullptr) {
68         advertisingStateChangeFunc(info);
69     }
70     return;
71 }
72 
OnStopResultEvent(int result,int advHandle)73 void FfiBluetoothBleAdvertiseCallback::OnStopResultEvent(int result, int advHandle)
74 {
75     CAdvertisingStateChangeInfo info{0};
76     info.advertisingId = advHandle;
77     info.state = static_cast<int>(AdvertisingState::STOPPED);
78     if (advertisingStateChangeFunc != nullptr) {
79         advertisingStateChangeFunc(info);
80     }
81     return;
82 }
83 
OnGetAdvHandleEvent(int result,int advHandle)84 void FfiBluetoothBleAdvertiseCallback::OnGetAdvHandleEvent(int result, int advHandle)
85 {
86     handleEvent = advHandle;
87     return;
88 }
89 
OnChangeAdvResultEvent(int result,int advHandle)90 void FfiBluetoothBleAdvertiseCallback::OnChangeAdvResultEvent(int result, int advHandle)
91 {}
92 
GetAdvHandleEvent()93 int32_t FfiBluetoothBleAdvertiseCallback::GetAdvHandleEvent()
94 {
95     return handleEvent;
96 }
97 
98 } // namespace CJBluetoothBle
99 } // namespace CJSystemapi
100 } // namespace OHOS