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 TELEPHONY_OBSERVER_CLIENT_H 17 #define TELEPHONY_OBSERVER_CLIENT_H 18 19 #include <cstdint> 20 #include <iremote_object.h> 21 #include <singleton.h> 22 23 #include "i_telephony_state_notify.h" 24 25 namespace OHOS { 26 namespace Telephony { 27 class TelephonyObserverClient : public DelayedRefSingleton<TelephonyObserverClient> { 28 DECLARE_DELAYED_REF_SINGLETON(TelephonyObserverClient); 29 30 public: 31 int32_t AddStateObserver(const sptr<TelephonyObserverBroker> &telephonyObserver, 32 int32_t slotId, uint32_t mask, bool isUpdate); 33 int32_t RemoveStateObserver(int32_t slotId, uint32_t mask); 34 sptr<ITelephonyStateNotify> GetProxy(); 35 36 private: 37 class StateRegistryDeathRecipient : public IRemoteObject::DeathRecipient { 38 public: StateRegistryDeathRecipient(TelephonyObserverClient & client)39 explicit StateRegistryDeathRecipient(TelephonyObserverClient &client) : client_(client) {} 40 ~StateRegistryDeathRecipient() override = default; OnRemoteDied(const wptr<IRemoteObject> & remote)41 void OnRemoteDied(const wptr<IRemoteObject> &remote) override 42 { 43 client_.OnRemoteDied(remote); 44 } 45 46 private: 47 TelephonyObserverClient &client_; 48 }; 49 50 void OnRemoteDied(const wptr<IRemoteObject> &remote); 51 52 private: 53 std::mutex mutexProxy_; 54 sptr<ITelephonyStateNotify> proxy_ {nullptr}; 55 sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 56 }; 57 } // namespace Telephony 58 } // namespace OHOS 59 #endif // TELEPHONY_OBSERVER_CLIENT_H 60