• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_REQUEST_HANDLER_H
17 #define CALL_REQUEST_HANDLER_H
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 
23 #include "event_handler.h"
24 #include "event_runner.h"
25 
26 #include "common_type.h"
27 #include "call_request_process.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 struct AnswerCallPara {
32     int32_t callId;
33     int32_t videoState;
34 };
35 
36 struct RejectCallPara {
37     int32_t callId;
38     bool isSendSms;
39     char content[REJECT_CALL_MSG_MAX_LEN + 1];
40 };
41 
42 struct StartRttPara {
43     int32_t callId;
44     std::u16string msg;
45 };
46 
47 struct CallMediaUpdatePara {
48     int32_t callId;
49     ImsCallMode mode;
50 };
51 
52 struct JoinConferencePara {
53     int32_t callId;
54     std::vector<std::string> numberList;
55 };
56 
57 /**
58  * @ClassName: CallRequestHandler
59  * @Description: inner event-handle mechanism on harmony platform, used by callcontrolmanager
60  * to handle downflowed telephone business, factually act as work thread.
61  */
62 class CallRequestHandler : public AppExecFwk::EventHandler {
63 public:
64     CallRequestHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner);
65     virtual ~CallRequestHandler();
66 
67     void Init();
68     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
69 
70 private:
71     using CallRequestFunc = void (CallRequestHandler::*)(const AppExecFwk::InnerEvent::Pointer &event);
72 
73     void DialCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
74     void AcceptCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
75     void RejectCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
76     void HangUpCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
77     void HoldCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
78     void UnHoldCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
79     void SwitchCallEvent(const AppExecFwk::InnerEvent::Pointer &event);
80     void CombineConferenceEvent(const AppExecFwk::InnerEvent::Pointer &event);
81     void SeparateConferenceEvent(const AppExecFwk::InnerEvent::Pointer &event);
82     void UpdateCallMediaModeEvent(const AppExecFwk::InnerEvent::Pointer &event);
83     void StartRttEvent(const AppExecFwk::InnerEvent::Pointer &event);
84     void StopRttEvent(const AppExecFwk::InnerEvent::Pointer &event);
85     void JoinConferenceEvent(const AppExecFwk::InnerEvent::Pointer &event);
86     std::map<uint32_t, CallRequestFunc> memberFuncMap_;
87     std::unique_ptr<CallRequestProcess> callRequestProcessPtr_;
88 };
89 
90 class CallRequestHandlerService {
91 public:
92     CallRequestHandlerService();
93     ~CallRequestHandlerService();
94     void Start();
95     int32_t DialCall();
96     int32_t AnswerCall(int32_t callId, int32_t videoState);
97     int32_t RejectCall(int32_t callId, bool isSendSms, std::string &content);
98     int32_t HangUpCall(int32_t callId);
99     int32_t HoldCall(int32_t callId);
100     int32_t UnHoldCall(int32_t callId);
101     int32_t SwitchCall(int32_t callId);
102     int32_t CombineConference(int32_t mainCallId);
103     int32_t SeparateConference(int32_t callId);
104     int32_t UpdateImsCallMode(int32_t callId, ImsCallMode mode);
105     int32_t StartRtt(int32_t callId, std::u16string &msg);
106     int32_t StopRtt(int32_t callId);
107     int32_t JoinConference(int32_t callId, std::vector<std::string> &numberList);
108     enum {
109         HANDLER_DIAL_CALL_REQUEST = 0,
110         HANDLER_ANSWER_CALL_REQUEST,
111         HANDLER_REJECT_CALL_REQUEST,
112         HANDLER_HANGUP_CALL_REQUEST,
113         HANDLER_HOLD_CALL_REQUEST,
114         HANDLER_UNHOLD_CALL_REQUEST,
115         HANDLER_SWAP_CALL_REQUEST,
116         HANDLER_COMBINE_CONFERENCE_REQUEST,
117         HANDLER_SEPARATE_CONFERENCE_REQUEST,
118         HANDLER_UPDATE_CALL_MEDIA_MODE_REQUEST,
119         HANDLER_STARTRTT_REQUEST,
120         HANDLER_STOPRTT_REQUEST,
121         HANDLER_INVITE_TO_CONFERENCE,
122     };
123 
124 private:
125     std::shared_ptr<AppExecFwk::EventRunner> eventLoop_;
126     std::shared_ptr<CallRequestHandler> handler_;
127 };
128 } // namespace Telephony
129 } // namespace OHOS
130 #endif // CALL_CONTROL_MANAGER_HANDLER_H
131