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_IMPL_H 17 #define DISTRIBUTED_OBJECT_IMPL_H 18 19 #include "flat_object_store.h" 20 21 namespace OHOS::ObjectStore { 22 class DistributedObjectImpl : public DistributedObject { 23 public: 24 DistributedObjectImpl(const std::string &sessionId, FlatObjectStore *flatObjectStore); 25 ~DistributedObjectImpl(); 26 uint32_t PutDouble(const std::string &key, double value) override; 27 uint32_t PutBoolean(const std::string &key, bool value) override; 28 uint32_t PutString(const std::string &key, const std::string &value) override; 29 uint32_t GetDouble(const std::string &key, double &value) override; 30 uint32_t GetBoolean(const std::string &key, bool &value) override; 31 uint32_t GetString(const std::string &key, std::string &value) override; 32 uint32_t PutComplex(const std::string &key, const std::vector<uint8_t> &value) override; 33 uint32_t GetComplex(const std::string &key, std::vector<uint8_t> &value) override; 34 std::string &GetSessionId() override; 35 uint32_t Save(const std::string &deviceId) override; 36 uint32_t RevokeSave() override; 37 uint32_t GetType(const std::string &key, Type &type) override; 38 uint32_t BindAssetStore(const std::string &assetKey, AssetBindInfo &bindInfo) override; 39 40 private: 41 uint32_t GetAssetValue(const std::string &assetKey, Asset &assetValue); 42 std::string sessionId_; 43 FlatObjectStore *flatObjectStore_ = nullptr; 44 uint32_t PutDeviceId(); 45 void RemovePrefix(Asset &assetValue); 46 }; 47 48 #define LOG_ERROR_RETURN(condition, message, retVal) \ 49 do { \ 50 if (!(condition)) { \ 51 LOG_ERROR("test (" #condition ") failed: " message); \ 52 return retVal; \ 53 } \ 54 } while (0) 55 } // namespace OHOS::ObjectStore 56 57 #endif // DISTRIBUTED_OBJECT_IMPL_H 58