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 "conference_base.h"
17
18 #include <string_ex.h>
19
20 #include "call_object_manager.h"
21 #include "call_manager_errors.h"
22 #include "telephony_log_wrapper.h"
23
24 namespace OHOS {
25 namespace Telephony {
ConferenceBase()26 ConferenceBase::ConferenceBase()
27 : mainCallId_(ERR_ID), state_(CONFERENCE_STATE_IDLE), beginTime_(0), conferenceType_(CallType::TYPE_CS)
28 {
29 subCallIdSet_.clear();
30 }
31
~ConferenceBase()32 ConferenceBase::~ConferenceBase()
33 {
34 std::lock_guard<std::mutex> lock(conferenceMutex_);
35 subCallIdSet_.clear();
36 }
37
GetMainCall()38 int32_t ConferenceBase::GetMainCall()
39 {
40 std::lock_guard<std::mutex> lock(conferenceMutex_);
41 return mainCallId_;
42 }
43
SetMainCall(int32_t callId)44 int32_t ConferenceBase::SetMainCall(int32_t callId)
45 {
46 if (callId <= ERR_ID) {
47 TELEPHONY_LOGE("callId is invalid:%{public}d", callId);
48 return CALL_ERR_INVALID_CALLID;
49 }
50 int32_t ret = CanCombineConference();
51 if (ret != TELEPHONY_SUCCESS) {
52 TELEPHONY_LOGE("join conference failed, errorCode:%{public}d", ret);
53 return ret;
54 }
55 std::lock_guard<std::mutex> lock(conferenceMutex_);
56 mainCallId_ = callId;
57 state_ = CONFERENCE_STATE_CREATING;
58 return TELEPHONY_SUCCESS;
59 }
60
GetConferenceState()61 ConferenceState ConferenceBase::GetConferenceState()
62 {
63 std::lock_guard<std::mutex> lock(conferenceMutex_);
64 return state_;
65 }
66
SetConferenceState(ConferenceState state)67 void ConferenceBase::SetConferenceState(ConferenceState state)
68 {
69 std::lock_guard<std::mutex> lock(conferenceMutex_);
70 state_ = state;
71 }
72
GetSubCallIdList(int32_t callId,std::vector<std::u16string> & callIdList)73 int32_t ConferenceBase::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
74 {
75 bool flag = false;
76 callIdList.clear();
77 std::lock_guard<std::mutex> lock(conferenceMutex_);
78 for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) {
79 if (*it == callId) {
80 flag = true;
81 }
82 callIdList.push_back(Str8ToStr16(std::to_string(*it)));
83 TELEPHONY_LOGI("subCallId_:%{public}d", *it);
84 }
85 if (!flag) {
86 callIdList.clear();
87 TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId);
88 return CALL_ERR_THE_CALL_IS_NOT_IN_THE_CONFERENCE;
89 }
90 return TELEPHONY_SUCCESS;
91 }
92
GetCallIdListForConference(int32_t callId,std::vector<std::u16string> & callIdList)93 int32_t ConferenceBase::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
94 {
95 bool flag = false;
96 callIdList.clear();
97 std::lock_guard<std::mutex> lock(conferenceMutex_);
98 for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) {
99 if (*it == callId) {
100 flag = true;
101 }
102 callIdList.push_back(Str8ToStr16(std::to_string(*it)));
103 TELEPHONY_LOGI("subCallId_:%{public}d", *it);
104 }
105 if (mainCallId_ == callId) {
106 flag = true;
107 }
108 callIdList.push_back(Str8ToStr16(std::to_string(mainCallId_)));
109 if (!flag) {
110 callIdList.clear();
111 TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId);
112 return CALL_ERR_THE_CALL_IS_NOT_IN_THE_CONFERENCE;
113 }
114 return TELEPHONY_SUCCESS;
115 }
116 } // namespace Telephony
117 } // namespace OHOS
118