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 "daudio_sink_ipc_callback.h"
17
18 #include "daudio_constants.h"
19 #include "daudio_errorcode.h"
20 #include "daudio_log.h"
21 #include "daudio_util.h"
22
23 #undef DH_LOG_TAG
24 #define DH_LOG_TAG "DAudioSinkIpcCallback"
25
26 namespace OHOS {
27 namespace DistributedHardware {
OnNotifyResourceInfo(const ResourceEventType & type,const std::string & subType,const std::string & networkId,bool & isSensitive,bool & isSameAccount)28 int32_t DAudioSinkIpcCallback::OnNotifyResourceInfo(const ResourceEventType &type, const std::string &subType,
29 const std::string &networkId, bool &isSensitive, bool &isSameAccount)
30 {
31 DHLOGI("On notify the resource info, subType: %{public}s, networkId: %{public}s, isSensitive: "
32 "%{public}d, isSameAccount: %{public}d", subType.c_str(), GetAnonyString(networkId).c_str(),
33 isSensitive, isSameAccount);
34
35 int32_t ret = DH_SUCCESS;
36 std::lock_guard<std::mutex> resourceLck(privacyResMtx_);
37 auto iter = privacyResCallback_.begin();
38 if (iter != privacyResCallback_.end()) {
39 ret = (*iter)->OnPrivaceResourceMessage(type, subType, networkId, isSensitive, isSameAccount);
40 }
41 return ret;
42 }
43
PushPrivacyResCallback(const std::shared_ptr<PrivacyResourcesListener> & callback)44 void DAudioSinkIpcCallback::PushPrivacyResCallback(const std::shared_ptr<PrivacyResourcesListener> &callback)
45 {
46 DHLOGD("Push resource info callback");
47 std::lock_guard<std::mutex> resourceLck(privacyResMtx_);
48 privacyResCallback_.push_back(callback);
49 }
50 } // DistributedHardware
51 } // OHOS