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 "interaction.h" 17e0e9324cSopenharmony_ci#include "common/common_macro.h" 18e0e9324cSopenharmony_ci#include "common/event_comm.h" 19e0e9324cSopenharmony_ci#include "common/reflect_registration.h" 20e0e9324cSopenharmony_ci#include "common/sharing_log.h" 21e0e9324cSopenharmony_ci#include "interaction/interaction_manager.h" 22e0e9324cSopenharmony_ci#include "magic_enum.hpp" 23e0e9324cSopenharmony_ci#include "scene/base_scene.h" 24e0e9324cSopenharmony_ci 25e0e9324cSopenharmony_cinamespace OHOS { 26e0e9324cSopenharmony_cinamespace Sharing { 27e0e9324cSopenharmony_ci 28e0e9324cSopenharmony_ciInteraction::~Interaction() 29e0e9324cSopenharmony_ci{ 30e0e9324cSopenharmony_ci SHARING_LOGD("id: %{public}d.", GetId()); 31e0e9324cSopenharmony_ci} 32e0e9324cSopenharmony_ci 33e0e9324cSopenharmony_cibool Interaction::CreateScene(const std::string &className) 34e0e9324cSopenharmony_ci{ 35e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 36e0e9324cSopenharmony_ci scene_ = ClassReflector<BaseScene>::Class2Instance(className); 37e0e9324cSopenharmony_ci if (scene_ == nullptr) { 38e0e9324cSopenharmony_ci SHARING_LOGE("create scene error."); 39e0e9324cSopenharmony_ci return false; 40e0e9324cSopenharmony_ci } 41e0e9324cSopenharmony_ci 42e0e9324cSopenharmony_ci scene_->SetInteractionId(GetId()); 43e0e9324cSopenharmony_ci scene_->Initialize(); 44e0e9324cSopenharmony_ci scene_->SetSharingAdapter(shared_from_this()); 45e0e9324cSopenharmony_ci 46e0e9324cSopenharmony_ci return true; 47e0e9324cSopenharmony_ci} 48e0e9324cSopenharmony_ci 49e0e9324cSopenharmony_civoid Interaction::OnDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) 50e0e9324cSopenharmony_ci{ 51e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 52e0e9324cSopenharmony_ci if (scene_) { 53e0e9324cSopenharmony_ci scene_->OnDomainMsg(msg); 54e0e9324cSopenharmony_ci } 55e0e9324cSopenharmony_ci} 56e0e9324cSopenharmony_ci 57e0e9324cSopenharmony_civoid Interaction::ForwardDomainMsg(std::shared_ptr<BaseDomainMsg> &msg) 58e0e9324cSopenharmony_ci{ 59e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 60e0e9324cSopenharmony_ci InteractionManager::GetInstance().SendDomainMsg(msg); 61e0e9324cSopenharmony_ci} 62e0e9324cSopenharmony_ci 63e0e9324cSopenharmony_civoid Interaction::ReleaseScene(uint32_t sceneId) 64e0e9324cSopenharmony_ci{ 65e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 66e0e9324cSopenharmony_ci auto interactionMsg = std::make_shared<InteractionEventMsg>(); 67e0e9324cSopenharmony_ci interactionMsg->toMgr = ModuleType::MODULE_INTERACTION; 68e0e9324cSopenharmony_ci interactionMsg->type = EVENT_INTERACTIONMGR_DESTROY_INTERACTION; 69e0e9324cSopenharmony_ci 70e0e9324cSopenharmony_ci SharingEvent event; 71e0e9324cSopenharmony_ci event.eventMsg = std::move(interactionMsg); 72e0e9324cSopenharmony_ci event.eventMsg->fromMgr = ModuleType::MODULE_INTERACTION; 73e0e9324cSopenharmony_ci event.eventMsg->dstId = GetId(); 74e0e9324cSopenharmony_ci SendEvent(event); 75e0e9324cSopenharmony_ci} 76e0e9324cSopenharmony_ci 77e0e9324cSopenharmony_civoid Interaction::OnSceneNotifyDestroyed(uint32_t sceneId) 78e0e9324cSopenharmony_ci{ 79e0e9324cSopenharmony_ci SHARING_LOGE("scene destroyed will remove interactionId: %{public}u.", GetId()); 80e0e9324cSopenharmony_ci auto interactionMsg = std::make_shared<InteractionEventMsg>(); 81e0e9324cSopenharmony_ci interactionMsg->toMgr = ModuleType::MODULE_INTERACTION; 82e0e9324cSopenharmony_ci interactionMsg->type = EVENT_INTERACTIONMGR_REMOVE_INTERACTION; 83e0e9324cSopenharmony_ci 84e0e9324cSopenharmony_ci SharingEvent event; 85e0e9324cSopenharmony_ci event.eventMsg = std::move(interactionMsg); 86e0e9324cSopenharmony_ci event.eventMsg->fromMgr = ModuleType::MODULE_INTERACTION; 87e0e9324cSopenharmony_ci event.eventMsg->dstId = GetId(); 88e0e9324cSopenharmony_ci SendEvent(event); 89e0e9324cSopenharmony_ci} 90e0e9324cSopenharmony_ci 91e0e9324cSopenharmony_civoid Interaction::Destroy() 92e0e9324cSopenharmony_ci{ 93e0e9324cSopenharmony_ci SHARING_LOGE("trace."); 94e0e9324cSopenharmony_ci if (scene_) { 95e0e9324cSopenharmony_ci scene_.reset(); 96e0e9324cSopenharmony_ci } 97e0e9324cSopenharmony_ci} 98e0e9324cSopenharmony_ci 99e0e9324cSopenharmony_ciint32_t Interaction::HandleEvent(SharingEvent &event) 100e0e9324cSopenharmony_ci{ 101e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 102e0e9324cSopenharmony_ci RETURN_INVALID_IF_NULL(event.eventMsg); 103e0e9324cSopenharmony_ci SHARING_LOGI("fromMgr: %{public}u, srcId: %{public}u, toMgr: %{public}u, dstId: %{public}u, event: %{public}s.", 104e0e9324cSopenharmony_ci event.eventMsg->fromMgr, event.eventMsg->srcId, event.eventMsg->toMgr, event.eventMsg->dstId, 105e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 106e0e9324cSopenharmony_ci auto interactionMsg = ConvertEventMsg<InteractionEventMsg>(event); 107e0e9324cSopenharmony_ci auto contextId = interactionMsg->contextId ? interactionMsg->contextId : interactionMsg->srcId; 108e0e9324cSopenharmony_ci auto agentId = interactionMsg->agentId; 109e0e9324cSopenharmony_ci auto agentType = interactionMsg->agentType; 110e0e9324cSopenharmony_ci auto errorCode = interactionMsg->errorCode; 111e0e9324cSopenharmony_ci 112e0e9324cSopenharmony_ci switch (event.eventMsg->type) { 113e0e9324cSopenharmony_ci case EVENT_INTERACTION_MSG_ERROR: { 114e0e9324cSopenharmony_ci SHARING_LOGI("interaction handle error, errorCode: %{public}d.", errorCode); 115e0e9324cSopenharmony_ci if (scene_) { 116e0e9324cSopenharmony_ci scene_->OnInnerError(contextId, agentId, errorCode); 117e0e9324cSopenharmony_ci if (errorCode == ERR_NETWORK_ERROR || errorCode == ERR_CONNECTION_FAILURE || 118e0e9324cSopenharmony_ci errorCode == ERR_INTERACTION_FAILURE || errorCode == ERR_PROTOCOL_INTERACTION_TIMEOUT || 119e0e9324cSopenharmony_ci errorCode == ERR_INTAKE_TIMEOUT) { 120e0e9324cSopenharmony_ci SHARING_LOGE("on inner destroy network error."); 121e0e9324cSopenharmony_ci scene_->OnInnerDestroy(contextId, agentId, agentType); 122e0e9324cSopenharmony_ci DestroyAgent(contextId, agentId); 123e0e9324cSopenharmony_ci } 124e0e9324cSopenharmony_ci } 125e0e9324cSopenharmony_ci break; 126e0e9324cSopenharmony_ci } 127e0e9324cSopenharmony_ci case EVENT_INTERACTION_STATE_AGENT_DESTROYED: 128e0e9324cSopenharmony_ci case EVENT_INTERACTION_STATE_CONTEXT_DESTROYED: { 129e0e9324cSopenharmony_ci SHARING_LOGI("interaction handle event, destroy result."); 130e0e9324cSopenharmony_ci if (scene_) { 131e0e9324cSopenharmony_ci scene_->OnInnerDestroy(contextId, agentId, agentType); 132e0e9324cSopenharmony_ci } 133e0e9324cSopenharmony_ci break; 134e0e9324cSopenharmony_ci } 135e0e9324cSopenharmony_ci default: 136e0e9324cSopenharmony_ci SHARING_LOGI("interaction forward event to scene."); 137e0e9324cSopenharmony_ci if (scene_) { 138e0e9324cSopenharmony_ci scene_->OnInnerEvent(event); 139e0e9324cSopenharmony_ci } 140e0e9324cSopenharmony_ci break; 141e0e9324cSopenharmony_ci } 142e0e9324cSopenharmony_ci 143e0e9324cSopenharmony_ci return 0; 144e0e9324cSopenharmony_ci} 145e0e9324cSopenharmony_ci 146e0e9324cSopenharmony_ciint32_t Interaction::NotifyEvent(EventMsg::Ptr eventMsg) 147e0e9324cSopenharmony_ci{ 148e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 149e0e9324cSopenharmony_ci RETURN_INVALID_IF_NULL(eventMsg); 150e0e9324cSopenharmony_ci SharingEvent event; 151e0e9324cSopenharmony_ci event.eventMsg = std::move(eventMsg); 152e0e9324cSopenharmony_ci event.eventMsg->fromMgr = ModuleType::MODULE_INTERACTION; 153e0e9324cSopenharmony_ci event.eventMsg->srcId = GetId(); 154e0e9324cSopenharmony_ci return SendEvent(event); 155e0e9324cSopenharmony_ci} 156e0e9324cSopenharmony_ci 157e0e9324cSopenharmony_ciint32_t Interaction::CreateContext(uint32_t &contextId) 158e0e9324cSopenharmony_ci{ 159e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 160e0e9324cSopenharmony_ci auto contextMsg = std::make_shared<ContextEventMsg>(); 161e0e9324cSopenharmony_ci contextMsg->type = EventType::EVENT_CONTEXTMGR_CREATE; 162e0e9324cSopenharmony_ci contextMsg->toMgr = ModuleType::MODULE_CONTEXT; 163e0e9324cSopenharmony_ci 164e0e9324cSopenharmony_ci SharingEvent event; 165e0e9324cSopenharmony_ci event.eventMsg = contextMsg; 166e0e9324cSopenharmony_ci event.eventMsg->fromMgr = ModuleType::MODULE_INTERACTION; 167e0e9324cSopenharmony_ci event.eventMsg->srcId = GetId(); 168e0e9324cSopenharmony_ci int32_t ret = SendSyncEvent(event); 169e0e9324cSopenharmony_ci if (ret != -1) { 170e0e9324cSopenharmony_ci contextId = contextMsg->dstId; 171e0e9324cSopenharmony_ci SHARING_LOGI("create context success contextId: %{public}u.", contextId); 172e0e9324cSopenharmony_ci } else { 173e0e9324cSopenharmony_ci SHARING_LOGE("create context failed."); 174e0e9324cSopenharmony_ci } 175e0e9324cSopenharmony_ci 176e0e9324cSopenharmony_ci return 0; 177e0e9324cSopenharmony_ci} 178e0e9324cSopenharmony_ci 179e0e9324cSopenharmony_ciint32_t Interaction::DestroyContext(uint32_t contextId) 180e0e9324cSopenharmony_ci{ 181e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u.", contextId); 182e0e9324cSopenharmony_ci auto contextMsg = std::make_shared<ContextEventMsg>(); 183e0e9324cSopenharmony_ci contextMsg->type = EventType::EVENT_CONTEXTMGR_DESTROY; 184e0e9324cSopenharmony_ci contextMsg->toMgr = ModuleType::MODULE_CONTEXT; 185e0e9324cSopenharmony_ci contextMsg->dstId = contextId; 186e0e9324cSopenharmony_ci 187e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(contextMsg); 188e0e9324cSopenharmony_ci if (ret != -1) { 189e0e9324cSopenharmony_ci SHARING_LOGI("destroy context success contextId: %{public}u.", contextId); 190e0e9324cSopenharmony_ci } else { 191e0e9324cSopenharmony_ci SHARING_LOGE("destroy context failed."); 192e0e9324cSopenharmony_ci } 193e0e9324cSopenharmony_ci 194e0e9324cSopenharmony_ci return ret; 195e0e9324cSopenharmony_ci} 196e0e9324cSopenharmony_ci 197e0e9324cSopenharmony_ciint32_t Interaction::CreateAgent(uint32_t &contextId, uint32_t &agentId, AgentType agentType, std::string sessionName) 198e0e9324cSopenharmony_ci{ 199e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 200e0e9324cSopenharmony_ci auto contextMsg = std::make_shared<ContextEventMsg>(); 201e0e9324cSopenharmony_ci contextMsg->type = EventType::EVENT_CONTEXTMGR_AGENT_CREATE; 202e0e9324cSopenharmony_ci contextMsg->toMgr = ModuleType::MODULE_CONTEXT; 203e0e9324cSopenharmony_ci contextMsg->dstId = contextId; 204e0e9324cSopenharmony_ci contextMsg->agentType = agentType; 205e0e9324cSopenharmony_ci contextMsg->className = std::move(sessionName); 206e0e9324cSopenharmony_ci contextMsg->agentId = agentId; 207e0e9324cSopenharmony_ci 208e0e9324cSopenharmony_ci SharingEvent event; 209e0e9324cSopenharmony_ci event.eventMsg = contextMsg; 210e0e9324cSopenharmony_ci event.eventMsg->fromMgr = ModuleType::MODULE_INTERACTION; 211e0e9324cSopenharmony_ci event.eventMsg->srcId = GetId(); 212e0e9324cSopenharmony_ci int32_t ret = SendSyncEvent(event); 213e0e9324cSopenharmony_ci 214e0e9324cSopenharmony_ci SHARING_LOGI("notify create agent ret: %{public}d agentId: %{public}u.", ret, contextMsg->agentId); 215e0e9324cSopenharmony_ci if (ret != -1) { 216e0e9324cSopenharmony_ci if ((agentId == contextMsg->agentId) || contextMsg->agentId == INVALID_ID) { 217e0e9324cSopenharmony_ci agentId = INVALID_ID; 218e0e9324cSopenharmony_ci } else { 219e0e9324cSopenharmony_ci agentId = contextMsg->agentId; 220e0e9324cSopenharmony_ci } 221e0e9324cSopenharmony_ci contextId = contextMsg->dstId; 222e0e9324cSopenharmony_ci SHARING_LOGI("notify create agent success agentId: %{public}u.", agentId); 223e0e9324cSopenharmony_ci } else { 224e0e9324cSopenharmony_ci SHARING_LOGE("notify create agent failed!"); 225e0e9324cSopenharmony_ci } 226e0e9324cSopenharmony_ci 227e0e9324cSopenharmony_ci return ret; 228e0e9324cSopenharmony_ci} 229e0e9324cSopenharmony_ci 230e0e9324cSopenharmony_ciint32_t Interaction::DestroyAgent(uint32_t contextId, uint32_t agentId) 231e0e9324cSopenharmony_ci{ 232e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 233e0e9324cSopenharmony_ci auto contextMsg = std::make_shared<AgentEventMsg>(); 234e0e9324cSopenharmony_ci contextMsg->type = EventType::EVENT_CONTEXT_AGENT_DESTROY; 235e0e9324cSopenharmony_ci contextMsg->toMgr = ModuleType::MODULE_CONTEXT; 236e0e9324cSopenharmony_ci contextMsg->dstId = contextId; 237e0e9324cSopenharmony_ci contextMsg->agentId = agentId; 238e0e9324cSopenharmony_ci 239e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(contextMsg); 240e0e9324cSopenharmony_ci if (ret != -1) { 241e0e9324cSopenharmony_ci SHARING_LOGI("destroy agent success agentId: %{public}u.", agentId); 242e0e9324cSopenharmony_ci } else { 243e0e9324cSopenharmony_ci SHARING_LOGE("destroy agent failed, agentId: %{public}u.", agentId); 244e0e9324cSopenharmony_ci } 245e0e9324cSopenharmony_ci 246e0e9324cSopenharmony_ci return ret; 247e0e9324cSopenharmony_ci} 248e0e9324cSopenharmony_ci 249e0e9324cSopenharmony_ciint32_t Interaction::Stop(uint32_t contextId, uint32_t agentId) 250e0e9324cSopenharmony_ci{ 251e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 252e0e9324cSopenharmony_ci return 0; 253e0e9324cSopenharmony_ci} 254e0e9324cSopenharmony_ci 255e0e9324cSopenharmony_ciint32_t Interaction::Start(uint32_t contextId, uint32_t agentId) 256e0e9324cSopenharmony_ci{ 257e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 258e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 259e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_START; 260e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 261e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 262e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 263e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 264e0e9324cSopenharmony_ci if (ret != -1) { 265e0e9324cSopenharmony_ci SHARING_LOGI("start agent success agentId: %{public}u.", agentId); 266e0e9324cSopenharmony_ci } else { 267e0e9324cSopenharmony_ci SHARING_LOGE("start agent failed, agentId: %{public}u.", agentId); 268e0e9324cSopenharmony_ci } 269e0e9324cSopenharmony_ci 270e0e9324cSopenharmony_ci return ret; 271e0e9324cSopenharmony_ci} 272e0e9324cSopenharmony_ci 273e0e9324cSopenharmony_ciint32_t Interaction::Pause(uint32_t contextId, uint32_t agentId, MediaType mediaType) 274e0e9324cSopenharmony_ci{ 275e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 276e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 277e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_PAUSE; 278e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 279e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 280e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 281e0e9324cSopenharmony_ci agentMsg->mediaType = mediaType; 282e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 283e0e9324cSopenharmony_ci if (ret != -1) { 284e0e9324cSopenharmony_ci SHARING_LOGI("pause agent success agentId: %{public}u.", agentId); 285e0e9324cSopenharmony_ci } else { 286e0e9324cSopenharmony_ci SHARING_LOGE("pause agent failed, agentId: %{public}u.", agentId); 287e0e9324cSopenharmony_ci } 288e0e9324cSopenharmony_ci 289e0e9324cSopenharmony_ci return ret; 290e0e9324cSopenharmony_ci} 291e0e9324cSopenharmony_ci 292e0e9324cSopenharmony_ciint32_t Interaction::Resume(uint32_t contextId, uint32_t agentId, MediaType mediaType) 293e0e9324cSopenharmony_ci{ 294e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 295e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 296e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_RESUME; 297e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 298e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 299e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 300e0e9324cSopenharmony_ci agentMsg->mediaType = mediaType; 301e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 302e0e9324cSopenharmony_ci if (ret != -1) { 303e0e9324cSopenharmony_ci SHARING_LOGI("resume agent success agentId: %{public}u.", agentId); 304e0e9324cSopenharmony_ci } else { 305e0e9324cSopenharmony_ci SHARING_LOGE("resume agent failed, agentId: %{public}u.", agentId); 306e0e9324cSopenharmony_ci } 307e0e9324cSopenharmony_ci 308e0e9324cSopenharmony_ci return ret; 309e0e9324cSopenharmony_ci} 310e0e9324cSopenharmony_ci 311e0e9324cSopenharmony_ciint32_t Interaction::ForwardEvent(uint32_t contextId, uint32_t agentId, SharingEvent &event, bool isSync) 312e0e9324cSopenharmony_ci{ 313e0e9324cSopenharmony_ci SHARING_LOGI("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 314e0e9324cSopenharmony_ci RETURN_INVALID_IF_NULL(event.eventMsg); 315e0e9324cSopenharmony_ci event.eventMsg->fromMgr = MODULE_INTERACTION; 316e0e9324cSopenharmony_ci event.eventMsg->srcId = GetId(); 317e0e9324cSopenharmony_ci event.listenerType = CLASS_TYPE_SCHEDULER; 318e0e9324cSopenharmony_ci 319e0e9324cSopenharmony_ci if (isSync) { 320e0e9324cSopenharmony_ci return SendSyncEvent(event); 321e0e9324cSopenharmony_ci } else { 322e0e9324cSopenharmony_ci return SendEvent(event); 323e0e9324cSopenharmony_ci } 324e0e9324cSopenharmony_ci} 325e0e9324cSopenharmony_ci 326e0e9324cSopenharmony_ciint32_t Interaction::Play(uint32_t contextId, uint32_t agentId) 327e0e9324cSopenharmony_ci{ 328e0e9324cSopenharmony_ci SHARING_LOGI("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 329e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 330e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_PLAY_START; 331e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 332e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 333e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 334e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 335e0e9324cSopenharmony_ci if (ret != -1) { 336e0e9324cSopenharmony_ci SHARING_LOGI("agent play success agentId: %{public}u.", agentId); 337e0e9324cSopenharmony_ci } else { 338e0e9324cSopenharmony_ci SHARING_LOGE("agent play failed, agentId: %{public}u.", agentId); 339e0e9324cSopenharmony_ci } 340e0e9324cSopenharmony_ci 341e0e9324cSopenharmony_ci return ret; 342e0e9324cSopenharmony_ci} 343e0e9324cSopenharmony_ci 344e0e9324cSopenharmony_ciint32_t Interaction::Close(uint32_t contextId, uint32_t agentId) 345e0e9324cSopenharmony_ci{ 346e0e9324cSopenharmony_ci SHARING_LOGI("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 347e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 348e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_PLAY_STOP; 349e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 350e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 351e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 352e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 353e0e9324cSopenharmony_ci if (ret != -1) { 354e0e9324cSopenharmony_ci SHARING_LOGI("agent close success agentId: %{public}u.", agentId); 355e0e9324cSopenharmony_ci } else { 356e0e9324cSopenharmony_ci SHARING_LOGE("agent close failed, agentId: %{public}u.", agentId); 357e0e9324cSopenharmony_ci } 358e0e9324cSopenharmony_ci 359e0e9324cSopenharmony_ci return ret; 360e0e9324cSopenharmony_ci} 361e0e9324cSopenharmony_ci 362e0e9324cSopenharmony_ciint32_t Interaction::SetVolume(uint32_t contextId, uint32_t agentId, float volume) 363e0e9324cSopenharmony_ci{ 364e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 365e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 366e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_CHANNEL_SETVOLUME; 367e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 368e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 369e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 370e0e9324cSopenharmony_ci agentMsg->volume = volume; 371e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 372e0e9324cSopenharmony_ci if (ret != -1) { 373e0e9324cSopenharmony_ci SHARING_LOGI("agent set volume success agentId: %{public}u.", agentId); 374e0e9324cSopenharmony_ci } else { 375e0e9324cSopenharmony_ci SHARING_LOGE("agent set volume failed, agentId: %{public}u.", agentId); 376e0e9324cSopenharmony_ci } 377e0e9324cSopenharmony_ci 378e0e9324cSopenharmony_ci return 0; 379e0e9324cSopenharmony_ci} 380e0e9324cSopenharmony_ci 381e0e9324cSopenharmony_ciint32_t Interaction::SetKeyPlay(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyFrame) 382e0e9324cSopenharmony_ci{ 383e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 384e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 385e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_CHANNEL_SETSCENETYPE; 386e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 387e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 388e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 389e0e9324cSopenharmony_ci agentMsg->surfaceId = surfaceId; 390e0e9324cSopenharmony_ci agentMsg->sceneType = keyFrame ? SceneType::BACKGROUND : SceneType::FOREGROUND; 391e0e9324cSopenharmony_ci 392e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 393e0e9324cSopenharmony_ci if (ret != -1) { 394e0e9324cSopenharmony_ci SHARING_LOGI("agent set key play success agentId: %{public}u.", agentId); 395e0e9324cSopenharmony_ci } else { 396e0e9324cSopenharmony_ci SHARING_LOGE("agent set key play failed, agentId: %{public}u.", agentId); 397e0e9324cSopenharmony_ci } 398e0e9324cSopenharmony_ci 399e0e9324cSopenharmony_ci return ret; 400e0e9324cSopenharmony_ci} 401e0e9324cSopenharmony_ci 402e0e9324cSopenharmony_ciint32_t Interaction::SetKeyRedirect(uint32_t contextId, uint32_t agentId, uint64_t surfaceId, bool keyRedirect) 403e0e9324cSopenharmony_ci{ 404e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 405e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 406e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_CHANNEL_SETKEYREDIRECT; 407e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 408e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 409e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 410e0e9324cSopenharmony_ci agentMsg->surfaceId = surfaceId; 411e0e9324cSopenharmony_ci agentMsg->keyRedirect = keyRedirect; 412e0e9324cSopenharmony_ci 413e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 414e0e9324cSopenharmony_ci if (ret != -1) { 415e0e9324cSopenharmony_ci SHARING_LOGI("agent set key play success agentId: %{public}u.", agentId); 416e0e9324cSopenharmony_ci } else { 417e0e9324cSopenharmony_ci SHARING_LOGE("agent set key play failed, agentId: %{public}u.", agentId); 418e0e9324cSopenharmony_ci } 419e0e9324cSopenharmony_ci 420e0e9324cSopenharmony_ci return ret; 421e0e9324cSopenharmony_ci} 422e0e9324cSopenharmony_ci 423e0e9324cSopenharmony_ciint32_t Interaction::AppendSurface(uint32_t contextId, uint32_t agentId, sptr<Surface> surface, SceneType sceneType) 424e0e9324cSopenharmony_ci{ 425e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 426e0e9324cSopenharmony_ci RETURN_INVALID_IF_NULL(surface); 427e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 428e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_CHANNEL_APPENDSURFACE; 429e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 430e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 431e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 432e0e9324cSopenharmony_ci agentMsg->surface = surface; 433e0e9324cSopenharmony_ci agentMsg->sceneType = sceneType; 434e0e9324cSopenharmony_ci agentMsg->requestId = GetRequestId(); 435e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 436e0e9324cSopenharmony_ci if (ret != -1) { 437e0e9324cSopenharmony_ci SHARING_LOGI("agent set surface success agentId: %{public}u.", agentId); 438e0e9324cSopenharmony_ci } else { 439e0e9324cSopenharmony_ci SHARING_LOGE("agent set surface failed, agentId: %{public}u.", agentId); 440e0e9324cSopenharmony_ci } 441e0e9324cSopenharmony_ci 442e0e9324cSopenharmony_ci return ret; 443e0e9324cSopenharmony_ci} 444e0e9324cSopenharmony_ci 445e0e9324cSopenharmony_ciint32_t Interaction::RemoveSurface(uint32_t contextId, uint32_t agentId, uint64_t surfaceId) 446e0e9324cSopenharmony_ci{ 447e0e9324cSopenharmony_ci SHARING_LOGD("contextId: %{public}u, agentId: %{public}u.", contextId, agentId); 448e0e9324cSopenharmony_ci auto agentMsg = std::make_shared<AgentEventMsg>(); 449e0e9324cSopenharmony_ci agentMsg->type = EventType::EVENT_AGENT_CHANNEL_REMOVESURFACE; 450e0e9324cSopenharmony_ci agentMsg->toMgr = ModuleType::MODULE_CONTEXT; 451e0e9324cSopenharmony_ci agentMsg->dstId = contextId; 452e0e9324cSopenharmony_ci agentMsg->agentId = agentId; 453e0e9324cSopenharmony_ci agentMsg->surfaceId = surfaceId; 454e0e9324cSopenharmony_ci agentMsg->requestId = GetRequestId(); 455e0e9324cSopenharmony_ci int32_t ret = NotifyEvent(agentMsg); 456e0e9324cSopenharmony_ci if (ret != -1) { 457e0e9324cSopenharmony_ci SHARING_LOGI("agent del surface success agentId: %{public}u.", agentId); 458e0e9324cSopenharmony_ci } else { 459e0e9324cSopenharmony_ci SHARING_LOGE("agent del surface failed, agentId: %{public}u.", agentId); 460e0e9324cSopenharmony_ci } 461e0e9324cSopenharmony_ci 462e0e9324cSopenharmony_ci return ret; 463e0e9324cSopenharmony_ci} 464e0e9324cSopenharmony_ci 465e0e9324cSopenharmony_ciint32_t Interaction::DestroyWindow(int32_t windowId) 466e0e9324cSopenharmony_ci{ 467e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 468e0e9324cSopenharmony_ci (void)windowId; 469e0e9324cSopenharmony_ci return 0; 470e0e9324cSopenharmony_ci} 471e0e9324cSopenharmony_ci 472e0e9324cSopenharmony_ciint32_t Interaction::CreateWindow(int32_t &windowId, WindowProperty &windowProperty) 473e0e9324cSopenharmony_ci{ 474e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 475e0e9324cSopenharmony_ci (void)windowId; 476e0e9324cSopenharmony_ci (void)windowProperty; 477e0e9324cSopenharmony_ci return 0; 478e0e9324cSopenharmony_ci} 479e0e9324cSopenharmony_ci 480e0e9324cSopenharmony_ciint32_t Interaction::Hide(int32_t windowId) 481e0e9324cSopenharmony_ci{ 482e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 483e0e9324cSopenharmony_ci (void)windowId; 484e0e9324cSopenharmony_ci return 0; 485e0e9324cSopenharmony_ci} 486e0e9324cSopenharmony_ci 487e0e9324cSopenharmony_ciint32_t Interaction::Show(int32_t windowId) 488e0e9324cSopenharmony_ci{ 489e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 490e0e9324cSopenharmony_ci (void)windowId; 491e0e9324cSopenharmony_ci return 0; 492e0e9324cSopenharmony_ci} 493e0e9324cSopenharmony_ci 494e0e9324cSopenharmony_ciint32_t Interaction::SetFullScreen(int32_t windowId, bool isFull) 495e0e9324cSopenharmony_ci{ 496e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 497e0e9324cSopenharmony_ci (void)windowId; 498e0e9324cSopenharmony_ci (void)isFull; 499e0e9324cSopenharmony_ci return 0; 500e0e9324cSopenharmony_ci} 501e0e9324cSopenharmony_ci 502e0e9324cSopenharmony_ciint32_t Interaction::MoveTo(int32_t windowId, int32_t x, int32_t y) 503e0e9324cSopenharmony_ci{ 504e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 505e0e9324cSopenharmony_ci (void)windowId; 506e0e9324cSopenharmony_ci (void)x; 507e0e9324cSopenharmony_ci (void)y; 508e0e9324cSopenharmony_ci return 0; 509e0e9324cSopenharmony_ci} 510e0e9324cSopenharmony_ci 511e0e9324cSopenharmony_ciint32_t Interaction::GetSurface(int32_t windowId, sptr<Surface> &surface) 512e0e9324cSopenharmony_ci{ 513e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 514e0e9324cSopenharmony_ci (void)windowId; 515e0e9324cSopenharmony_ci (void)surface; 516e0e9324cSopenharmony_ci return 0; 517e0e9324cSopenharmony_ci} 518e0e9324cSopenharmony_ci 519e0e9324cSopenharmony_ciint32_t Interaction::ReSize(int32_t windowId, int32_t width, int32_t height) 520e0e9324cSopenharmony_ci{ 521e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 522e0e9324cSopenharmony_ci (void)windowId; 523e0e9324cSopenharmony_ci (void)width; 524e0e9324cSopenharmony_ci (void)height; 525e0e9324cSopenharmony_ci return 0; 526e0e9324cSopenharmony_ci} 527e0e9324cSopenharmony_ci 528e0e9324cSopenharmony_ci} // namespace Sharing 529e0e9324cSopenharmony_ci} // namespace OHOS