Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / Zephyr / ThreadStackManagerImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 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  *          Provides an implementation of the ThreadStackManager object for
21  *          Zephyr platforms.
22  */
23
24 #pragma once
25
26 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
27
28 #include <net/openthread.h>
29 #include <zephyr.h>
30
31 #include <openthread/thread.h>
32 #include <platform/Zephyr/BLEManagerImpl.h>
33
34 #include <support/logging/CHIPLogging.h>
35
36 namespace chip {
37 namespace DeviceLayer {
38
39 class ThreadStackManager;
40 class ThreadStackManagerImpl;
41
42 /**
43  * Concrete implementation of the ThreadStackManager singleton object for nRF Connect platforms.
44  */
45 class ThreadStackManagerImpl final : public ThreadStackManager,
46                                      public Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>
47 {
48     // Allow the ThreadStackManager interface class to delegate method calls to
49     // the implementation methods provided by this class.
50     friend class ThreadStackManager;
51
52     // namespace Internal {
53
54     // Allow the generic implementation base classes to call helper methods on
55     // this class.
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57     friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
58 #endif
59
60 public:
61     // ===== Methods that implement the ThreadStackManager abstract interface.
62     CHIP_ERROR _InitThreadStack();
63
64 protected:
65     // ===== Methods that implement the ThreadStackManager abstract interface.
66
67     CHIP_ERROR _StartThreadTask();
68     void _LockThreadStack();
69     bool _TryLockThreadStack();
70     void _UnlockThreadStack();
71
72     // ===== Methods that override the GenericThreadStackManagerImpl_OpenThread abstract interface.
73
74     void _ProcessThreadActivity();
75     void _OnCHIPoBLEAdvertisingStart();
76     void _OnCHIPoBLEAdvertisingStop();
77
78     //} // namespace Internal
79
80 private:
81     // ===== Members for internal use by the following friends.
82
83     friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
84     friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
85
86     static ThreadStackManagerImpl sInstance;
87
88     // ===== Private members for use by this class only.
89
90     ThreadStackManagerImpl() = default;
91 };
92
93 /**
94  * Returns the public interface of the ThreadStackManager singleton object.
95  *
96  * chip applications should use this to access features of the ThreadStackManager object
97  * that are common to all platforms.
98  */
99 inline ThreadStackManager & ThreadStackMgr(void)
100 {
101     return ThreadStackManagerImpl::sInstance;
102 }
103
104 /**
105  * Returns the platform-specific implementation of the ThreadStackManager singleton object.
106  *
107  * chip applications can use this to gain access to features of the ThreadStackManager
108  * that are specific to nRF Connect platforms.
109  */
110 inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
111 {
112     return ThreadStackManagerImpl::sInstance;
113 }
114
115 } // namespace DeviceLayer
116 } // namespace chip