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#ifndef CALL_OBJECT_MANAGER_H
17#define CALL_OBJECT_MANAGER_H
18
19#include <condition_variable>
20#include <cstdio>
21#include <cstdlib>
22#include <list>
23#include <memory>
24#include <mutex>
25
26#include "refbase.h"
27
28#include "call_base.h"
29#include "common_type.h"
30#include "call_manager_inner_type.h"
31
32namespace OHOS {
33namespace Telephony {
34class CallObjectManager {
35public:
36    CallObjectManager();
37    virtual ~CallObjectManager();
38
39    static int32_t AddOneCallObject(sptr<CallBase> &call);
40    static void DelayedDisconnectCallConnectAbility();
41    static int32_t DeleteOneCallObject(int32_t callId);
42    static void DeleteOneCallObject(sptr<CallBase> &call);
43    static sptr<CallBase> GetOneCallObject(int32_t callId);
44    static sptr<CallBase> GetOneCallObject(std::string &phoneNumber);
45    static sptr<CallBase> GetOneCallObjectByIndex(int32_t index);
46    static sptr<CallBase> GetOneCallObjectByIndexAndSlotId(int32_t index, int32_t slotId);
47    static sptr<CallBase> GetOneCallObjectByVoipCallId(std::string voipCallId, std::string bundleName, int32_t uid);
48    static void UpdateOneCallObjectByCallId(int32_t callId, TelCallState nextCallState);
49    static int32_t HasNewCall();
50    static int32_t IsNewCallAllowedCreate(bool &enabled);
51    static int32_t GetCurrentCallNum();
52    static int32_t GetCarrierCallList(std::list<int32_t> &list);
53    static int32_t GetVoipCallNum();
54    static int32_t GetVoipCallList(std::list<int32_t> &list);
55    static bool HasRingingMaximum();
56    static bool HasDialingMaximum();
57    static int32_t HasEmergencyCall(bool &enabled);
58    static int32_t GetNewCallId();
59    static bool IsCallExist(int32_t callId);
60    static bool IsCallExist(std::string &phoneNumber);
61    static bool HasCallExist();
62    static int32_t HasRingingCall(bool &hasRingingCall);
63    static int32_t HasHoldCall(bool &hasHoldCall);
64    static TelCallState GetCallState(int32_t callId);
65    static sptr<CallBase> GetOneCallObject(CallRunningState callState);
66    static bool IsCallExist(CallType type, TelCallState callState);
67    static bool IsCallExist(TelCallState callState);
68    static bool IsCallExist(TelCallState callState, int32_t &callId);
69    static bool IsConferenceCallExist(TelConferenceState state, int32_t &callId);
70    static int32_t GetCallNum(TelCallState callState, bool isIncludeVoipCall = true);
71    static std::string GetCallNumber(TelCallState callState, bool isIncludeVoipCall = true);
72    static std::vector<CallAttributeInfo> GetCallInfoList(int32_t slotId);
73    static sptr<CallBase> GetForegroundCall(bool isIncludeVoipCall = true);
74    static sptr<CallBase> GetForegroundLiveCall();
75    static std::vector<CallAttributeInfo> GetAllCallInfoList();
76    int32_t DealFailDial(sptr<CallBase> call);
77    static bool HasVideoCall();
78    static std::list<sptr<CallBase>> GetAllCallList();
79    static bool HasCellularCallExist();
80    static bool HasVoipCallExist();
81    static bool HasIncomingCallCrsType();
82    static CellularCallInfo GetDialCallInfo();
83    static bool HasSatelliteCallExist();
84    static int32_t GetSatelliteCallList(std::list<int32_t> &list);
85    static int32_t GetCallNumByRunningState(CallRunningState callState);
86
87protected:
88    static std::condition_variable cv_;
89    static bool isFirstDialCallAdded_;
90    static bool needWaitHold_;
91    static CellularCallInfo dialCallInfo_;
92
93private:
94    static std::list<sptr<CallBase>> callObjectPtrList_;
95    static std::mutex listMutex_;
96    static int32_t callId_;
97};
98} // namespace Telephony
99} // namespace OHOS
100
101#endif // CALL_OBJECT_MANAGER_H
102