• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 DISTRIBUTED_OBJECTSTORE_H
17 #define DISTRIBUTED_OBJECTSTORE_H
18 #include <string>
19 
20 #include "distributed_object.h"
21 
22 namespace OHOS::ObjectStore {
23 class StatusNotifier {
24 public:
25     virtual void OnChanged(
26         const std::string &sessionId, const std::string &networkId, const std::string &onlineStatus) = 0;
27 };
28 class ProgressNotifier {
29 public:
30     virtual void OnChanged(const std::string &sessionId, int32_t progress) = 0;
31 };
32 class DistributedObjectStore {
33 public:
~DistributedObjectStore()34     virtual ~DistributedObjectStore(){};
35 
36     /**
37      * @brief Get the instance to handle the object, such as create the object.
38      *
39      * @param bundleName Indicates the bundleName.
40      *
41      * @return Returns the pointer to the DistributedObjectStore class.
42      */
43     static DistributedObjectStore *GetInstance(const std::string &bundleName = "");
44 
45     /**
46      * @brief Create a object according to the sessionId.
47      *
48      * @param sessionId Indicates the sessionId.
49      *
50      * @return Returns the pointer to the DistributedObject class.
51      */
52     virtual DistributedObject *CreateObject(const std::string &sessionId) = 0;
53 
54     /**
55      * @brief Create a object according to the sessionId.
56      *
57      * @param sessionId Indicates the sessionId.
58      * @param status Indicates whether the distributed object is created successfully,
59      * 0 means success, other means fail.
60      *
61      * @return Returns the pointer to the DistributedObject class.
62      */
63     virtual DistributedObject *CreateObject(const std::string &sessionId, uint32_t &status) = 0;
64 
65     /**
66      * @brief Get the double pointer to the object.
67      *
68      * @param sessionId Indicates the sessionId.
69      * @param object Indicates the double pointer to the object.
70      *
71      * @return Returns 0 for success, others for failure.
72      */
73     virtual uint32_t Get(const std::string &sessionId, DistributedObject **object) = 0;
74 
75     /**
76      * @brief Delete the object according to the sessionId.
77      *
78      * @param sessionId Indicates the sessionId.
79      *
80      * @return Returns 0 for success, others for failure.
81      */
82     virtual uint32_t DeleteObject(const std::string &sessionId) = 0;
83 
84     /**
85      * @brief Set listening for data changes.
86      *
87      * @param object Indicates the pointer to the DistributedObject class.
88      * @param objectWatcher Indicates callback function for data changes.
89      *
90      * @return Returns 0 for success, others for failure.
91      */
92     virtual uint32_t Watch(DistributedObject *object, std::shared_ptr<ObjectWatcher> objectWatcher) = 0;
93 
94     /**
95      * @brief Undo listening for data changes.
96      *
97      * @param object Indicates the pointer to the DistributedObject class.
98      *
99      * @return Returns the pointer to the DistributedObject class.
100      */
101     virtual uint32_t UnWatch(DistributedObject *object) = 0;
102 
103     /**
104      * @brief Set listening for device online and offline .
105      *
106      * @param notifier Indicates callback function for device online ond offline.
107      *
108      * @return Returns 0 for success, others for failure.
109      */
110     virtual uint32_t SetStatusNotifier(std::shared_ptr<StatusNotifier> notifier) = 0;
111 
112     /**
113      * @brief Notify the status of the local device from the cached callback function according to the sessionId.
114      *
115      * @param sessionId Indicates the sessionId.
116      *
117      */
118     virtual void NotifyCachedStatus(const std::string &sessionId) = 0;
119 
120     /**
121      * @brief Set listening for progress.
122      *
123      * @param notifier Indicates callback function for progress.
124      *
125      * @return Returns 0 for success, others for failure.
126      */
127     virtual uint32_t SetProgressNotifier(std::shared_ptr<ProgressNotifier> notifier) = 0;
128 
129     /**
130      * @brief Notify the status of the progress from the cached callback function according to the sessionId.
131      *
132      * @param sessionId Indicates the sessionId.
133      *
134      */
135     virtual void NotifyProgressStatus(const std::string &sessionId) = 0;
136 };
137 } // namespace OHOS::ObjectStore
138 
139 #endif // DISTRIBUTED_OBJECTSTORE_H
140