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