15b8fca66Sopenharmony_ci/* 25b8fca66Sopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd. 35b8fca66Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45b8fca66Sopenharmony_ci * you may not use this file except in compliance with the License. 55b8fca66Sopenharmony_ci * You may obtain a copy of the License at 65b8fca66Sopenharmony_ci * 75b8fca66Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85b8fca66Sopenharmony_ci * 95b8fca66Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105b8fca66Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115b8fca66Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125b8fca66Sopenharmony_ci * See the License for the specific language governing permissions and 135b8fca66Sopenharmony_ci * limitations under the License. 145b8fca66Sopenharmony_ci */ 155b8fca66Sopenharmony_ci 165b8fca66Sopenharmony_ci#ifndef TELEPHONY_OBSERVER_CLIENT_H 175b8fca66Sopenharmony_ci#define TELEPHONY_OBSERVER_CLIENT_H 185b8fca66Sopenharmony_ci 195b8fca66Sopenharmony_ci#include <cstdint> 205b8fca66Sopenharmony_ci#include <iremote_object.h> 215b8fca66Sopenharmony_ci#include <singleton.h> 225b8fca66Sopenharmony_ci 235b8fca66Sopenharmony_ci#include "i_telephony_state_notify.h" 245b8fca66Sopenharmony_ci 255b8fca66Sopenharmony_cinamespace OHOS { 265b8fca66Sopenharmony_cinamespace Telephony { 275b8fca66Sopenharmony_ciclass TelephonyObserverClient : public DelayedRefSingleton<TelephonyObserverClient> { 285b8fca66Sopenharmony_ci DECLARE_DELAYED_REF_SINGLETON(TelephonyObserverClient); 295b8fca66Sopenharmony_ci 305b8fca66Sopenharmony_cipublic: 315b8fca66Sopenharmony_ci /** 325b8fca66Sopenharmony_ci * @brief Add state observer. 335b8fca66Sopenharmony_ci * 345b8fca66Sopenharmony_ci * @param telephonyObserver Indicates the TelephonyObserverBroker. 355b8fca66Sopenharmony_ci * @param slotId Indicates the slot identification. 365b8fca66Sopenharmony_ci * @param mask Indicates the event type mask. 375b8fca66Sopenharmony_ci * @param isUpdate Whether to update data immediately. 385b8fca66Sopenharmony_ci * @return Return 0 if add succeed, others if remove failed. 395b8fca66Sopenharmony_ci */ 405b8fca66Sopenharmony_ci int32_t AddStateObserver(const sptr<TelephonyObserverBroker> &telephonyObserver, 415b8fca66Sopenharmony_ci int32_t slotId, uint32_t mask, bool isUpdate); 425b8fca66Sopenharmony_ci 435b8fca66Sopenharmony_ci /** 445b8fca66Sopenharmony_ci * @brief Remove state observer. 455b8fca66Sopenharmony_ci * 465b8fca66Sopenharmony_ci * @param slotId Indicates the slot identification. 475b8fca66Sopenharmony_ci * @param mask Indicates event type mask. 485b8fca66Sopenharmony_ci * @return Return 0 if remove successful, others if remove failed. 495b8fca66Sopenharmony_ci */ 505b8fca66Sopenharmony_ci int32_t RemoveStateObserver(int32_t slotId, uint32_t mask); 515b8fca66Sopenharmony_ci 525b8fca66Sopenharmony_ci /** 535b8fca66Sopenharmony_ci * @brief Get the state registry proxy. 545b8fca66Sopenharmony_ci * 555b8fca66Sopenharmony_ci * @return Return the ITelephonyStateNotify interface. 565b8fca66Sopenharmony_ci */ 575b8fca66Sopenharmony_ci sptr<ITelephonyStateNotify> GetProxy(); 585b8fca66Sopenharmony_ci 595b8fca66Sopenharmony_ciprivate: 605b8fca66Sopenharmony_ci class StateRegistryDeathRecipient : public IRemoteObject::DeathRecipient { 615b8fca66Sopenharmony_ci public: 625b8fca66Sopenharmony_ci explicit StateRegistryDeathRecipient(TelephonyObserverClient &client) : client_(client) {} 635b8fca66Sopenharmony_ci ~StateRegistryDeathRecipient() override = default; 645b8fca66Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote) override 655b8fca66Sopenharmony_ci { 665b8fca66Sopenharmony_ci client_.OnRemoteDied(remote); 675b8fca66Sopenharmony_ci } 685b8fca66Sopenharmony_ci 695b8fca66Sopenharmony_ci private: 705b8fca66Sopenharmony_ci TelephonyObserverClient &client_; 715b8fca66Sopenharmony_ci }; 725b8fca66Sopenharmony_ci 735b8fca66Sopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote); 745b8fca66Sopenharmony_ci 755b8fca66Sopenharmony_ciprivate: 765b8fca66Sopenharmony_ci std::mutex mutexProxy_; 775b8fca66Sopenharmony_ci sptr<ITelephonyStateNotify> proxy_ {nullptr}; 785b8fca66Sopenharmony_ci sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr}; 795b8fca66Sopenharmony_ci}; 805b8fca66Sopenharmony_ci} // namespace Telephony 815b8fca66Sopenharmony_ci} // namespace OHOS 825b8fca66Sopenharmony_ci#endif // TELEPHONY_OBSERVER_CLIENT_H 83