Line data Source code
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 :
28 : #if CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV
29 :
30 : #include <lib/core/CHIPError.h>
31 : #include <system/SocketEvents.h>
32 :
33 : namespace chip {
34 : namespace System {
35 :
36 : class LayerSockets;
37 : class WakeEventTest;
38 :
39 : /**
40 : * @class WakeEvent
41 : *
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().
44 : */
45 : class WakeEvent
46 : {
47 : public:
48 : CHIP_ERROR Open(LayerSockets & systemLayer); /**< Initialize the pipeline */
49 : void Close(LayerSockets & systemLayer); /**< Close both ends of the pipeline. */
50 :
51 : CHIP_ERROR Notify() const; /**< Set the event. */
52 : void Confirm() const; /**< Clear the event. */
53 :
54 : private:
55 : friend class WakeEventTest;
56 :
57 : int GetReadFD() const { return mReadFD; }
58 6601572 : static void Confirm(System::SocketEvents events, intptr_t data) { reinterpret_cast<WakeEvent *>(data)->Confirm(); }
59 :
60 : #if CHIP_SYSTEM_CONFIG_USE_POSIX_PIPE
61 : int mWriteFD;
62 : #endif
63 : int mReadFD;
64 : SocketWatchToken mReadWatch;
65 : };
66 :
67 : } // namespace System
68 : } // namespace chip
69 :
70 : #endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && !CHIP_SYSTEM_CONFIG_USE_LIBEV
|