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_HIREDISCLUSTEREPOLLADAPTER_HPP_ |
| 23 | #define SHAREDDATALAYER_REDIS_HIREDISCLUSTEREPOLLADAPTER_HPP_ |
| 24 | |
| 25 | #include <map> |
| 26 | #include <memory> |
| 27 | |
| 28 | extern "C" |
| 29 | { |
| 30 | struct redisClusterAsyncContext; |
| 31 | struct redisAsyncContext; |
| 32 | } |
| 33 | |
| 34 | namespace 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 Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 95 | HiredisClusterSystem& hiredisClusterSystem; |
Timo Tietavainen | faf9fc7 | 2021-08-05 11:46:07 +0300 | [diff] [blame^] | 96 | Engine& engine; |
Rolf Badorek | ef2bf51 | 2019-08-20 11:17:15 +0300 | [diff] [blame] | 97 | 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 |