• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 TELEPHONY_OBSERVER_IMPL_H
17 #define TELEPHONY_OBSERVER_IMPL_H
18 
19 #include "observer_event_handler.h"
20 #include "telephony_observer.h"
21 #include "telephony_observer_broker.h"
22 #include "telephony_observer_utils.h"
23 #include "telephony_types.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 
28 class TelephonyObserverImpl {
29 public:
30     template<typename T, typename D>
31     inline static bool SendEvent(uint32_t innerEventId, std::unique_ptr<T, D> &object, int64_t delayTime = 0)
32     {
33         auto handler = DelayedSingleton<ObserverEventHandler>::GetInstance();
34         if (handler == nullptr) {
35             TELEPHONY_LOGE("Get handler failed");
36             return false;
37         }
38         return handler->SendEvent(innerEventId, object, delayTime);
39     }
40 
SendEvent(uint32_t innerEventId)41     inline static bool SendEvent(uint32_t innerEventId)
42     {
43         auto handler = DelayedSingleton<ObserverEventHandler>::GetInstance();
44         if (handler == nullptr) {
45             TELEPHONY_LOGE("Get handler failed");
46             return false;
47         }
48         return handler->SendEvent(innerEventId);
49     }
50 
51     static int32_t OnNetworkStateChange(ObserverOptions options, int64_t funcId);
52     static int32_t OffNetworkStateChange(int64_t funcId);
53     static int32_t OffAllNetworkStateChange();
54 
55     static int32_t OnSignalInfoChange(ObserverOptions options, int64_t funcId);
56     static int32_t OffSignalInfoChange(int64_t funcId);
57     static int32_t OffAllSignalInfoChange();
58 
59     static int32_t OnCallStateChange(ObserverOptions options, int64_t funcId);
60     static int32_t OffCallStateChange(int64_t funcId);
61     static int32_t OffAllCallStateChange();
62 
63     static int32_t OnCellularDataConnectionStateChange(ObserverOptions options, int64_t funcId);
64     static int32_t OffCellularDataConnectionStateChange(int64_t funcId);
65     static int32_t OffAllCellularDataConnectionStateChange();
66 
67     static int32_t OnCellularDataFlowChange(ObserverOptions options, int64_t funcId);
68     static int32_t OffCellularDataFlowChange(int64_t funcId);
69     static int32_t OffAllCellularDataFlowChange();
70 
71     static int32_t OnSimStateChange(ObserverOptions options, int64_t funcId);
72     static int32_t OffSimStateChange(int64_t funcId);
73     static int32_t OffAllSimStateChange();
74 
75     static int32_t OnIccAccountInfoChange(ObserverOptions options, int64_t funcId);
76     static int32_t OffIccAccountInfoChange(int64_t funcId);
77     static int32_t OffAllIccAccountInfoChange();
78 };
79 
80 class FfiTelephonyObserver : public TelephonyObserver {
81 public:
82     void OnCallStateUpdated(int32_t slotId, int32_t callState, const std::u16string &phoneNumber) override;
83     void OnSignalInfoUpdated(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec) override;
84     void OnNetworkStateUpdated(int32_t slotId, const sptr<NetworkState> &networkState) override;
85     void OnSimStateUpdated(int32_t slotId, CardType type, SimState state, LockReason reason) override;
86     void OnCellInfoUpdated(int32_t slotId, const std::vector<sptr<CellInformation>> &vec) override;
87     void OnCellularDataConnectStateUpdated(int32_t slotId, int32_t dataState, int32_t networkType) override;
88     void OnCellularDataFlowUpdated(int32_t slotId, int32_t dataFlowType) override;
89     void OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult) override;
90     void OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult) override;
91     void OnIccAccountUpdated() override;
92 };
93 }
94 }
95 
96 #endif