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_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 | |
| 33 | namespace 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 Badorek | 8324d02 | 2019-09-17 16:47:20 +0300 | [diff] [blame] | 74 | std::shared_ptr<Logger> logger, |
| 75 | bool usedForSentinel); |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 76 | |
| 77 | protected: |
| 78 | AsyncCommandDispatcher() = default; |
| 79 | }; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | #endif |