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)73 std::vector<std::u16string> ConferenceBase::GetSubCallIdList(int32_t callId)
74 {
75 std::vector<std::u16string> vec;
76 bool flag = false;
77 vec.clear();
78 std::lock_guard<std::mutex> lock(conferenceMutex_);
79 for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) {
80 if (*it == callId) {
81 flag = true;
82 }
83 vec.push_back(Str8ToStr16(std::to_string(*it)));
84 TELEPHONY_LOGI("subCallId_:%{public}d", *it);
85 }
86 if (!flag) {
87 vec.clear();
88 TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId);
89 }
90 return vec;
91 }
92
GetCallIdListForConference(int32_t callId)93 std::vector<std::u16string> ConferenceBase::GetCallIdListForConference(int32_t callId)
94 {
95 std::vector<std::u16string> vec;
96 bool flag = false;
97 vec.clear();
98 std::lock_guard<std::mutex> lock(conferenceMutex_);
99 for (auto it = subCallIdSet_.begin(); it != subCallIdSet_.end(); ++it) {
100 if (*it == callId) {
101 flag = true;
102 }
103 vec.push_back(Str8ToStr16(std::to_string(*it)));
104 TELEPHONY_LOGI("subCallId_:%{public}d", *it);
105 }
106 if (mainCallId_ == callId) {
107 flag = true;
108 }
109 vec.push_back(Str8ToStr16(std::to_string(mainCallId_)));
110 if (!flag) {
111 vec.clear();
112 TELEPHONY_LOGW("the call is not in the conference, callId:%{public}d", callId);
113 }
114 return vec;
115 }
116 } // namespace Telephony
117 } // namespace OHOS
118