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 "base_connection.h"
17
18 #include "securec.h"
19 #include "standardize_utils.h"
20
21 namespace OHOS {
22 namespace Telephony {
BaseConnection()23 BaseConnection::BaseConnection()
24 {
25 (void)memset_s(&callReportInfo_, sizeof(CallReportInfo), 0, sizeof(callReportInfo_));
26 }
27
SetOrUpdateCallReportInfo(CallReportInfo & callReportInfo)28 void BaseConnection::SetOrUpdateCallReportInfo(CallReportInfo &callReportInfo)
29 {
30 callReportInfo_ = callReportInfo;
31 }
32
GetCallReportInfo()33 CallReportInfo BaseConnection::GetCallReportInfo()
34 {
35 return callReportInfo_;
36 }
37
SetStatus(TelCallState state)38 void BaseConnection::SetStatus(TelCallState state)
39 {
40 callReportInfo_.state = state;
41 }
42
GetStatus() const43 TelCallState BaseConnection::GetStatus() const
44 {
45 return callReportInfo_.state;
46 }
47
IsRingingState() const48 bool BaseConnection::IsRingingState() const
49 {
50 return this->GetStatus() == TelCallState::CALL_STATUS_INCOMING ||
51 this->GetStatus() == TelCallState::CALL_STATUS_WAITING ||
52 this->GetStatus() == TelCallState::CALL_STATUS_ALERTING;
53 }
54
SetFlag(bool flag)55 void BaseConnection::SetFlag(bool flag)
56 {
57 flag_ = flag;
58 }
59
GetFlag() const60 bool BaseConnection::GetFlag() const
61 {
62 return flag_;
63 }
64
SetIndex(int32_t index)65 void BaseConnection::SetIndex(int32_t index)
66 {
67 index_ = index;
68 }
69
GetIndex() const70 int32_t BaseConnection::GetIndex() const
71 {
72 return index_;
73 }
74
SetNumber(const std::string & number)75 void BaseConnection::SetNumber(const std::string &number)
76 {
77 number_ = number;
78 }
79
GetNumber() const80 std::string BaseConnection::GetNumber() const
81 {
82 return number_;
83 }
84
ProcessNextChar(int32_t slotId,char & c)85 PostDialCallState BaseConnection::ProcessNextChar(int32_t slotId, char &c)
86 {
87 if (postDialCalltate_ == PostDialCallState::POST_DIAL_CALL_CANCELED) {
88 return PostDialCallState::POST_DIAL_CALL_CANCELED;
89 }
90 if (postDialCallString_.empty() || postDialCallString_.length() <= static_cast<size_t>(nextPostDialCallCode_)) {
91 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_COMPLETE);
92 return PostDialCallState::POST_DIAL_CALL_COMPLETE;
93 } else {
94 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_STARTED);
95 c = postDialCallString_.at(nextPostDialCallCode_++);
96 ProcessPostDialCallChar(slotId, c);
97 }
98 return postDialCalltate_;
99 }
100
SetPostDialCallState(PostDialCallState s)101 void BaseConnection::SetPostDialCallState(PostDialCallState s)
102 {
103 postDialCalltate_ = s;
104 }
105
UpdateCallNumber(std::string phoneNum)106 void BaseConnection::UpdateCallNumber(std::string phoneNum)
107 {
108 StandardizeUtils standardizeUtils;
109 standardizeUtils.ExtractAddressAndPostDial(phoneNum, phoneNumber_, postDialCallString_);
110 }
111
GetLeftPostDialCallString()112 std::string BaseConnection::GetLeftPostDialCallString()
113 {
114 if (postDialCallString_.empty() || postDialCallString_.length() <= static_cast<size_t>(nextPostDialCallCode_)) {
115 return "";
116 }
117 return postDialCallString_.substr(nextPostDialCallCode_);
118 }
119
ProcessPostDialCallChar(int32_t slotId,char c)120 int32_t BaseConnection::ProcessPostDialCallChar(int32_t slotId, char c)
121 {
122 return TELEPHONY_SUCCESS;
123 }
124 } // namespace Telephony
125 } // namespace OHOS