Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / EFR32 / ThreadStackManagerImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2019 Nest Labs, Inc.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18
19 /**
20  *    @file
21  *          Provides an implementation of the ThreadStackManager object
22  *          for EFR32 platforms using the Silicon Labs SDK and the OpenThread
23  *          stack.
24  */
25
26 #pragma once
27
28 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
29 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
30
31 #include <openthread/tasklet.h>
32 #include <openthread/thread.h>
33
34 extern "C" void otSysEventSignalPending(void);
35
36 namespace chip {
37 namespace DeviceLayer {
38
39 class ThreadStackManager;
40 class ThreadStackManagerImpl;
41 namespace Internal {
42 extern int GetEntropy_EFR32(uint8_t * buf, size_t bufSize);
43 }
44
45 /**
46  * Concrete implementation of the ThreadStackManager singleton object for EFR32 platforms
47  * using the Silicon Labs SDK and the OpenThread stack.
48  */
49 class ThreadStackManagerImpl final : public ThreadStackManager,
50                                      public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
51                                      public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
52 {
53     // Allow the ThreadStackManager interface class to delegate method calls to
54     // the implementation methods provided by this class.
55     friend class ThreadStackManager;
56
57     // Allow the generic implementation base classes to call helper methods on
58     // this class.
59 #ifndef DOXYGEN_SHOULD_SKIP_THIS
60     friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
61     friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
62     friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
63 #endif
64
65     // Allow glue functions called by OpenThread to call helper methods on this
66     // class.
67     friend void ::otTaskletsSignalPending(otInstance * otInst);
68     friend void ::otSysEventSignalPending(void);
69
70 public:
71     // ===== Platform-specific members that may be accessed directly by the application.
72
73     using ThreadStackManager::InitThreadStack;
74     CHIP_ERROR InitThreadStack(otInstance * otInst);
75     void _OnCHIPoBLEAdvertisingStart(void);
76     void _OnCHIPoBLEAdvertisingStop(void);
77
78 private:
79     // ===== Methods that implement the ThreadStackManager abstract interface.
80
81     CHIP_ERROR _InitThreadStack(void);
82
83     // ===== Members for internal use by the following friends.
84
85     friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
86     friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
87     friend int Internal::GetEntropy_EFR32(uint8_t * buf, size_t bufSize);
88
89     static ThreadStackManagerImpl sInstance;
90
91     static bool IsInitialized();
92
93     // ===== Private members for use by this class only.
94
95     ThreadStackManagerImpl() = default;
96 };
97
98 /**
99  * Returns the public interface of the ThreadStackManager singleton object.
100  *
101  * Chip applications should use this to access features of the ThreadStackManager object
102  * that are common to all platforms.
103  */
104 inline ThreadStackManager & ThreadStackMgr(void)
105 {
106     return ThreadStackManagerImpl::sInstance;
107 }
108
109 /**
110  * Returns the platform-specific implementation of the ThreadStackManager singleton object.
111  *
112  * Chip applications can use this to gain access to features of the ThreadStackManager
113  * that are specific to EFR32 platforms.
114  */
115 inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
116 {
117     return ThreadStackManagerImpl::sInstance;
118 }
119
120 } // namespace DeviceLayer
121 } // namespace chip