1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#ifndef OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H 17eace7efcSopenharmony_ci#define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H 18eace7efcSopenharmony_ci 19eace7efcSopenharmony_ci#include <atomic> 20eace7efcSopenharmony_ci#include <list> 21eace7efcSopenharmony_ci#include <map> 22eace7efcSopenharmony_ci#include <memory> 23eace7efcSopenharmony_ci#include <mutex> 24eace7efcSopenharmony_ci#include <string> 25eace7efcSopenharmony_ci#include "cpp/mutex.h" 26eace7efcSopenharmony_ci 27eace7efcSopenharmony_ci#include "data_ability_observer_interface.h" 28eace7efcSopenharmony_ci 29eace7efcSopenharmony_cinamespace OHOS { 30eace7efcSopenharmony_cinamespace AAFwk { 31eace7efcSopenharmony_ciclass DataObsMgrInner : public std::enable_shared_from_this<DataObsMgrInner> { 32eace7efcSopenharmony_cipublic: 33eace7efcSopenharmony_ci using ObsMapType = std::map<std::string, std::list<sptr<IDataAbilityObserver>>>; 34eace7efcSopenharmony_ci using ObsRecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>; 35eace7efcSopenharmony_ci 36eace7efcSopenharmony_ci DataObsMgrInner(); 37eace7efcSopenharmony_ci virtual ~DataObsMgrInner(); 38eace7efcSopenharmony_ci 39eace7efcSopenharmony_ci int HandleRegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver); 40eace7efcSopenharmony_ci int HandleUnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver); 41eace7efcSopenharmony_ci int HandleNotifyChange(const Uri &uri); 42eace7efcSopenharmony_ci void OnCallBackDied(const wptr<IRemoteObject> &remote); 43eace7efcSopenharmony_ci 44eace7efcSopenharmony_ciprivate: 45eace7efcSopenharmony_ci void AddObsDeathRecipient(sptr<IDataAbilityObserver> dataObserver); 46eace7efcSopenharmony_ci void RemoveObsDeathRecipient(sptr<IRemoteObject> dataObserver); 47eace7efcSopenharmony_ci void RemoveObs(sptr<IRemoteObject> dataObserver); 48eace7efcSopenharmony_ci bool HaveRegistered(sptr<IDataAbilityObserver> dataObserver); 49eace7efcSopenharmony_ci 50eace7efcSopenharmony_ci static constexpr uint32_t OBS_NUM_MAX = 50; 51eace7efcSopenharmony_ci ffrt::mutex innerMutex_; 52eace7efcSopenharmony_ci ObsMapType observers_; 53eace7efcSopenharmony_ci ObsRecipientMapType obsRecipient_; 54eace7efcSopenharmony_ci}; 55eace7efcSopenharmony_ci} // namespace AAFwk 56eace7efcSopenharmony_ci} // namespace OHOS 57eace7efcSopenharmony_ci#endif // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H 58