• 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 DistributedObjectStore {
29 public:
~DistributedObjectStore()30     virtual ~DistributedObjectStore(){};
31 
32     /**
33      * @brief Get the instance to handle the object, such as create the object.
34      *
35      * @param bundleName Indicates the bundleName.
36      *
37      * @return Returns the pointer to the DistributedObjectStore class.
38      */
39     static DistributedObjectStore *GetInstance(const std::string &bundleName = "");
40 
41     /**
42      * @brief Create a object according to the sessionId.
43      *
44      * @param sessionId Indicates the sessionId.
45      *
46      * @return Returns the pointer to the DistributedObject class.
47      */
48     virtual DistributedObject *CreateObject(const std::string &sessionId) = 0;
49 
50     /**
51      * @brief Create a object according to the sessionId.
52      *
53      * @param sessionId Indicates the sessionId.
54      * @param status Indicates whether the distributed object is created successfully,
55      * 0 means success, other means fail.
56      *
57      * @return Returns the pointer to the DistributedObject class.
58      */
59     virtual DistributedObject *CreateObject(const std::string &sessionId, uint32_t &status) = 0;
60 
61     /**
62      * @brief Get the double pointer to the object.
63      *
64      * @param sessionId Indicates the sessionId.
65      * @param object Indicates the double pointer to the object.
66      *
67      * @return Returns 0 for success, others for failure.
68      */
69     virtual uint32_t Get(const std::string &sessionId, DistributedObject **object) = 0;
70 
71     /**
72      * @brief Delete the object according to the sessionId.
73      *
74      * @param sessionId Indicates the sessionId.
75      *
76      * @return Returns 0 for success, others for failure.
77      */
78     virtual uint32_t DeleteObject(const std::string &sessionId) = 0;
79 
80     /**
81      * @brief Set listening for data changes.
82      *
83      * @param object Indicates the pointer to the DistributedObject class.
84      * @param objectWatcher Indicates callback function for data changes.
85      *
86      * @return Returns 0 for success, others for failure.
87      */
88     virtual uint32_t Watch(DistributedObject *object, std::shared_ptr<ObjectWatcher> objectWatcher) = 0;
89 
90     /**
91      * @brief Undo listening for data changes.
92      *
93      * @param object Indicates the pointer to the DistributedObject class.
94      *
95      * @return Returns the pointer to the DistributedObject class.
96      */
97     virtual uint32_t UnWatch(DistributedObject *object) = 0;
98 
99     /**
100      * @brief Set listening for device online and offline .
101      *
102      * @param notifier Indicates callback function for device online ond offline.
103      *
104      * @return Returns 0 for success, others for failure.
105      */
106     virtual uint32_t SetStatusNotifier(std::shared_ptr<StatusNotifier> notifier) = 0;
107 
108     /**
109      * @brief Notify the status of the local device from the cached callback function according to the sessionId.
110      *
111      * @param sessionId Indicates the sessionId.
112      *
113      */
114     virtual void NotifyCachedStatus(const std::string &sessionId) = 0;
115 };
116 } // namespace OHOS::ObjectStore
117 
118 #endif // DISTRIBUTED_OBJECTSTORE_H
119