1 /*
2 * Copyright (C) 2023 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_common_event_helper.h"
17 #include "common_event.h"
18 #include "common_event_data.h"
19 #include "common_event_manager.h"
20 #include "common_event_subscriber.h"
21 #include "log.h"
22
23 using namespace OHOS::EventFwk;
24
25 namespace OHOS {
26 namespace BluetoothHelper {
PublishEvent(const std::string & eventAction,int code,const std::vector<std::string> & permissions)27 bool BluetoothCommonEventHelper::PublishEvent(const std::string &eventAction,int code,
28 const std::vector<std::string> &permissions)
29 {
30 Want want;
31 want.SetAction(eventAction);
32 CommonEventData commonData;
33 commonData.SetWant(want);
34 commonData.SetCode(code);
35 if (permissions.size() > 0) {
36 CommonEventPublishInfo publishInfo;
37 publishInfo.SetSubscriberPermissions(permissions);
38 if (!CommonEventManager::PublishCommonEvent(commonData, publishInfo)) {
39 HILOGE("failed to send common event with permission!");
40 return false;
41 }
42 HILOGI("send common event with permission!");
43 return true;
44 }
45 if (!CommonEventManager::PublishCommonEvent(commonData)) {
46 HILOGE("failed to send common event!");
47 return false;
48 }
49 return true;
50 }
51
PublishBluetoothStateChangeEvent(int code,const std::vector<std::string> & permissions)52 bool BluetoothCommonEventHelper::PublishBluetoothStateChangeEvent(int code,
53 const std::vector<std::string> &permissions)
54 {
55 return BluetoothCommonEventHelper::PublishEvent(COMMON_EVENT_BLUETOOTH_HOST_STATE_UPDATE , code, permissions);
56 }
57 }
58 }
59
60
61