• 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 OHOS_HRIL_MANAGER_H
17 #define OHOS_HRIL_MANAGER_H
18 
19 #include <list>
20 #include <mutex>
21 #include <unordered_map>
22 
23 #include "hril_call.h"
24 #include "hril_data.h"
25 #include "hril_modem.h"
26 #include "hril_network.h"
27 #include "hril_sim.h"
28 #include "hril_sms.h"
29 #include "hril_timer_callback.h"
30 
31 namespace OHOS {
32 namespace Telephony {
33 typedef enum : int32_t {
34     RIL_REGISTER_IS_NONE = 0,
35     RIL_REGISTER_IS_RUNNING,
36 } RegisterState;
37 
38 class HRilManager : public IHRilReporter {
39 public:
40     HRilManager();
41     virtual ~HRilManager();
42 
43     std::unique_ptr<HRilTimerCallback> timerCallback_ = nullptr;
44     std::unique_ptr<std::thread> eventLoop_ = nullptr;
45 
46     int32_t GetMaxSimSlotCount();
47 
48     virtual int32_t ReportToParent(int32_t requestNum, const HdfSBuf *dataSbuf) override;
49     virtual int32_t NotifyToParent(int32_t requestNum, const HdfSBuf *dataSbuf) override;
50     virtual ReqDataInfo *CreateHRilRequest(int32_t serial, int32_t slotId, int32_t request) override;
51     virtual void ReleaseHRilRequest(int32_t request, ReqDataInfo *requestInfo) override;
52 
53     void RegisterCallFuncs(int32_t slotId, const HRilCallReq *callFuncs);
54     void RegisterDataFuncs(int32_t slotId, const HRilDataReq *dataFuncs);
55     void RegisterModemFuncs(int32_t slotId, const HRilModemReq *modemFuncs);
56     void RegisterNetworkFuncs(int32_t slotId, const HRilNetworkReq *networkFuncs);
57     void RegisterSimFuncs(int32_t slotId, const HRilSimReq *simFuncs);
58     void RegisterSmsFuncs(int32_t slotId, const HRilSmsReq *smsFuncs);
59 
60     int32_t Dispatch(int32_t slotId, int32_t cmd, struct HdfSBuf *data);
61 
62     void RegisterModulesNotifyCallback(const HdfRemoteService *serviceCallbackInd);
63 
64     void RegisterModulesResponseCallback(const HdfRemoteService *serviceCallbackInd);
65 
66     void OnCallReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
67     void OnDataReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
68     void OnModemReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
69     void OnNetworkReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
70     void OnSimReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
71     void OnSmsReport(int32_t slotId, const ReportInfo *reportInfo, const uint8_t *response, size_t responseLen);
72 
73 private:
74     template<typename T>
75     void OnReport(std::vector<std::unique_ptr<T>> &subModules, int32_t slotId, const ReportInfo *reportInfo,
76         const uint8_t *response, size_t responseLen);
77 
78     const int32_t hrilSimSlotCount_;
79     std::vector<std::unique_ptr<HRilCall>> hrilCall_;
80     std::vector<std::unique_ptr<HRilModem>> hrilModem_;
81     std::vector<std::unique_ptr<HRilNetwork>> hrilNetwork_;
82     std::vector<std::unique_ptr<HRilSim>> hrilSim_;
83     std::vector<std::unique_ptr<HRilSms>> hrilSms_;
84     std::vector<std::unique_ptr<HRilData>> hrilData_;
85 
86     const struct HdfRemoteService *serviceCallback_ = nullptr;
87     const struct HdfRemoteService *serviceCallbackNotify_ = nullptr;
88     std::unordered_map<int32_t, std::list<ReqDataInfo *>> requestList_;
89     std::mutex requestListLock_;
90 };
91 
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95 
96 int32_t GetSimSlotCount(void);
97 int32_t DispatchRequest(int32_t cmd, struct HdfSBuf *data);
98 void HRilRegOps(const HRilOps *hrilOps);
99 void OnCallReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
100 void OnDataReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
101 void OnModemReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
102 void OnNetworkReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
103 void OnSimReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
104 void OnSmsReport(int32_t slotId, struct ReportInfo reportInfo, const uint8_t *response, size_t responseLen);
105 void OnTimerCallback(HRilCallbackFun func, uint8_t *param, const struct timeval *tv);
106 
107 #ifdef __cplusplus
108 }
109 #endif
110 } // namespace Telephony
111 } // namespace OHOS
112 #endif // OHOS_RIL_IMPL_H