Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2020-2021 Project CHIP Authors |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * @file |
| 20 | * This file declares the abstraction of socket (file descriptor) events. |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | |
| 25 | // Include configuration headers |
| 26 | #include <system/SystemConfig.h> |
| 27 | |
Lukas Zeller | 4c9a1ad | 2023-08-29 17:57:44 +0200 | [diff] [blame] | 28 | #if CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 29 | |
Zang MingJie | 53dd583 | 2021-09-03 03:05:16 +0800 | [diff] [blame] | 30 | #include <lib/core/CHIPError.h> |
Kevin Schoedel | 82cf1b1 | 2021-08-23 09:20:13 -0400 | [diff] [blame] | 31 | #include <system/SocketEvents.h> |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 32 | |
| 33 | namespace chip { |
| 34 | namespace System { |
| 35 | |
Kevin Schoedel | 3a50501 | 2021-09-08 15:21:38 -0400 | [diff] [blame] | 36 | class LayerSockets; |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 37 | class WakeEventTest; |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * @class WakeEvent |
| 41 | * |
Kevin Schoedel | 3a50501 | 2021-09-08 15:21:38 -0400 | [diff] [blame] | 42 | * An instance of this type can be used by a System::Layer to allow other threads |
| 43 | * to wake its event loop thread via System::Layer::Signal(). |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 44 | */ |
| 45 | class WakeEvent |
| 46 | { |
| 47 | public: |
Kevin Schoedel | 3a50501 | 2021-09-08 15:21:38 -0400 | [diff] [blame] | 48 | CHIP_ERROR Open(LayerSockets & systemLayer); /**< Initialize the pipeline */ |
| 49 | void Close(LayerSockets & systemLayer); /**< Close both ends of the pipeline. */ |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 50 | |
Andrei Litvin | d43e6a7 | 2022-03-17 17:39:24 -0400 | [diff] [blame] | 51 | CHIP_ERROR Notify() const; /**< Set the event. */ |
| 52 | void Confirm() const; /**< Clear the event. */ |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | friend class WakeEventTest; |
| 56 | |
Kevin Schoedel | 82cf1b1 | 2021-08-23 09:20:13 -0400 | [diff] [blame] | 57 | int GetReadFD() const { return mReadFD; } |
| 58 | static void Confirm(System::SocketEvents events, intptr_t data) { reinterpret_cast<WakeEvent *>(data)->Confirm(); } |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 59 | |
| 60 | #if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE |
| 61 | int mWriteFD; |
| 62 | #endif |
Kevin Schoedel | 82cf1b1 | 2021-08-23 09:20:13 -0400 | [diff] [blame] | 63 | int mReadFD; |
| 64 | SocketWatchToken mReadWatch; |
Kevin Schoedel | fa6033f | 2021-07-19 15:44:08 -0400 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace System |
| 68 | } // namespace chip |
| 69 | |
Lukas Zeller | 4c9a1ad | 2023-08-29 17:57:44 +0200 | [diff] [blame] | 70 | #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV |