1e0e9324cSopenharmony_ci/*
2e0e9324cSopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3e0e9324cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0e9324cSopenharmony_ci * you may not use this file except in compliance with the License.
5e0e9324cSopenharmony_ci * You may obtain a copy of the License at
6e0e9324cSopenharmony_ci *
7e0e9324cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0e9324cSopenharmony_ci *
9e0e9324cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0e9324cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0e9324cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0e9324cSopenharmony_ci * See the License for the specific language governing permissions and
13e0e9324cSopenharmony_ci * limitations under the License.
14e0e9324cSopenharmony_ci */
15e0e9324cSopenharmony_ci
16e0e9324cSopenharmony_ci#include "base_producer.h"
17e0e9324cSopenharmony_ci#include "common/common_macro.h"
18e0e9324cSopenharmony_ci
19e0e9324cSopenharmony_cinamespace OHOS {
20e0e9324cSopenharmony_cinamespace Sharing {
21e0e9324cSopenharmony_ci
22e0e9324cSopenharmony_ciBaseProducer::BaseProducer()
23e0e9324cSopenharmony_ci{
24e0e9324cSopenharmony_ci    SHARING_LOGD("producerId: %{public}u.", GetId());
25e0e9324cSopenharmony_ci}
26e0e9324cSopenharmony_ci
27e0e9324cSopenharmony_ciBaseProducer::~BaseProducer()
28e0e9324cSopenharmony_ci{
29e0e9324cSopenharmony_ci    SHARING_LOGD("producerId: %{public}u.", GetId());
30e0e9324cSopenharmony_ci}
31e0e9324cSopenharmony_ci
32e0e9324cSopenharmony_civoid BaseProducer::SetProducerListener(std::weak_ptr<IProducerListener> listener)
33e0e9324cSopenharmony_ci{
34e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
35e0e9324cSopenharmony_ci    listener_ = listener;
36e0e9324cSopenharmony_ci}
37e0e9324cSopenharmony_ci
38e0e9324cSopenharmony_cibool BaseProducer::IsRunning()
39e0e9324cSopenharmony_ci{
40e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
41e0e9324cSopenharmony_ci    return isRunning_;
42e0e9324cSopenharmony_ci}
43e0e9324cSopenharmony_ci
44e0e9324cSopenharmony_civoid BaseProducer::SetSrcAgentId(uint32_t agentId)
45e0e9324cSopenharmony_ci{
46e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
47e0e9324cSopenharmony_ci    srcAgentId_ = agentId;
48e0e9324cSopenharmony_ci}
49e0e9324cSopenharmony_ci
50e0e9324cSopenharmony_ciuint32_t BaseProducer::GetSrcAgentId()
51e0e9324cSopenharmony_ci{
52e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
53e0e9324cSopenharmony_ci    return srcAgentId_;
54e0e9324cSopenharmony_ci}
55e0e9324cSopenharmony_ci
56e0e9324cSopenharmony_civoid BaseProducer::Notify(ProsumerStatusMsg::Ptr &statusMsg)
57e0e9324cSopenharmony_ci{
58e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
59e0e9324cSopenharmony_ci    RETURN_IF_NULL(statusMsg);
60e0e9324cSopenharmony_ci    statusMsg->prosumerId = GetId();
61e0e9324cSopenharmony_ci    statusMsg->agentId = GetSrcAgentId();
62e0e9324cSopenharmony_ci
63e0e9324cSopenharmony_ci    auto listener = listener_.lock();
64e0e9324cSopenharmony_ci    if (listener) {
65e0e9324cSopenharmony_ci        listener->OnProducerNotify(statusMsg);
66e0e9324cSopenharmony_ci    }
67e0e9324cSopenharmony_ci}
68e0e9324cSopenharmony_ci
69e0e9324cSopenharmony_civoid BaseProducer::NotifyPrivateEvent(EventMsg::Ptr eventMsg)
70e0e9324cSopenharmony_ci{
71e0e9324cSopenharmony_ci    SHARING_LOGD("trace.");
72e0e9324cSopenharmony_ci    RETURN_IF_NULL(eventMsg);
73e0e9324cSopenharmony_ci    auto pMsg = std::make_shared<ProsumerStatusMsg>();
74e0e9324cSopenharmony_ci    pMsg->prosumerId = GetId();
75e0e9324cSopenharmony_ci    pMsg->agentId = GetSrcAgentId();
76e0e9324cSopenharmony_ci    pMsg->status = PROSUMER_NOTIFY_PRIVATE_EVENT;
77e0e9324cSopenharmony_ci    pMsg->eventMsg = std::move(eventMsg);
78e0e9324cSopenharmony_ci
79e0e9324cSopenharmony_ci    auto listener = listener_.lock();
80e0e9324cSopenharmony_ci    if (listener) {
81e0e9324cSopenharmony_ci        listener->OnProducerNotify(pMsg);
82e0e9324cSopenharmony_ci    }
83e0e9324cSopenharmony_ci}
84e0e9324cSopenharmony_ci
85e0e9324cSopenharmony_ci} // namespace Sharing
86e0e9324cSopenharmony_ci} // namespace OHOS