blob: d6a90dfe12b4dea0d933e504c7f66153348d3e2f [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
17#ifndef SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
18#define SHAREDDATALAYER_REDIS_ASYNCSTORAGEIMPL_HPP_
19
Rolf Badorek8324d022019-09-17 16:47:20 +030020#include <functional>
Rolf Badorekef2bf512019-08-20 11:17:15 +030021#include <sdl/asyncstorage.hpp>
22#include <sdl/publisherid.hpp>
23#include "private/configurationreader.hpp"
24#include "private/databaseconfigurationimpl.hpp"
25#include "private/logger.hpp"
26#include "private/namespaceconfigurationsimpl.hpp"
Rolf Badorek8324d022019-09-17 16:47:20 +030027#include "private/redis/asyncdatabasediscovery.hpp"
Rolf Badorekef2bf512019-08-20 11:17:15 +030028
29namespace shareddatalayer
30{
31 class Engine;
32
33 class AsyncStorageImpl: public AsyncStorage
34 {
35 public:
Rolf Badorek8324d022019-09-17 16:47:20 +030036 using AsyncDatabaseDiscoveryCreator = std::function<std::shared_ptr<redis::AsyncDatabaseDiscovery>(std::shared_ptr<Engine> engine,
37 const DatabaseConfiguration& databaseConfiguration,
38 std::shared_ptr<Logger> logger)>;
39
Rolf Badorekef2bf512019-08-20 11:17:15 +030040 AsyncStorageImpl(const AsyncStorageImpl&) = delete;
41
42 AsyncStorageImpl& operator = (const AsyncStorageImpl&) = delete;
43
44 AsyncStorageImpl(AsyncStorageImpl&&) = delete;
45
46 AsyncStorageImpl& operator = (AsyncStorageImpl&&) = delete;
47
48 AsyncStorageImpl(std::shared_ptr<Engine> engine,
49 const boost::optional<PublisherId>& pId,
50 std::shared_ptr<Logger> logger);
51
52 // Meant for UT
53 AsyncStorageImpl(std::shared_ptr<Engine> engine,
54 const boost::optional<PublisherId>& pId,
55 std::shared_ptr<DatabaseConfiguration> databaseConfiguration,
56 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations,
Rolf Badorek8324d022019-09-17 16:47:20 +030057 std::shared_ptr<Logger> logger,
58 const AsyncDatabaseDiscoveryCreator& asyncDatabaseDiscoveryCreator);
Rolf Badorekef2bf512019-08-20 11:17:15 +030059
60 int fd() const override;
61
62 void handleEvents() override;
63
64 void waitReadyAsync(const Namespace& ns, const ReadyAck& readyAck) override;
65
66 void setAsync(const Namespace& ns, const DataMap& dataMap, const ModifyAck& modifyAck) override;
67
68 void setIfAsync(const Namespace& ns, const Key& key, const Data& oldData, const Data& newData, const ModifyIfAck& modifyIfAck) override;
69
70 void setIfNotExistsAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
71
72 void getAsync(const Namespace& ns, const Keys& keys, const GetAck& getAck) override;
73
74 void removeAsync(const Namespace& ns, const Keys& keys, const ModifyAck& modifyAck) override;
75
76 void removeIfAsync(const Namespace& ns, const Key& key, const Data& data, const ModifyIfAck& modifyIfAck) override;
77
78 void findKeysAsync(const Namespace& ns, const std::string& keyPrefix, const FindKeysAck& findKeysAck) override;
79
80 void removeAllAsync(const Namespace& ns, const ModifyAck& modifyAck) override;
81
82 //public for UT
83 AsyncStorage& getOperationHandler(const std::string& ns);
84 private:
85 std::shared_ptr<Engine> engine;
86 std::shared_ptr<DatabaseConfiguration> databaseConfiguration;
87 std::shared_ptr<NamespaceConfigurations> namespaceConfigurations;
88 const boost::optional<PublisherId> publisherId;
89 std::shared_ptr<Logger> logger;
Rolf Badorek8324d022019-09-17 16:47:20 +030090 AsyncDatabaseDiscoveryCreator asyncDatabaseDiscoveryCreator;
Rolf Badorekef2bf512019-08-20 11:17:15 +030091
92 AsyncStorage& getRedisHandler();
93 AsyncStorage& getDummyHandler();
94 };
95}
96
97#endif