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 NOTIFICATION_ADVANCED_DATASHAER_OBSERVER_H
17 #define NOTIFICATION_ADVANCED_DATASHAER_OBSERVER_H
18 
19 #include "datashare_helper.h"
20 #include "iremote_broker.h"
21 #include "singleton.h"
22 #include "ans_const_define.h"
23 #include "system_ability_definition.h"
24 #include "uri.h"
25 
26 namespace OHOS {
27 namespace Notification {
28 namespace {
29 
30 } // namespace
31 
32 class AdvancedDatashareObserver : public Singleton<AdvancedDatashareObserver> {
33     DECLARE_SINGLETON(AdvancedDatashareObserver);
34 public:
35     /**
36      * Registers an observer to DataObsMgr specified by the given Uri.
37      *
38      * @param uri, Indicates the path of the data to operate.
39      * @param dataObserver, Indicates the IDataAbilityObserver object.
40      */
41     void RegisterSettingsObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
42 
43     /**
44      * Deregisters an observer used for DataObsMgr specified by the given Uri.
45      *
46      * @param uri, Indicates the path of the data to operate.
47      * @param dataObserver, Indicates the IDataAbilityObserver object.
48      */
49     void UnRegisterSettingsObserver(const Uri &uri, const sptr<AAFwk::IDataAbilityObserver> &dataObserver);
50 
51     /**
52      * Notifies the registered observers of a change to the data resource specified by Uri.
53      *
54      * @param uri, Indicates the path of the data to operate.
55      */
56     void NotifyChange(const Uri &uri);
57 
58     bool CheckIfSettingsDataReady();
59 
60 private:
61     std::shared_ptr<DataShare::DataShareHelper> CreateDataShareHelper();
62     static sptr<AdvancedDatashareObserver> instance_;
63     static std::mutex instanceMutex_;
64     bool isDataShareReady_ = false;
65 };
66 } // namespace Notification
67 } // namespace OHOS
68 #endif // NOTIFICATION_ADVANCED_DATASHAER_OBSERVER_H
69