Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / platform / qpg6100 / 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
21  *          for Qorvo platforms and the OpenThread
22  *          stack.
23  */
24
25 #pragma once
26
27 #include <platform/FreeRTOS/GenericThreadStackManagerImpl_FreeRTOS.h>
28 #include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.h>
29
30 #include <openthread/tasklet.h>
31 #include <openthread/thread.h>
32
33 extern "C" void otSysEventSignalPending(void);
34
35 namespace chip {
36 namespace DeviceLayer {
37
38 class ThreadStackManager;
39 class ThreadStackManagerImpl;
40 namespace Internal {
41 extern int GetEntropy(uint8_t * buf, size_t bufSize);
42 }
43
44 /**
45  * Concrete implementation of the ThreadStackManager singleton object for Qorvo platforms
46  * using the OpenThread stack.
47  */
48 class ThreadStackManagerImpl final : public ThreadStackManager,
49                                      public Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>,
50                                      public Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>
51 {
52     // Allow the ThreadStackManager interface class to delegate method calls to
53     // the implementation methods provided by this class.
54     friend class ThreadStackManager;
55
56     // Allow the generic implementation base classes to call helper methods on
57     // this class.
58 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59     friend Internal::GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
60     friend Internal::GenericThreadStackManagerImpl_OpenThread_LwIP<ThreadStackManagerImpl>;
61     friend Internal::GenericThreadStackManagerImpl_FreeRTOS<ThreadStackManagerImpl>;
62 #endif
63
64     // Allow glue functions called by OpenThread to call helper methods on this
65     // class.
66     friend void ::otTaskletsSignalPending(otInstance * otInst);
67     friend void ::otSysEventSignalPending(void);
68
69 public:
70     // ===== Platform-specific members that may be accessed directly by the application.
71
72     using ThreadStackManager::InitThreadStack;
73     CHIP_ERROR InitThreadStack(otInstance * otInst);
74     void _OnCHIPoBLEAdvertisingStart(void);
75     void _OnCHIPoBLEAdvertisingStop(void);
76
77 private:
78     // ===== Methods that implement the ThreadStackManager abstract interface.
79
80     CHIP_ERROR _InitThreadStack(void);
81
82     // ===== Members for internal use by the following friends.
83
84     friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
85     friend ThreadStackManagerImpl & ::chip::DeviceLayer::ThreadStackMgrImpl(void);
86     friend int Internal::GetEntropy(uint8_t * buf, size_t bufSize);
87
88     static ThreadStackManagerImpl sInstance;
89
90     static bool IsInitialized();
91
92     // ===== Private members for use by this class only.
93
94     ThreadStackManagerImpl() = default;
95 };
96
97 /**
98  * Returns the public interface of the ThreadStackManager singleton object.
99  *
100  * chip applications should use this to access features of the ThreadStackManager object
101  * that are common to all platforms.
102  */
103 inline ThreadStackManager & ThreadStackMgr(void)
104 {
105     return ThreadStackManagerImpl::sInstance;
106 }
107
108 /**
109  * Returns the platform-specific implementation of the ThreadStackManager singleton object.
110  *
111  * chip applications can use this to gain access to features of the ThreadStackManager
112  * that are specific to the platform.
113  */
114 inline ThreadStackManagerImpl & ThreadStackMgrImpl(void)
115 {
116     return ThreadStackManagerImpl::sInstance;
117 }
118
119 } // namespace DeviceLayer
120 } // namespace chip