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 | |
Timo Tietavainen | a0745d2 | 2019-11-28 09:55:22 +0200 | [diff] [blame] | 17 | /* |
| 18 | * This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 19 | * platform project (RICP). |
| 20 | */ |
| 21 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 22 | #ifndef SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_ |
| 23 | #define SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_ |
| 24 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 25 | #include <sdl/asyncstorage.hpp> |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 26 | #include <sdl/syncstorage.hpp> |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 27 | #include <sys/poll.h> |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 28 | #include <system_error> |
| 29 | |
| 30 | namespace shareddatalayer |
| 31 | { |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 32 | class System; |
| 33 | |
| 34 | class SyncStorageImpl: public SyncStorage |
| 35 | { |
| 36 | public: |
| 37 | explicit SyncStorageImpl(std::unique_ptr<AsyncStorage> asyncStorage); |
| 38 | |
| 39 | SyncStorageImpl(std::unique_ptr<AsyncStorage> asyncStorage, |
| 40 | System& system); |
| 41 | |
Timo Tietavainen | d565df6 | 2021-08-11 07:33:30 +0300 | [diff] [blame^] | 42 | virtual void waitReady(const Namespace& ns, const std::chrono::steady_clock::duration& timeout) override; |
| 43 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 44 | virtual void set(const Namespace& ns, const DataMap& dataMap) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 45 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 46 | virtual bool setIf(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 47 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 48 | virtual bool setIfNotExists(const Namespace& ns, const Key& key, const Data& data) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 49 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 50 | virtual DataMap get(const Namespace& ns, const Keys& keys) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 51 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 52 | virtual void remove(const Namespace& ns, const Keys& keys) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 53 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 54 | virtual bool removeIf(const Namespace& ns, const Key& key, const Data& data) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 55 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 56 | virtual Keys findKeys(const Namespace& ns, const std::string& keyPrefix) override; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 57 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 58 | virtual void removeAll(const Namespace& ns) override; |
| 59 | |
| 60 | virtual void setOperationTimeout(const std::chrono::steady_clock::duration& timeout) override; |
| 61 | |
| 62 | static constexpr int NO_TIMEOUT = -1; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 63 | |
| 64 | private: |
| 65 | std::unique_ptr<AsyncStorage> asyncStorage; |
| 66 | System& system; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 67 | DataMap localMap; |
| 68 | Keys localKeys; |
| 69 | bool localStatus; |
| 70 | std::error_code localError; |
| 71 | bool synced; |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 72 | bool isReady; |
| 73 | struct pollfd events; |
| 74 | std::chrono::steady_clock::duration operationTimeout; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 75 | |
| 76 | void verifyBackendResponse(); |
| 77 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 78 | void pollAndHandleEvents(int timeout_ms); |
| 79 | |
Timo Tietavainen | d565df6 | 2021-08-11 07:33:30 +0300 | [diff] [blame^] | 80 | void waitForReadinessCheckCallback(const std::chrono::steady_clock::duration& timeout); |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 81 | |
| 82 | void waitForOperationCallback(); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 83 | |
| 84 | void waitSdlToBeReady(const Namespace& ns); |
| 85 | |
Timo Tietavainen | d565df6 | 2021-08-11 07:33:30 +0300 | [diff] [blame^] | 86 | void waitSdlToBeReady(const Namespace& ns, const std::chrono::steady_clock::duration& timeout); |
| 87 | |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 88 | void waitReadyAck(const std::error_code& error); |
| 89 | |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 90 | void modifyAck(const std::error_code& error); |
| 91 | |
| 92 | void modifyIfAck(const std::error_code& error, bool status); |
| 93 | |
| 94 | void getAck(const std::error_code& error, const DataMap& dataMap); |
| 95 | |
| 96 | void findKeysAck(const std::error_code& error, const Keys& keys); |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame] | 97 | |
| 98 | void handlePendingEvents(); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 99 | }; |
| 100 | } |
| 101 | |
| 102 | #endif |