blob: b0f5fb534270b1b00d61864a35bbc662ef61641e [file] [log] [blame]
Rolf Badorekef2bf512019-08-20 11:17:15 +03001/*
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 Tietavainena0745d22019-11-28 09:55:22 +020017/*
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
20*/
21
Rolf Badorekef2bf512019-08-20 11:17:15 +030022#ifndef SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_
23#define SHAREDDATALAYER_SYNCSTORAGEIMPL_HPP_
24
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030025#include <sdl/asyncstorage.hpp>
Rolf Badorekef2bf512019-08-20 11:17:15 +030026#include <sdl/syncstorage.hpp>
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030027#include <sys/poll.h>
Rolf Badorekef2bf512019-08-20 11:17:15 +030028#include <system_error>
29
30namespace shareddatalayer
31{
Rolf Badorekef2bf512019-08-20 11:17:15 +030032 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 Tietavainend565df62021-08-11 07:33:30 +030042 virtual void waitReady(const Namespace& ns, const std::chrono::steady_clock::duration& timeout) override;
43
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030044 virtual void set(const Namespace& ns, const DataMap& dataMap) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030045
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030046 virtual bool setIf(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030047
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030048 virtual bool setIfNotExists(const Namespace& ns, const Key& key, const Data& data) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030049
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030050 virtual DataMap get(const Namespace& ns, const Keys& keys) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030051
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030052 virtual void remove(const Namespace& ns, const Keys& keys) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030053
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030054 virtual bool removeIf(const Namespace& ns, const Key& key, const Data& data) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030055
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030056 virtual Keys findKeys(const Namespace& ns, const std::string& keyPrefix) override;
Rolf Badorekef2bf512019-08-20 11:17:15 +030057
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030058 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 Badorekef2bf512019-08-20 11:17:15 +030063
64 private:
65 std::unique_ptr<AsyncStorage> asyncStorage;
66 System& system;
Rolf Badorekef2bf512019-08-20 11:17:15 +030067 DataMap localMap;
68 Keys localKeys;
69 bool localStatus;
70 std::error_code localError;
71 bool synced;
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030072 bool isReady;
73 struct pollfd events;
74 std::chrono::steady_clock::duration operationTimeout;
Rolf Badorekef2bf512019-08-20 11:17:15 +030075
76 void verifyBackendResponse();
77
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030078 void pollAndHandleEvents(int timeout_ms);
79
Timo Tietavainend565df62021-08-11 07:33:30 +030080 void waitForReadinessCheckCallback(const std::chrono::steady_clock::duration& timeout);
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030081
82 void waitForOperationCallback();
Rolf Badorekef2bf512019-08-20 11:17:15 +030083
84 void waitSdlToBeReady(const Namespace& ns);
85
Timo Tietavainend565df62021-08-11 07:33:30 +030086 void waitSdlToBeReady(const Namespace& ns, const std::chrono::steady_clock::duration& timeout);
87
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030088 void waitReadyAck(const std::error_code& error);
89
Rolf Badorekef2bf512019-08-20 11:17:15 +030090 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 Tietavainenfaf9fc72021-08-05 11:46:07 +030097
98 void handlePendingEvents();
Rolf Badorekef2bf512019-08-20 11:17:15 +030099 };
100}
101
102#endif