Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 1 | /* |
| 2 | Copyright (c) 2018-2019 Nokia. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_ |
| 18 | #define SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_ |
| 19 | |
| 20 | #include <sdl/syncstorage.hpp> |
| 21 | #include <system_error> |
| 22 | |
| 23 | namespace shareddatalayer |
| 24 | { |
| 25 | class AsyncStorage; |
| 26 | |
| 27 | class System; |
| 28 | |
| 29 | class SyncStorageImpl: public SyncStorage |
| 30 | { |
| 31 | public: |
| 32 | explicit SyncStorageImpl(std::unique_ptr<AsyncStorage> asyncStorage); |
| 33 | |
| 34 | SyncStorageImpl(std::unique_ptr<AsyncStorage> asyncStorage, |
| 35 | System& system); |
| 36 | |
| 37 | void set(const Namespace& ns, const DataMap& dataMap) override; |
| 38 | |
| 39 | bool setIf(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData) override; |
| 40 | |
| 41 | bool setIfNotExists(const Namespace& ns, const Key& key, const Data& data) override; |
| 42 | |
| 43 | DataMap get(const Namespace& ns, const Keys& keys) override; |
| 44 | |
| 45 | void remove(const Namespace& ns, const Keys& keys) override; |
| 46 | |
| 47 | bool removeIf(const Namespace& ns, const Key& key, const Data& data) override; |
| 48 | |
| 49 | Keys findKeys(const Namespace& ns, const std::string& keyPrefix) override; |
| 50 | |
| 51 | void removeAll(const Namespace& ns) override; |
| 52 | |
| 53 | private: |
| 54 | std::unique_ptr<AsyncStorage> asyncStorage; |
| 55 | System& system; |
| 56 | int pFd; |
| 57 | DataMap localMap; |
| 58 | Keys localKeys; |
| 59 | bool localStatus; |
| 60 | std::error_code localError; |
| 61 | bool synced; |
| 62 | |
| 63 | void verifyBackendResponse(); |
| 64 | |
| 65 | void waitForCallback(); |
| 66 | |
| 67 | void waitSdlToBeReady(const Namespace& ns); |
| 68 | |
| 69 | void modifyAck(const std::error_code& error); |
| 70 | |
| 71 | void modifyIfAck(const std::error_code& error, bool status); |
| 72 | |
| 73 | void getAck(const std::error_code& error, const DataMap& dataMap); |
| 74 | |
| 75 | void findKeysAck(const std::error_code& error, const Keys& keys); |
| 76 | }; |
| 77 | } |
| 78 | |
| 79 | #endif |