2 Copyright (c) 2018-2019 Nokia.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #ifndef SHAREDDATALAYER_REDIS_ASYNCCOMMANDDISPATCHER_HPP_
23 #define SHAREDDATALAYER_REDIS_ASYNCCOMMANDDISPATCHER_HPP_
26 #include <system_error>
30 #include "private/asyncconnection.hpp"
31 #include "private/logger.hpp"
33 namespace shareddatalayer
38 class ContentsBuilder;
43 class AsyncCommandDispatcher
46 AsyncCommandDispatcher(const AsyncCommandDispatcher&) = delete;
48 AsyncCommandDispatcher& operator = (const AsyncCommandDispatcher&) = delete;
50 virtual ~AsyncCommandDispatcher() = default;
52 using ConnectAck = std::function<void()>;
54 virtual void waitConnectedAsync(const ConnectAck& connectAck) = 0;
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()>;
60 virtual void registerDisconnectCb(const DisconnectCb& disconnectCb) = 0;
62 using CommandCb = std::function<void(const std::error_code&, const Reply&)>;
64 virtual void dispatchAsync(const CommandCb& commandCb,
65 const AsyncConnection::Namespace& ns,
66 const Contents& contents) = 0;
68 virtual void disableCommandCallbacks() = 0;
70 static std::shared_ptr<AsyncCommandDispatcher> create(Engine& engine,
71 const DatabaseInfo& databaseInfo,
72 std::shared_ptr<ContentsBuilder> contentsBuilder,
73 bool usePermanentCommandCallbacks,
74 std::shared_ptr<Logger> logger,
75 bool usedForSentinel);
78 AsyncCommandDispatcher() = default;