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_INTERFACE_H
17 #define OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INTERFACE_H
18 
19 #include <vector>
20 
21 #include <ipc_types.h>
22 #include <iremote_broker.h>
23 
24 #include "data_ability_observer_interface.h"
25 #include "dataobs_mgr_errors.h"
26 #include "uri.h"
27 
28 namespace OHOS {
29 namespace AAFwk {
30 using Uri = OHOS::Uri;
31 constexpr const char* DATAOBS_MANAGER_SERVICE_NAME = "DataObsMgrService";
32 /**
33  * @class IDataObsMgr
34  * IDataObsMgr interface is used to access dataobs manager services.
35  */
36 class IDataObsMgr : public OHOS::IRemoteBroker {
37 public:
38     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.DataObsMgr")
39 
40     enum {
41         TRANS_HEAD,
42         REGISTER_OBSERVER = TRANS_HEAD,
43         UNREGISTER_OBSERVER,
44         NOTIFY_CHANGE,
45         REGISTER_OBSERVER_EXT,
46         UNREGISTER_OBSERVER_EXT,
47         UNREGISTER_OBSERVER_ALL_EXT,
48         NOTIFY_CHANGE_EXT,
49         TRANS_BUTT,
50     };
51     /**
52      * Registers an observer to DataObsMgr specified by the given Uri.
53      *
54      * @param uri, Indicates the path of the data to operate.
55      * @param dataObserver, Indicates the IDataAbilityObserver object.
56      *
57      * @return Returns ERR_OK on success, others on failure.
58      */
59     virtual int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) = 0;
60 
61     /**
62      * Deregisters an observer used for DataObsMgr specified by the given Uri.
63      *
64      * @param uri, Indicates the path of the data to operate.
65      * @param dataObserver, Indicates the IDataAbilityObserver object.
66      *
67      * @return Returns ERR_OK on success, others on failure.
68      */
69     virtual int UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) = 0;
70 
71     /**
72      * Notifies the registered observers of a change to the data resource specified by Uri.
73      *
74      * @param uri, Indicates the path of the data to operate.
75      *
76      * @return Returns ERR_OK on success, others on failure.
77      */
78     virtual int NotifyChange(const Uri &uri) = 0;
79 
80     /**
81      * Registers an observer to DataObsMgr specified by the given Uri.
82      *
83      * @param uri, Indicates the path of the data to operate.
84      * @param dataObserver, Indicates the IDataAbilityObserver object.
85      * @param isDescendants, Indicates the Whether to note the change of descendants.
86      *
87      * @return Returns SUCCESS on success, others on failure.
88      */
89     virtual Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, bool isDescendants) = 0;
90 
91     /**
92      * Deregisters an observer used for DataObsMgr specified by the given Uri.
93      *
94      * @param uri, Indicates the path of the data to operate.
95      * @param dataObserver, Indicates the IDataAbilityObserver object.
96      *
97      * @return Returns SUCCESS on success, others on failure.
98      */
99     virtual Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) = 0;
100 
101     /**
102      * Deregisters dataObserver used for DataObsMgr specified
103      *
104      * @param dataObserver, Indicates the IDataAbilityObserver object.
105      *
106      * @return Returns SUCCESS on success, others on failure.
107      */
108     virtual Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver) = 0;
109 
110     /**
111      * Notifies the registered observers of a change to the data resource specified by Uris.
112      *
113      * @param changeInfo Indicates the info of the data to operate.
114      *
115      * @return Returns SUCCESS on success, others on failure.
116      */
117     virtual Status NotifyChangeExt(const ChangeInfo &changeInfo) = 0;
118 };
119 }  // namespace AAFwk
120 }  // namespace OHOS
121 #endif  // OHOS_ABILITY_RUNTIME_DATAOBS_MGR_INTERFACE_H
122