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