1 /* 2 * Copyright (C) 2021-2022 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 OHOS_RADIO_PROTOCOL_CONTROLLER_H 17 #define OHOS_RADIO_PROTOCOL_CONTROLLER_H 18 19 #include <condition_variable> 20 #include <ffrt.h> 21 #include <mutex> 22 23 #include "i_tel_ril_manager.h" 24 #include "sim_constant.h" 25 #include "tel_event_handler.h" 26 27 namespace OHOS { 28 namespace Telephony { 29 class RadioProtocolController : public TelEventHandler { 30 public: 31 explicit RadioProtocolController(std::weak_ptr<Telephony::ITelRilManager> telRilManager); 32 virtual ~RadioProtocolController() = default; 33 34 void Init(); 35 int32_t GetRadioProtocolTech(int32_t slotId); 36 int32_t GetRadioProtocolModemId(int32_t slotId); 37 void GetRadioProtocol(int32_t slotId); 38 bool SetRadioProtocol(int32_t slotId); 39 void UnRegisterEvents(); 40 void RadioProtocolControllerWait(); 41 bool RadioProtocolControllerPoll(); 42 bool SetActiveSimToRil(int32_t slotId, int32_t type, int32_t enable); 43 int32_t GetActiveSimToRilResult(); 44 45 public: 46 static ffrt::mutex ctx_; 47 static ffrt::condition_variable cv_; 48 49 private: 50 void InitMemberFunc(); 51 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 52 void ProcessGetRadioProtocol(const AppExecFwk::InnerEvent::Pointer &event); 53 void ProcessCheckRadioProtocol(const AppExecFwk::InnerEvent::Pointer &event); 54 void ProcessUpdateRadioProtocol(const AppExecFwk::InnerEvent::Pointer &event); 55 void ProcessRadioProtocolNotify(const AppExecFwk::InnerEvent::Pointer &event); 56 void ProcessSetRadioProtocolComplete(const AppExecFwk::InnerEvent::Pointer &event); 57 void ProcessSetRadioProtocolTimeout(const AppExecFwk::InnerEvent::Pointer &event); 58 void ExecuteCheckCommunication(); 59 void ExecuteUpdateCommunication(); 60 void ExecuteCompleteCommunication(); 61 void ResetNextCommunicationSlotCount(); 62 void BuildRadioProtocolForCommunication(RadioProtocolPhase phase, RadioProtocolStatus status); 63 void SendRadioProtocolEvent(std::vector<RadioProtocol> radioProtocol, uint32_t eventId); 64 void UpdateRadioProtocol(std::shared_ptr<RadioProtocol> radioProtocol); 65 void CleanUpCommunication(); 66 void ProcessCommunicationResponse(bool result); 67 bool ProcessResponseInfoOfEvent(const AppExecFwk::InnerEvent::Pointer &event); 68 void ProcessActiveSimToRilResponse(const AppExecFwk::InnerEvent::Pointer &event); 69 void ProcessActiveSimTimeOutDone(const AppExecFwk::InnerEvent::Pointer &event); 70 void RadioProtocolControllerContinue(); 71 72 private: 73 using ProcessFunc = std::function<void(const AppExecFwk::InnerEvent::Pointer &event)>; 74 std::weak_ptr<Telephony::ITelRilManager> telRilManager_; 75 std::map<int32_t, ProcessFunc> memberFuncMap_; 76 std::vector<RadioProtocol> radioProtocol_; 77 std::vector<RadioProtocol> oldRadioProtocol_; 78 std::vector<RadioProtocol> newRadioProtocol_; 79 int32_t slotCount_ = 0; 80 int32_t sessionId_ = 0; 81 int32_t communicatingSlotCount_ = 0; 82 bool communicationFailed_ = false; 83 bool isCommunicating_ = false; 84 bool communicationResponseResult_ = false; 85 ffrt::mutex radioProtocolMutex_; 86 ffrt::condition_variable radioProtocolCv_; 87 bool responseReady_ = false; 88 int32_t activeResponse_ = 0; 89 }; 90 } // namespace Telephony 91 } // namespace OHOS 92 #endif // OHOS_RADIO_PROTOCOL_CONTROLLER_H 93