37a45d4e7bf16e17ffd709190840586ba724f016
[ric-plt/sdl.git] / include / private / redis / asyncdatabasediscovery.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 /*
18  * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19  * platform project (RICP).
20 */
21
22 #ifndef SHAREDDATALAYER_REDIS_ASYNCDATABASEDISCOVERY_HPP_
23 #define SHAREDDATALAYER_REDIS_ASYNCDATABASEDISCOVERY_HPP_
24
25 #include <functional>
26 #include <map>
27 #include <string>
28 #include <memory>
29 #include <vector>
30 #include <boost/optional.hpp>
31 #include "private/logger.hpp"
32
33 namespace shareddatalayer
34 {
35     class Engine;
36     class DatabaseConfiguration;
37
38     namespace redis
39     {
40         struct DatabaseInfo;
41
42         class AsyncDatabaseDiscovery
43         {
44         public:
45             AsyncDatabaseDiscovery(const AsyncDatabaseDiscovery&) = delete;
46
47             AsyncDatabaseDiscovery& operator = (const AsyncDatabaseDiscovery&) = delete;
48
49             virtual ~AsyncDatabaseDiscovery() = default;
50
51             using StateChangedCb = std::function<void(const DatabaseInfo&)>;
52
53             /**
54              * Register a callback to be invoked whenever connection information changes. Client would tear down
55              * its current connection and setup a new one using the information that was passed to the callback.
56              *
57              * @note connection state changes (e.g. connection down, switchover)) do not invoke callback if
58              *       connection information does not change.
59              *
60              * @note When a callback is set, it should be scheduled right away (not called inside this function)
61              *       if connection info is already available.
62              *
63              * @param stateChangedCb Callback to be invoked when the information of the database changes.
64              */
65             virtual void setStateChangedCb(const StateChangedCb& stateChangedCb) = 0;
66
67             virtual void clearStateChangedCb() = 0;
68
69             using Namespace = std::string;
70
71             static std::shared_ptr<AsyncDatabaseDiscovery> create(std::shared_ptr<Engine> engine,
72                                                                   const boost::optional<Namespace>& ns,
73                                                                   const DatabaseConfiguration& staticDatabaseConfiguration,
74                                                                   std::shared_ptr<Logger> logger);
75
76         protected:
77             AsyncDatabaseDiscovery() = default;
78         };
79     }
80 }
81
82 #endif