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 "ims_conference.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <string_ex.h> 19e1c44949Sopenharmony_ci 20e1c44949Sopenharmony_ci#include "call_base.h" 21e1c44949Sopenharmony_ci#include "call_object_manager.h" 22e1c44949Sopenharmony_ci#include "call_manager_errors.h" 23e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h" 24e1c44949Sopenharmony_ci#include "call_manager_inner_type.h" 25e1c44949Sopenharmony_ci 26e1c44949Sopenharmony_cinamespace OHOS { 27e1c44949Sopenharmony_cinamespace Telephony { 28e1c44949Sopenharmony_ciImsConference::ImsConference() : ConferenceBase() 29e1c44949Sopenharmony_ci{ 30e1c44949Sopenharmony_ci conferenceType_ = CallType::TYPE_IMS; 31e1c44949Sopenharmony_ci maxSubCallLimits_ = CS_CONFERENCE_MAX_CALLS_CNT; 32e1c44949Sopenharmony_ci // get from configuration file 33e1c44949Sopenharmony_ci#ifdef ABILITY_CONFIG_SUPPORT 34e1c44949Sopenharmony_ci maxSubCallLimits_ = GetConfig(IMS_CONFERENCE_SUB_CALL_LIMITS); 35e1c44949Sopenharmony_ci#endif 36e1c44949Sopenharmony_ci} 37e1c44949Sopenharmony_ci 38e1c44949Sopenharmony_ciImsConference::~ImsConference() {} 39e1c44949Sopenharmony_ci 40e1c44949Sopenharmony_ciint32_t ImsConference::JoinToConference(int32_t callId) 41e1c44949Sopenharmony_ci{ 42e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 43e1c44949Sopenharmony_ci if (state_ != CONFERENCE_STATE_CREATING && state_ != CONFERENCE_STATE_ACTIVE && 44e1c44949Sopenharmony_ci state_ != CONFERENCE_STATE_LEAVING && state_ != CONFERENCE_STATE_HOLDING) { 45e1c44949Sopenharmony_ci TELEPHONY_LOGE("the current conference status does not allow CombineConference"); 46e1c44949Sopenharmony_ci return CALL_ERR_ILLEGAL_CALL_OPERATION; 47e1c44949Sopenharmony_ci } 48e1c44949Sopenharmony_ci 49e1c44949Sopenharmony_ci subCallIdSet_.insert(callId); 50e1c44949Sopenharmony_ci state_ = CONFERENCE_STATE_ACTIVE; 51e1c44949Sopenharmony_ci oldState_ = state_; 52e1c44949Sopenharmony_ci beginTime_ = time(nullptr); 53e1c44949Sopenharmony_ci TELEPHONY_LOGI("JoinToConference success, callId:%{public}d", callId); 54e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 55e1c44949Sopenharmony_ci} 56e1c44949Sopenharmony_ci 57e1c44949Sopenharmony_ciint32_t ImsConference::LeaveFromConference(int32_t callId) 58e1c44949Sopenharmony_ci{ 59e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 60e1c44949Sopenharmony_ci if (subCallIdSet_.find(callId) != subCallIdSet_.end()) { 61e1c44949Sopenharmony_ci subCallIdSet_.erase(callId); 62e1c44949Sopenharmony_ci if (mainCallId_ == callId) { 63e1c44949Sopenharmony_ci mainCallId_ = *subCallIdSet_.begin(); 64e1c44949Sopenharmony_ci } 65e1c44949Sopenharmony_ci } else { 66e1c44949Sopenharmony_ci TELEPHONY_LOGE("separate conference failed, callId %{public}d not in conference", callId); 67e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_SEPERATE_FAILED; 68e1c44949Sopenharmony_ci } 69e1c44949Sopenharmony_ci if (subCallIdSet_.empty()) { 70e1c44949Sopenharmony_ci mainCallId_ = ERR_ID; 71e1c44949Sopenharmony_ci state_ = CONFERENCE_STATE_IDLE; 72e1c44949Sopenharmony_ci oldState_ = state_; 73e1c44949Sopenharmony_ci beginTime_ = 0; 74e1c44949Sopenharmony_ci } 75e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 76e1c44949Sopenharmony_ci} 77e1c44949Sopenharmony_ci 78e1c44949Sopenharmony_ciint32_t ImsConference::HoldConference(int32_t callId) 79e1c44949Sopenharmony_ci{ 80e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 81e1c44949Sopenharmony_ci if (state_ == CONFERENCE_STATE_HOLDING) { 82e1c44949Sopenharmony_ci TELEPHONY_LOGI("HoldConference success"); 83e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 84e1c44949Sopenharmony_ci } 85e1c44949Sopenharmony_ci if (subCallIdSet_.find(callId) == subCallIdSet_.end()) { 86e1c44949Sopenharmony_ci TELEPHONY_LOGE("separate conference failed, callId %{public}d not in conference", callId); 87e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_SEPERATE_FAILED; 88e1c44949Sopenharmony_ci } 89e1c44949Sopenharmony_ci if (subCallIdSet_.empty()) { 90e1c44949Sopenharmony_ci mainCallId_ = ERR_ID; 91e1c44949Sopenharmony_ci state_ = CONFERENCE_STATE_IDLE; 92e1c44949Sopenharmony_ci oldState_ = state_; 93e1c44949Sopenharmony_ci beginTime_ = 0; 94e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_SEPERATE_FAILED; 95e1c44949Sopenharmony_ci } 96e1c44949Sopenharmony_ci state_ = CONFERENCE_STATE_HOLDING; 97e1c44949Sopenharmony_ci oldState_ = state_; 98e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 99e1c44949Sopenharmony_ci} 100e1c44949Sopenharmony_ci 101e1c44949Sopenharmony_ciint32_t ImsConference::CanCombineConference() 102e1c44949Sopenharmony_ci{ 103e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 104e1c44949Sopenharmony_ci if (subCallIdSet_.size() >= maxSubCallLimits_) { 105e1c44949Sopenharmony_ci TELEPHONY_LOGE("already %{public}zu calls in the conference, exceed limits!", subCallIdSet_.size()); 106e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_CALL_EXCEED_LIMIT; 107e1c44949Sopenharmony_ci } 108e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 109e1c44949Sopenharmony_ci} 110e1c44949Sopenharmony_ci 111e1c44949Sopenharmony_ciint32_t ImsConference::CanSeparateConference() 112e1c44949Sopenharmony_ci{ 113e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 114e1c44949Sopenharmony_ci if (subCallIdSet_.empty()) { 115e1c44949Sopenharmony_ci TELEPHONY_LOGE("no call is currently in the conference!"); 116e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_NOT_EXISTS; 117e1c44949Sopenharmony_ci } 118e1c44949Sopenharmony_ci if (state_ != CONFERENCE_STATE_ACTIVE) { 119e1c44949Sopenharmony_ci TELEPHONY_LOGE("call is not active!"); 120e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_CALL_IS_NOT_ACTIVE; 121e1c44949Sopenharmony_ci } 122e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 123e1c44949Sopenharmony_ci} 124e1c44949Sopenharmony_ci 125e1c44949Sopenharmony_ciint32_t ImsConference::CanKickOutFromConference() 126e1c44949Sopenharmony_ci{ 127e1c44949Sopenharmony_ci std::lock_guard<std::mutex> lock(conferenceMutex_); 128e1c44949Sopenharmony_ci if (subCallIdSet_.empty()) { 129e1c44949Sopenharmony_ci TELEPHONY_LOGE("no call is currently in the conference!"); 130e1c44949Sopenharmony_ci return CALL_ERR_CONFERENCE_NOT_EXISTS; 131e1c44949Sopenharmony_ci } 132e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 133e1c44949Sopenharmony_ci} 134e1c44949Sopenharmony_ci} // namespace Telephony 135e1c44949Sopenharmony_ci} // namespace OHOS 136