1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#include "conference_base.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <string_ex.h> 19e1c44949Sopenharmony_ci 20e1c44949Sopenharmony_ci#include "call_object_manager.h" 21e1c44949Sopenharmony_ci#include "call_manager_errors.h" 22e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h" 23e1c44949Sopenharmony_ci 24e1c44949Sopenharmony_cinamespace OHOS { 25e1c44949Sopenharmony_cinamespace Telephony { 26e1c44949Sopenharmony_ciConferenceBase::ConferenceBase() 27e1c44949Sopenharmony_ci : mainCallId_(ERR_ID), state_(CONFERENCE_STATE_IDLE), oldState_(CONFERENCE_STATE_IDLE), beginTime_(0), 28e1c44949Sopenharmony_ci conferenceType_(CallType::TYPE_CS) 29e1c44949Sopenharmony_ci{ 30e1c44949Sopenharmony_ci subCallIdSet_.clear(); 31e1c44949Sopenharmony_ci} 32e1c44949Sopenharmony_ci 33e1c44949Sopenharmony_ciConferenceBase::~ConferenceBase() 34e1c44949Sopenharmony_ci{ 35e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 36e1c44949Sopenharmony_ci subCallIdSet_.clear(); 37e1c44949Sopenharmony_ci} 38e1c44949Sopenharmony_ci 39e1c44949Sopenharmony_ciint32_t ConferenceBase::GetMainCall() 40e1c44949Sopenharmony_ci{ 41e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 42e1c44949Sopenharmony_ci return mainCallId_; 43e1c44949Sopenharmony_ci} 44e1c44949Sopenharmony_ci 45e1c44949Sopenharmony_ciint32_t ConferenceBase::SetMainCall(int32_t callId) 46e1c44949Sopenharmony_ci{ 47e1c44949Sopenharmony_ci if (callId < ERR_ID) { 48e1c44949Sopenharmony_ci TELEPHONY_LOGE("callId is invalid:%{public}d", callId); 49e1c44949Sopenharmony_ci return CALL_ERR_INVALID_CALLID; 50e1c44949Sopenharmony_ci } 51e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 52e1c44949Sopenharmony_ci mainCallId_ = callId; 53e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 54e1c44949Sopenharmony_ci} 55e1c44949Sopenharmony_ci 56e1c44949Sopenharmony_ciConferenceState ConferenceBase::GetConferenceState() 57e1c44949Sopenharmony_ci{ 58e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 59e1c44949Sopenharmony_ci return state_; 60e1c44949Sopenharmony_ci} 61e1c44949Sopenharmony_ci 62e1c44949Sopenharmony_civoid ConferenceBase::SetConferenceState(ConferenceState state) 63e1c44949Sopenharmony_ci{ 64e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 65e1c44949Sopenharmony_ci state_ = state; 66e1c44949Sopenharmony_ci} 67e1c44949Sopenharmony_ci 68e1c44949Sopenharmony_civoid ConferenceBase::SetOldConferenceState(ConferenceState state) 69e1c44949Sopenharmony_ci{ 70e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 71e1c44949Sopenharmony_ci oldState_ = state; 72e1c44949Sopenharmony_ci} 73e1c44949Sopenharmony_ci 74e1c44949Sopenharmony_ciConferenceState ConferenceBase::GetOldConferenceState() 75e1c44949Sopenharmony_ci{ 76e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 77e1c44949Sopenharmony_ci return oldState_; 78e1c44949Sopenharmony_ci} 79e1c44949Sopenharmony_ci 80e1c44949Sopenharmony_ciint32_t ConferenceBase::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList) 81e1c44949Sopenharmony_ci{ 82e1c44949Sopenharmony_ci bool flag = false; 83e1c44949Sopenharmony_ci callIdList.clear(); 84e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 85e1c44949Sopenharmony_ci for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) { 86e1c44949Sopenharmony_ci if (*it == callId) { 87e1c44949Sopenharmony_ci flag = true; 88e1c44949Sopenharmony_ci } 89e1c44949Sopenharmony_ci callIdList.push_back(Str8ToStr16(std::to_string(*it))); 90e1c44949Sopenharmony_ci TELEPHONY_LOGI("subCallId_:%{public}d", *it); 91e1c44949Sopenharmony_ci } 92e1c44949Sopenharmony_ci if (!flag) { 93e1c44949Sopenharmony_ci callIdList.clear(); 94e1c44949Sopenharmony_ci TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId); 95e1c44949Sopenharmony_ci return CALL_ERR_THE_CALL_IS_NOT_IN_THE_CONFERENCE; 96e1c44949Sopenharmony_ci } 97e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 98e1c44949Sopenharmony_ci} 99e1c44949Sopenharmony_ci 100e1c44949Sopenharmony_cistd::set<int32_t> ConferenceBase::GetSubCallIdList() 101e1c44949Sopenharmony_ci{ 102e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 103e1c44949Sopenharmony_ci return subCallIdSet_; 104e1c44949Sopenharmony_ci} 105e1c44949Sopenharmony_ci 106e1c44949Sopenharmony_ciint32_t ConferenceBase::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList) 107e1c44949Sopenharmony_ci{ 108e1c44949Sopenharmony_ci bool flag = false; 109e1c44949Sopenharmony_ci callIdList.clear(); 110e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 111e1c44949Sopenharmony_ci for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) { 112e1c44949Sopenharmony_ci if (*it == callId) { 113e1c44949Sopenharmony_ci flag = true; 114e1c44949Sopenharmony_ci } 115e1c44949Sopenharmony_ci callIdList.push_back(Str8ToStr16(std::to_string(*it))); 116e1c44949Sopenharmony_ci TELEPHONY_LOGI("subCallId_:%{public}d", *it); 117e1c44949Sopenharmony_ci } 118e1c44949Sopenharmony_ci if (mainCallId_ == callId) { 119e1c44949Sopenharmony_ci flag = true; 120e1c44949Sopenharmony_ci } 121e1c44949Sopenharmony_ci callIdList.push_back(Str8ToStr16(std::to_string(mainCallId_))); 122e1c44949Sopenharmony_ci if (!flag) { 123e1c44949Sopenharmony_ci callIdList.clear(); 124e1c44949Sopenharmony_ci TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId); 125e1c44949Sopenharmony_ci return CALL_ERR_THE_CALL_IS_NOT_IN_THE_CONFERENCE; 126e1c44949Sopenharmony_ci } 127e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 128e1c44949Sopenharmony_ci} 129e1c44949Sopenharmony_ci} // namespace Telephony 130e1c44949Sopenharmony_ci} // namespace OHOS 131