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 "scheduler.h" 17e0e9324cSopenharmony_ci#include "common/common_macro.h" 18e0e9324cSopenharmony_ci#include "common/sharing_log.h" 19e0e9324cSopenharmony_ci#include "context/context_manager.h" 20e0e9324cSopenharmony_ci#include "event/event_manager.h" 21e0e9324cSopenharmony_ci#include "extend/magic_enum/magic_enum.hpp" 22e0e9324cSopenharmony_ci#include "interaction/interaction_manager.h" 23e0e9324cSopenharmony_ci#include "mediachannel/channel_manager.h" 24e0e9324cSopenharmony_ci 25e0e9324cSopenharmony_cinamespace OHOS { 26e0e9324cSopenharmony_cinamespace Sharing { 27e0e9324cSopenharmony_ci 28e0e9324cSopenharmony_ciScheduler::Scheduler() 29e0e9324cSopenharmony_ci{ 30e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 31e0e9324cSopenharmony_ci EventManager::GetInstance().AddListener(std::make_shared<SchedulerEventListener>()); 32e0e9324cSopenharmony_ci} 33e0e9324cSopenharmony_ci 34e0e9324cSopenharmony_ciint32_t Scheduler::HandleEvent(SharingEvent &event) 35e0e9324cSopenharmony_ci{ 36e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 37e0e9324cSopenharmony_ci RETURN_INVALID_IF_NULL(event.eventMsg); 38e0e9324cSopenharmony_ci int32_t ret = -1; 39e0e9324cSopenharmony_ci switch (event.eventMsg->toMgr) { 40e0e9324cSopenharmony_ci case MODULE_CONTEXT: 41e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to context %{public}s.", 42e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 43e0e9324cSopenharmony_ci ret = ContextManager::GetInstance().HandleEvent(event); 44e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to context return %{public}s.", 45e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 46e0e9324cSopenharmony_ci break; 47e0e9324cSopenharmony_ci case MODULE_MEDIACHANNEL: 48e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to channel %{public}s.", 49e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 50e0e9324cSopenharmony_ci ret = ChannelManager::GetInstance().HandleEvent(event); 51e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to channel return %{public}s.", 52e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 53e0e9324cSopenharmony_ci break; 54e0e9324cSopenharmony_ci case MODULE_INTERACTION: 55e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to interaction %{public}s.", 56e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 57e0e9324cSopenharmony_ci ret = InteractionManager::GetInstance().HandleEvent(event); 58e0e9324cSopenharmony_ci SHARING_LOGD("handleEvent to interaction return %{public}s.", 59e0e9324cSopenharmony_ci std::string(magic_enum::enum_name(event.eventMsg->type)).c_str()); 60e0e9324cSopenharmony_ci break; 61e0e9324cSopenharmony_ci default: 62e0e9324cSopenharmony_ci break; 63e0e9324cSopenharmony_ci } 64e0e9324cSopenharmony_ci 65e0e9324cSopenharmony_ci return ret; 66e0e9324cSopenharmony_ci} 67e0e9324cSopenharmony_ci 68e0e9324cSopenharmony_ciint32_t SchedulerEventListener::OnEvent(SharingEvent &event) 69e0e9324cSopenharmony_ci{ 70e0e9324cSopenharmony_ci SHARING_LOGD("trace."); 71e0e9324cSopenharmony_ci return Scheduler::GetInstance().HandleEvent(event); 72e0e9324cSopenharmony_ci} 73e0e9324cSopenharmony_ci 74e0e9324cSopenharmony_ci} // namespace Sharing 75e0e9324cSopenharmony_ci} // namespace OHOS