• 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 OBJECT_STORAGE_ENGINE_H
17 #define OBJECT_STORAGE_ENGINE_H
18 
19 #include <cstdint>
20 #include <map>
21 #include <vector>
22 
23 #include "kv_store_observer.h"
24 #include "watcher.h"
25 
26 namespace OHOS::ObjectStore {
27 using Key = std::vector<uint8_t>;
28 using Value = std::vector<uint8_t>;
29 using Field = std::vector<uint8_t>;
30 
31 class TableWatcher : public Watcher {
32 public:
TableWatcher(const std::string & sessionId)33     TableWatcher(const std::string &sessionId) : Watcher(sessionId)
34     {
35     }
36     virtual void OnChanged(const std::string &sessionid, const std::vector<std::string> &changedData) = 0;
37 };
38 
39 class StatusWatcher {
40 public:
41     virtual void OnChanged(
42         const std::string &sessionId, const std::string &networkId, const std::string &onlineStatus) = 0;
43 };
44 
45 class ObjectStorageEngine {
46 public:
47     ObjectStorageEngine(const ObjectStorageEngine &) = delete;
48     ObjectStorageEngine &operator=(const ObjectStorageEngine &) = delete;
49     ObjectStorageEngine(ObjectStorageEngine &&) = delete;
50     ObjectStorageEngine &operator=(ObjectStorageEngine &&) = delete;
51     ObjectStorageEngine() = default;
52     virtual ~ObjectStorageEngine() = default;
53     virtual uint32_t Open(const std::string &bundleName) = 0;
54     virtual uint32_t Close() = 0;
55     virtual uint32_t DeleteTable(const std::string &key) = 0;
56     virtual uint32_t CreateTable(const std::string &key) = 0;
57     virtual uint32_t GetTable(const std::string &key, std::map<std::string, Value> &result) = 0;
58     virtual uint32_t UpdateItem(const std::string &key, const std::string &itemKey, Value &value) = 0;
59     virtual uint32_t UpdateItems(const std::string &key, const std::map<std::string, std::vector<uint8_t>> &data) = 0;
60     virtual uint32_t GetItem(const std::string &key, const std::string &itemKey, Value &value) = 0;
61     virtual uint32_t GetItems(const std::string &key, std::map<std::string, std::vector<uint8_t>> &data) = 0;
62     virtual uint32_t RegisterObserver(const std::string &key, std::shared_ptr<TableWatcher> watcher) = 0;
63     virtual uint32_t UnRegisterObserver(const std::string &key) = 0;
64     virtual uint32_t SetStatusNotifier(std::shared_ptr<StatusWatcher> watcher) = 0;
65 };
66 } // namespace OHOS::ObjectStore
67 #endif