1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "ott_conference.h"
17
18 #include <string_ex.h>
19
20 #include "call_base.h"
21 #include "call_object_manager.h"
22 #include "call_manager_errors.h"
23 #include "telephony_log_wrapper.h"
24 #include "call_manager_inner_type.h"
25
26 namespace OHOS {
27 namespace Telephony {
OttConference()28 OttConference::OttConference() : ConferenceBase()
29 {
30 conferenceType_ = CallType::TYPE_IMS;
31 maxSubCallLimits_ = CS_CONFERENCE_MAX_CALLS_CNT;
32 // get from configuration file
33 #ifdef ABILITY_CONFIG_SUPPORT
34 maxSubCallLimits_ = GetConfig(IMS_CONFERENCE_SUB_CALL_LIMITS);
35 #endif
36 }
37
~OttConference()38 OttConference::~OttConference() {}
39
JoinToConference(int32_t callId)40 int32_t OttConference::JoinToConference(int32_t callId)
41 {
42 std::lock_guard<std::mutex> lock(conferenceMutex_);
43 if (state_ != CONFERENCE_STATE_CREATING && state_ != CONFERENCE_STATE_ACTIVE &&
44 state_ != CONFERENCE_STATE_LEAVING) {
45 TELEPHONY_LOGE("the current conference status does not allow CombineConference");
46 return CALL_ERR_ILLEGAL_CALL_OPERATION;
47 }
48 if (subCallIdSet_.size() >= maxSubCallLimits_) {
49 TELEPHONY_LOGE("already %{public}zu calls in the conference, exceed limits!", subCallIdSet_.size());
50 return CALL_ERR_CONFERENCE_CALL_EXCEED_LIMIT;
51 }
52
53 subCallIdSet_.insert(callId);
54 state_ = CONFERENCE_STATE_ACTIVE;
55 beginTime_ = time(nullptr);
56 TELEPHONY_LOGI("JoinToConference success, callId:%{public}d", callId);
57 return TELEPHONY_SUCCESS;
58 }
59
LeaveFromConference(int32_t callId)60 int32_t OttConference::LeaveFromConference(int32_t callId)
61 {
62 std::lock_guard<std::mutex> lock(conferenceMutex_);
63 if (subCallIdSet_.find(callId) != subCallIdSet_.end()) {
64 subCallIdSet_.erase(callId);
65 if (mainCallId_ == callId) {
66 mainCallId_ = *subCallIdSet_.begin();
67 }
68 } else {
69 TELEPHONY_LOGE("separate conference failed, callId %{public}d not in conference", callId);
70 return CALL_ERR_CONFERENCE_SEPERATE_FAILED;
71 }
72 if (subCallIdSet_.empty()) {
73 mainCallId_ = ERR_ID;
74 state_ = CONFERENCE_STATE_IDLE;
75 beginTime_ = 0;
76 }
77 return TELEPHONY_SUCCESS;
78 }
79
HoldConference(int32_t callId)80 int32_t OttConference::HoldConference(int32_t callId)
81 {
82 std::lock_guard<std::mutex> lock(conferenceMutex_);
83 if (state_ == CONFERENCE_STATE_HOLDING) {
84 TELEPHONY_LOGI("HoldConference success");
85 return TELEPHONY_SUCCESS;
86 }
87 if (subCallIdSet_.find(callId) != subCallIdSet_.end()) {
88 subCallIdSet_.erase(callId);
89 } else {
90 TELEPHONY_LOGE("separate conference failed, callId %{public}d not in conference", callId);
91 return CALL_ERR_CONFERENCE_SEPERATE_FAILED;
92 }
93 if (subCallIdSet_.empty()) {
94 mainCallId_ = ERR_ID;
95 state_ = CONFERENCE_STATE_IDLE;
96 beginTime_ = 0;
97 }
98 return TELEPHONY_SUCCESS;
99 }
100
CanCombineConference()101 int32_t OttConference::CanCombineConference()
102 {
103 std::lock_guard<std::mutex> lock(conferenceMutex_);
104 if (subCallIdSet_.size() >= maxSubCallLimits_) {
105 TELEPHONY_LOGE("already %{public}zu calls in the conference, exceed limits!", subCallIdSet_.size());
106 return CALL_ERR_CONFERENCE_CALL_EXCEED_LIMIT;
107 }
108 return TELEPHONY_SUCCESS;
109 }
110
CanSeparateConference()111 int32_t OttConference::CanSeparateConference()
112 {
113 std::lock_guard<std::mutex> lock(conferenceMutex_);
114 if (subCallIdSet_.empty() || state_ != CONFERENCE_STATE_ACTIVE) {
115 TELEPHONY_LOGE("no call is currently in the conference!");
116 return CALL_ERR_CONFERENCE_NOT_EXISTS;
117 }
118 return TELEPHONY_SUCCESS;
119 }
120
CanKickOutFromConference()121 int32_t OttConference::CanKickOutFromConference()
122 {
123 std::lock_guard<std::mutex> lock(conferenceMutex_);
124 if (subCallIdSet_.empty() || state_ != CONFERENCE_STATE_ACTIVE) {
125 TELEPHONY_LOGE("no call is currently in the conference!");
126 return CALL_ERR_CONFERENCE_NOT_EXISTS;
127 }
128 return TELEPHONY_SUCCESS;
129 }
130 } // namespace Telephony
131 } // namespace OHOS
132