• 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_OBJECT_H
17 #define DISTRIBUTED_OBJECT_H
18 #include "object_types.h"
19 
20 namespace OHOS::ObjectStore {
21 enum Type : uint8_t {
22     TYPE_STRING = 0,
23     TYPE_BOOLEAN,
24     TYPE_DOUBLE,
25     TYPE_COMPLEX,
26 };
27 class DistributedObject {
28 public:
~DistributedObject()29     virtual ~DistributedObject(){};
30 
31     /**
32      * @brief Put or update the data whose value type is double into the database, which means that the data of
33      * objects in the same sessionId is put or updated.
34      *
35      * @param key Indicates the key of key-value data to put or update.
36      * @param value Indicates the value of key-value data to put or update.
37      *
38      * @return Returns 0 for success, others for failure.
39      */
40     virtual uint32_t PutDouble(const std::string &key, double value) = 0;
41 
42     /**
43      * @brief Put or update the data whose value type is bool into the database, which means that the data of
44      * objects in the same sessionId is put or updated.
45      *
46      * @param key Indicates the key of key-value data to put or update.
47      * @param value Indicates the value of key-value data to put or update.
48      *
49      * @return Returns 0 for success, others for failure.
50      */
51     virtual uint32_t PutBoolean(const std::string &key, bool value) = 0;
52 
53     /**
54      * @brief Put or update the data whose value type is string into the database, which means that the data of
55      * objects in the same sessionId is put or updated.
56      *
57      * @param key Indicates the key of key-value data to put or update.
58      * @param value Indicates the value of key-value data to put or update.
59      *
60      * @return Returns 0 for success, others for failure.
61      */
62     virtual uint32_t PutString(const std::string &key, const std::string &value) = 0;
63 
64     /**
65      * @brief Put or update the data whose value type is bytes stream into the database, which means that the data of
66      * objects in the same sessionId is put or updated.
67      *
68      * @param key Indicates the key of key-value data to put or update.
69      * @param value Indicates the value of key-value data to put or update.
70      *
71      * @return Returns 0 for success, others for failure.
72      */
73     virtual uint32_t PutComplex(const std::string &key, const std::vector<uint8_t> &value) = 0;
74 
75     /**
76      * @brief Get the data whose value type is double from the database according to the key,
77      * which means that the data of objects in the same sessionId is get.
78      *
79      * @param key Indicates the key of key-value data to put or update.
80      * @param value Indicates the value of key-value data to put or update.
81      *
82      * @return Returns 0 for success, others for failure.
83      */
84     virtual uint32_t GetDouble(const std::string &key, double &value) = 0;
85 
86     /**
87      * @brief Get the data whose value type is bool from the database according to the key,
88      * which means that the data of objects in the same sessionId is get.
89      *
90      * @param key Indicates the key of key-value data to get.
91      * @param value Indicates the value of key-value data to get.
92      *
93      * @return Returns 0 for success, others for failure.
94      */
95     virtual uint32_t GetBoolean(const std::string &key, bool &value) = 0;
96 
97     /**
98      * @brief Get the data whose value type is string from the database according to the key,
99      * which means that the data of objects in the same sessionId is get.
100      *
101      * @param key Indicates the key of key-value data to put or update.
102      * @param value Indicates the value of key-value data to put or update.
103      *
104      * @return Returns 0 for success, others for failure.
105      */
106     virtual uint32_t GetString(const std::string &key, std::string &value) = 0;
107 
108     /**
109      * @brief Get the data whose value type is complex from the database according to the key,
110      * which means that the data of objects in the same sessionId is get.
111      *
112      * @param key Indicates the key of key-value data to put or update.
113      * @param value Indicates the value of key-value data to put or update.
114      *
115      * @return Returns 0 for success, others for failure.
116      */
117     virtual uint32_t GetComplex(const std::string &key, std::vector<uint8_t> &value) = 0;
118 
119     /**
120      * @brief Get the value type of key-value data by the key
121      *
122      * @param key Indicates the key of key-value data.
123      * @param value Indicates the value of key-value data.
124      *
125      * @return Returns 0 for success, others for failure.
126      */
127     virtual uint32_t GetType(const std::string &key, Type &type) = 0;
128 
129     /**
130      * @brief Save the data to local device.
131      *
132      * @param deviceId Indicates the device Id.
133      *
134      * @return Returns 0 for success, others for failure.
135      */
136     virtual uint32_t Save(const std::string &deviceId) = 0;
137 
138     /**
139      * @brief Revoke save data.
140      *
141      * @return Returns 0 for success, others for failure.
142      */
143     virtual uint32_t RevokeSave() = 0;
144 
145     /**
146      * @brief Get the sessionId of the object.
147      *
148      * @return Returns sessionId of the object.
149      */
150     virtual std::string &GetSessionId() = 0;
151 
152     /**
153      * @brief Bind Asset.
154      *
155      * @param assetKey Indicates the assetKey key.
156      * @param bindInfo Indicates asset info.
157      *
158      * @return Returns 0 for success, others for failure.
159      */
160     virtual uint32_t BindAssetStore(const std::string &assetKey, AssetBindInfo &bindInfo) = 0;
161 };
162 
163 class ObjectWatcher {
164 public:
165     virtual void OnChanged(const std::string &sessionid, const std::vector<std::string> &changedData) = 0;
166 };
167 } // namespace OHOS::ObjectStore
168 #endif // DISTRIBUTED_OBJECT_H
169