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 HFP_AG_SYSTEM_EVENT_PROCESS_H
17 #define HFP_AG_SYSTEM_EVENT_PROCESS_H
18 
19 #include <string>
20 
21 #include "hfp_ag_message.h"
22 #include "hfp_ag_profile.h"
23 #include "hfp_ag_system_interface.h"
24 
25 namespace OHOS {
26 namespace bluetooth {
27 /**
28  * @brief This class provides a set of methods that is used to process system event.
29  */
30 class HfpAgSystemEventProcesser {
31 public:
32     /**
33      * @brief Construct a new HfpAgSystemEventProcesser object.
34      *
35      * @param profile AG profile instance.
36      * @param address Remote device address.
37      */
38     HfpAgSystemEventProcesser(HfpAgProfile &profile, const std::string &address);
39 
40     /**
41      * @brief Destroy the HfpAgSystemEventProcesser object.
42      */
43     ~HfpAgSystemEventProcesser() = default;
44 
45     /**
46      * @brief Process system event.
47      *
48      * @param event The system event.
49      */
50     void ExecuteEventProcess(const HfpAgMessage &event);
51 
52     /**
53      * @brief Start the system event processor.
54      */
55     static void Start();
56 
57     /**
58      * @brief Stop the system event processor.
59      */
60     static void Stop();
61 
62     /**
63      * @brief Set the audio actice device.
64      *
65      * @param audioActive The address of the bluetooth device.
66      */
67     static void SetAudioActive(const std::string &audioActive);
68 
69 private:
70     /**
71      * @brief Process the event of answering call.
72      */
73     void ProcessAnswerCallEvent() const;
74 
75     /**
76      * @brief Process the event of hanging up call.
77      */
78     void ProcessHangupCallEvent() const;
79 
80     /**
81      * @brief Process the event of rejecting call.
82      */
83     void ProcessRejectCallEvent();
84 
85     /**
86      * @briefProcess the event of the hf volume changed.
87      *
88      * @param type The volume type.
89      * @param volume The volume valume.
90      */
91     void ProcessHfVolumeChangedEvent(int type, int volume) const;
92 
93     /**
94      * @brief Process the event of dialing out call.
95      *
96      * @param number The number of the call.
97      */
98     void ProcessDialOutCallEvent(const std::string &number, int dialType);
99 
100     /**
101      * @brief Process the event of sending the DTMF.
102      *
103      * @param dtmf The code of the DTMF.
104      */
105     void ProcessSendDtmfEvent(int dtmf) const;
106 
107     /**
108      * @brief Process the event of noise reduction.
109      *
110      * @param flag Enable/disable flag.
111      */
112     void ProcessNoiseReductionEvent(int flag) const;
113 
114     /**
115      * @brief Process the event of the wide band speech.
116      *
117      * @param codec The code of the wide band speech.
118      */
119     void ProcessWideBandSpeechEvent(int codec) const;
120 
121     /**
122      * @brief Process the event of holding the call.
123      *
124      * @param chld The value of the CHLD command.
125      */
126     void ProcessHoldCallEvent(int chld) const;
127 
128     /**
129      * @brief Get the Subscriber Number of the phone.
130      */
131     void GetSubscriberNumber() const;
132 
133     /**
134      * @brief Get the Ag indicator.
135      */
136     void GetAgIndicator();
137 
138     /**
139      * @brief Get the network operator of the phone.
140      */
141     void GetNetworkOperator() const;
142 
143     /**
144      * @brief Get the current calls list.
145      */
146     void GetCurrentCalls() const;
147 
148     /**
149      * @brief Process the event of the AT unknown command.
150      *
151      * @param atString The string of the command.
152      */
153     void ProcessAtUnknownEvent(const std::string &atString) const;
154 
155     /**
156      * @brief Process the event of the key pressed.
157      */
158     void ProcessKeyPressedEvent() const;
159 
160     /**
161      * @brief Process the event of the AT bind.
162      *
163      * @param atString The string of the command.
164      */
165     void ProcessATBindEvent(const std::string &atString) const;
166 
167     /**
168      * @brief Process the event of sinding the hf indicator.
169      *
170      * @param indId The id of the indicator.
171      * @param indValue The value of the indicator.
172      */
173     void SendHfIndicator(int indId, int indValue) const;
174 
175     /**
176      * @brief Process the event of the AT BIA.
177      *
178      * @param data The BIA event.
179      */
180     void ProcessAtBiaEvent(const HfpAgMessage &event);
181 
182     /**
183      * @brief process the event of querying AG indicator.
184      */
185     void QueryAgIndicator();
186 
187     /**
188      * @brief The status of the voice recognition change.
189      *
190      * @param status The status of the voice recognition.
191      */
192     void VoiceRecognitionStateChanged(int status);
193 
194     /**
195      * @brief process the event of update AG indicator.
196      */
197     void UpdataAgIndicator();
198 
199     /**
200      * @brief get voice number.
201      */
202     void GetVoiceNumber();
203 
204     /**
205      * @brief get response hold state.
206      */
207     void GetResponseHoldState(std::string address);
208 
209     void SetResponseHold(std::string address, int btrh);
210 
211     /**
212      * @brief get response hold state.
213      */
214     void HandlePhoneStateMock(std::string number, int state, int type);
215 
216     /**
217      * @brief Get the control other modules event type.
218      *
219      * @param type Event type number.
220      * @return Returns the event type string name.
221      */
222     static std::string GetEventType(int type);
223 
224     // The quote of the HfpAgSystemInterface class.
225     HfpAgSystemInterface &systemInterface_ {HfpAgSystemInterface::GetInstance()};
226     // The pointer of the HfpAgProfile.
227     HfpAgProfile& profile_;
228     // The address of the bluetooth device.
229     std::string address_ {""};
230 };
231 }  // namespace bluetooth
232 }  // namespace OHOS
233 #endif // HFP_AG_SYSTEM_EVENT_PROCESS_H