blob: d0c603952c21b7b3e7e768dbaf15d13b5265bff9 [file] [log] [blame]
Kevin Schoedelfa6033f2021-07-19 15:44:08 -04001/*
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 Zeller4c9a1ad2023-08-29 17:57:44 +020028#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040029
Zang MingJie53dd5832021-09-03 03:05:16 +080030#include <lib/core/CHIPError.h>
Kevin Schoedel82cf1b12021-08-23 09:20:13 -040031#include <system/SocketEvents.h>
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040032
33namespace chip {
34namespace System {
35
Kevin Schoedel3a505012021-09-08 15:21:38 -040036class LayerSockets;
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040037class WakeEventTest;
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040038
39/**
40 * @class WakeEvent
41 *
Kevin Schoedel3a505012021-09-08 15:21:38 -040042 * 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 Schoedelfa6033f2021-07-19 15:44:08 -040044 */
45class WakeEvent
46{
47public:
Kevin Schoedel3a505012021-09-08 15:21:38 -040048 CHIP_ERROR Open(LayerSockets & systemLayer); /**< Initialize the pipeline */
49 void Close(LayerSockets & systemLayer); /**< Close both ends of the pipeline. */
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040050
Andrei Litvind43e6a72022-03-17 17:39:24 -040051 CHIP_ERROR Notify() const; /**< Set the event. */
52 void Confirm() const; /**< Clear the event. */
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040053
54private:
55 friend class WakeEventTest;
56
Kevin Schoedel82cf1b12021-08-23 09:20:13 -040057 int GetReadFD() const { return mReadFD; }
58 static void Confirm(System::SocketEvents events, intptr_t data) { reinterpret_cast<WakeEvent *>(data)->Confirm(); }
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040059
60#if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE
61 int mWriteFD;
62#endif
Kevin Schoedel82cf1b12021-08-23 09:20:13 -040063 int mReadFD;
64 SocketWatchToken mReadWatch;
Kevin Schoedelfa6033f2021-07-19 15:44:08 -040065};
66
67} // namespace System
68} // namespace chip
69
Lukas Zeller4c9a1ad2023-08-29 17:57:44 +020070#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV