blob: b86af06afa473f5aa4c55419bc688b07aca9b281 [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_HIREDISCLUSTEREPOLLADAPTER_HPP_
23#define SHAREDDATALAYER_REDIS_HIREDISCLUSTEREPOLLADAPTER_HPP_
24
25#include <map>
26#include <memory>
27
28extern "C"
29{
30 struct redisClusterAsyncContext;
31 struct redisAsyncContext;
32}
33
34namespace shareddatalayer
35{
36 class Engine;
37
38 namespace redis
39 {
40 class HiredisClusterSystem;
41
42 class HiredisClusterEpollAdapter
43 {
44 public:
45 class Node;
46
47 explicit HiredisClusterEpollAdapter(Engine& engine);
48
49 HiredisClusterEpollAdapter(Engine& engine, HiredisClusterSystem& hiredisClusterSystem);
50
51 virtual ~HiredisClusterEpollAdapter() = default;
52
53 virtual void setup(redisClusterAsyncContext* acc);
54
55 virtual void attach(redisAsyncContext* ac);
56
57 virtual void detach(const redisAsyncContext* ac);
58
59 HiredisClusterEpollAdapter(const HiredisClusterEpollAdapter&) = delete;
60 HiredisClusterEpollAdapter(HiredisClusterEpollAdapter&&) = delete;
61 HiredisClusterEpollAdapter& operator = (const HiredisClusterEpollAdapter&) = delete;
62 HiredisClusterEpollAdapter& operator = (HiredisClusterEpollAdapter&&) = delete;
63
64 private:
65 Engine& engine;
66 HiredisClusterSystem& hiredisClusterSystem;
67 std::map<int, std::unique_ptr<Node>> nodes;
68 };
69
70 class HiredisClusterEpollAdapter::Node
71 {
72 public:
73 Node(Engine& engine,
74 redisAsyncContext* ac,
75 HiredisClusterSystem& hiredisClusterSystem);
76
77 ~Node();
78
79 void addRead();
80
81 void addWrite();
82
83 void delRead();
84
85 void delWrite();
86
87 void cleanup();
88
89 Node(const Node&) = delete;
90 Node(Node&&) = delete;
91 Node& operator = (const Node&) = delete;
92 Node& operator = (Node&&) = delete;
93
94 private:
Rolf Badorekef2bf512019-08-20 11:17:15 +030095 HiredisClusterSystem& hiredisClusterSystem;
Timo Tietavainenfaf9fc72021-08-05 11:46:07 +030096 Engine& engine;
Rolf Badorekef2bf512019-08-20 11:17:15 +030097 redisAsyncContext* ac;
98 unsigned int eventState;
99 bool reading;
100 bool writing;
101 bool isMonitoring;
102
103 void eventHandler(unsigned int events);
104 };
105 }
106}
107
108#endif