blob: 8df16af8452ce65c5612da08074619a5b408787d [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_REDIS_ASYNCCOMMANDDISPATCHER_HPP_
23#define SHAREDDATALAYER_REDIS_ASYNCCOMMANDDISPATCHER_HPP_
24
25#include <functional>
26#include <system_error>
27#include <string>
28#include <memory>
29#include <vector>
30#include "private/asyncconnection.hpp"
31#include "private/logger.hpp"
32
33namespace shareddatalayer
34{
35 class Engine;
36 namespace redis
37 {
38 class ContentsBuilder;
39 class Reply;
40 struct Contents;
41 struct DatabaseInfo;
42
43 class AsyncCommandDispatcher
44 {
45 public:
46 AsyncCommandDispatcher(const AsyncCommandDispatcher&) = delete;
47
48 AsyncCommandDispatcher& operator = (const AsyncCommandDispatcher&) = delete;
49
50 virtual ~AsyncCommandDispatcher() = default;
51
52 using ConnectAck = std::function<void()>;
53
54 virtual void waitConnectedAsync(const ConnectAck& connectAck) = 0;
55
56 // NOTE: If there are connections open to several database instances, callback
57 // does not identify that which one was disconnected.
58 using DisconnectCb = std::function<void()>;
59
60 virtual void registerDisconnectCb(const DisconnectCb& disconnectCb) = 0;
61
62 using CommandCb = std::function<void(const std::error_code&, const Reply&)>;
63
64 virtual void dispatchAsync(const CommandCb& commandCb,
65 const AsyncConnection::Namespace& ns,
66 const Contents& contents) = 0;
67
68 virtual void disableCommandCallbacks() = 0;
69
70 static std::shared_ptr<AsyncCommandDispatcher> create(Engine& engine,
71 const DatabaseInfo& databaseInfo,
72 std::shared_ptr<ContentsBuilder> contentsBuilder,
73 bool usePermanentCommandCallbacks,
Rolf Badorek8324d022019-09-17 16:47:20 +030074 std::shared_ptr<Logger> logger,
75 bool usedForSentinel);
Rolf Badorekef2bf512019-08-20 11:17:15 +030076
77 protected:
78 AsyncCommandDispatcher() = default;
79 };
80 }
81}
82
83#endif