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