• 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_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H
17 #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H
18 
19 #include <atomic>
20 #include <list>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 #include "cpp/mutex.h"
26 
27 #include "data_ability_observer_interface.h"
28 #include "dataobs_mgr_inner_common.h"
29 
30 namespace OHOS {
31 namespace AAFwk {
32 class DataObsMgrInner : public std::enable_shared_from_this<DataObsMgrInner> {
33 public:
34     using ObsMapType = std::map<std::string, std::list<struct ObserverNode>>;
35     using ObsRecipientMapType = std::map<sptr<IRemoteObject>, sptr<IRemoteObject::DeathRecipient>>;
36 
37     DataObsMgrInner();
38     virtual ~DataObsMgrInner();
39 
40     int HandleRegisterObserver(const Uri &uri, struct ObserverNode observerNode);
41     int HandleUnregisterObserver(const Uri &uri, struct ObserverNode observerNode);
42     int HandleNotifyChange(const Uri &uri, int32_t userId);
43     void OnCallBackDied(const wptr<IRemoteObject> &remote);
44 
45 private:
46     void AddObsDeathRecipient(sptr<IDataAbilityObserver> dataObserver);
47     void RemoveObsDeathRecipient(sptr<IRemoteObject> dataObserver);
48     void RemoveObs(sptr<IRemoteObject> dataObserver);
49     bool HaveRegistered(sptr<IDataAbilityObserver> dataObserver);
50 
51     static constexpr uint32_t OBS_NUM_MAX = 50;
52     static constexpr uint32_t OBS_ALL_NUM_MAX = OBS_NUM_MAX * OBS_NUM_MAX;
53     ffrt::mutex innerMutex_;
54     ObsMapType observers_;
55     ObsRecipientMapType obsRecipient_;
56 };
57 }  // namespace AAFwk
58 }  // namespace OHOS
59 #endif  // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INNER_H
60