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