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#ifndef OHOS_SHARING_AGENT_H 17e0e9324cSopenharmony_ci#define OHOS_SHARING_AGENT_H 18e0e9324cSopenharmony_ci 19e0e9324cSopenharmony_ci#include <map> 20e0e9324cSopenharmony_ci#include "agent/session/base_session.h" 21e0e9324cSopenharmony_ci#include "agent_def.h" 22e0e9324cSopenharmony_ci#include "common/event_comm.h" 23e0e9324cSopenharmony_ci 24e0e9324cSopenharmony_cinamespace OHOS { 25e0e9324cSopenharmony_cinamespace Sharing { 26e0e9324cSopenharmony_ci 27e0e9324cSopenharmony_ciclass IAgentListener { 28e0e9324cSopenharmony_cipublic: 29e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<IAgentListener>; 30e0e9324cSopenharmony_ci 31e0e9324cSopenharmony_ci virtual ~IAgentListener() = default; 32e0e9324cSopenharmony_ci 33e0e9324cSopenharmony_ci virtual void OnAgentNotify(AgentStatusMsg::Ptr &statusMsg) = 0; 34e0e9324cSopenharmony_ci}; 35e0e9324cSopenharmony_ci 36e0e9324cSopenharmony_ciclass Agent : public IdentifierInfo, 37e0e9324cSopenharmony_ci public ISessionListener, 38e0e9324cSopenharmony_ci public HandleEventBase, 39e0e9324cSopenharmony_ci public std::enable_shared_from_this<Agent> { 40e0e9324cSopenharmony_cipublic: 41e0e9324cSopenharmony_ci using Ptr = std::shared_ptr<Agent>; 42e0e9324cSopenharmony_ci 43e0e9324cSopenharmony_ci explicit Agent(AgentType agentType); 44e0e9324cSopenharmony_ci 45e0e9324cSopenharmony_ci void SetDestroy() 46e0e9324cSopenharmony_ci { 47e0e9324cSopenharmony_ci destroy_ = true; 48e0e9324cSopenharmony_ci } 49e0e9324cSopenharmony_ci 50e0e9324cSopenharmony_ci bool GetDestroy() 51e0e9324cSopenharmony_ci { 52e0e9324cSopenharmony_ci return destroy_; 53e0e9324cSopenharmony_ci } 54e0e9324cSopenharmony_ci 55e0e9324cSopenharmony_ci void UpdateMediaChannelId(uint32_t mediaChannelId) 56e0e9324cSopenharmony_ci { 57e0e9324cSopenharmony_ci mediaChannelId_ = mediaChannelId; 58e0e9324cSopenharmony_ci } 59e0e9324cSopenharmony_ci 60e0e9324cSopenharmony_ci void SetAgentListener(std::weak_ptr<IAgentListener> agentListener) 61e0e9324cSopenharmony_ci { 62e0e9324cSopenharmony_ci agentListener_ = agentListener; 63e0e9324cSopenharmony_ci } 64e0e9324cSopenharmony_ci 65e0e9324cSopenharmony_ci uint32_t GetMediaChannelId() 66e0e9324cSopenharmony_ci { 67e0e9324cSopenharmony_ci return mediaChannelId_; 68e0e9324cSopenharmony_ci } 69e0e9324cSopenharmony_ci 70e0e9324cSopenharmony_ci AgentType GetAgentType() 71e0e9324cSopenharmony_ci { 72e0e9324cSopenharmony_ci return agentType_; 73e0e9324cSopenharmony_ci } 74e0e9324cSopenharmony_ci 75e0e9324cSopenharmony_cipublic: 76e0e9324cSopenharmony_ci int32_t HandleEvent(SharingEvent &event) override; 77e0e9324cSopenharmony_ci SharingErrorCode CreateSession(const std::string &className); 78e0e9324cSopenharmony_ci 79e0e9324cSopenharmony_ciprotected: 80e0e9324cSopenharmony_ci void PushNextStep(SessionStatusMsg::Ptr &statusMsg); 81e0e9324cSopenharmony_ci void HandleSessionError(SessionStatusMsg::Ptr &statusMsg); 82e0e9324cSopenharmony_ci void UpdateSessionStatus(SessionStatusMsg::Ptr &statusMsg); 83e0e9324cSopenharmony_ci void PopNextStep(AgentRunStep step, AgentRunningStatus status); 84e0e9324cSopenharmony_ci void OnSessionNotify(SessionStatusMsg::Ptr &statusMsg) override; 85e0e9324cSopenharmony_ci void SetRunningStatus(AgentRunStep step, AgentRunningStatus status); 86e0e9324cSopenharmony_ci 87e0e9324cSopenharmony_ci AgentRunStep GetRunStep(EventType eventType); 88e0e9324cSopenharmony_ci AgentRunStepWeight GetRunStepWeight(AgentRunStep runStep); 89e0e9324cSopenharmony_ci SharingErrorCode CheckRunStep(SharingEvent &event, bool &isCached); 90e0e9324cSopenharmony_ci 91e0e9324cSopenharmony_ciprivate: 92e0e9324cSopenharmony_ci uint32_t NotifyPrivateEvent(SessionStatusMsg::Ptr &statusMsg); 93e0e9324cSopenharmony_ci 94e0e9324cSopenharmony_ci void HandleProsumerState(SessionStatusMsg::Ptr &statusMsg); 95e0e9324cSopenharmony_ci void HandleProsumerError(SessionStatusMsg::Ptr &statusMsg); 96e0e9324cSopenharmony_ci 97e0e9324cSopenharmony_ci void SendContextEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 98e0e9324cSopenharmony_ci void SendChannelEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 99e0e9324cSopenharmony_ci void SendInteractionEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 100e0e9324cSopenharmony_ci void SendChannelSetVolumeEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 101e0e9324cSopenharmony_ci void SendChannelSceneTypeEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 102e0e9324cSopenharmony_ci void SendChannelKeyRedirectEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 103e0e9324cSopenharmony_ci void SendChannelAppendSurfaceEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 104e0e9324cSopenharmony_ci void SendChannelRemoveSurfaceEvent(SessionStatusMsg::Ptr &statusMsg, EventType eventType); 105e0e9324cSopenharmony_ci 106e0e9324cSopenharmony_ciprotected: 107e0e9324cSopenharmony_ci bool destroy_ = false; 108e0e9324cSopenharmony_ci uint32_t prosumerId_ = INVALID_ID; 109e0e9324cSopenharmony_ci uint32_t mediaChannelId_ = INVALID_ID; 110e0e9324cSopenharmony_ci 111e0e9324cSopenharmony_ci std::mutex runStepMutex_; 112e0e9324cSopenharmony_ci std::weak_ptr<IAgentListener> agentListener_; 113e0e9324cSopenharmony_ci std::map<AgentRunStepKey, SharingEvent> runEvents_; 114e0e9324cSopenharmony_ci 115e0e9324cSopenharmony_ci AgentType agentType_ = SRC_AGENT; 116e0e9324cSopenharmony_ci BaseSession::Ptr session_ = nullptr; 117e0e9324cSopenharmony_ci AgentRunStep runStep_ = AGENT_STEP_IDLE; 118e0e9324cSopenharmony_ci AgentRunningStatus runningStatus_ = AGENT_STATUS_IDLE; 119e0e9324cSopenharmony_ci}; 120e0e9324cSopenharmony_ci 121e0e9324cSopenharmony_ci} // namespace Sharing 122e0e9324cSopenharmony_ci} // namespace OHOS 123e0e9324cSopenharmony_ci#endif