3 * Copyright (c) 2020-2021 Project CHIP Authors
4 * Copyright (c) 2019 Nest Labs, Inc.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * Provides an generic implementation of ConnectivityManager features
22 * for use on platforms that support Thread.
27 #include <platform/ThreadStackManager.h>
28 #include <support/BitFlags.h>
33 namespace DeviceLayer {
35 class ConnectivityManagerImpl;
40 * Provides a generic implementation of WiFi-specific ConnectivityManager features for
41 * use on platforms that support Thread.
43 * This class is intended to be inherited (directly or indirectly) by the ConnectivityManagerImpl
44 * class, which also appears as the template's ImplClass parameter.
46 * The GenericConnectivityManagerImpl_Thread<> class is designed to be independent of the particular
47 * Thread stack in use, implying, for example, that the code does not make direct use of any OpenThread
48 * APIs. This is achieved by delegating all stack-specific operations to the ThreadStackManager class.
51 template <class ImplClass>
52 class GenericConnectivityManagerImpl_Thread
55 // ===== Methods that implement the ConnectivityManager abstract interface.
58 void _OnPlatformEvent(const ChipDeviceEvent * event);
59 ConnectivityManager::ThreadMode _GetThreadMode();
60 CHIP_ERROR _SetThreadMode(ConnectivityManager::ThreadMode val);
61 bool _IsThreadEnabled();
62 bool _IsThreadApplicationControlled();
63 ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();
64 CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
65 void _GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
66 CHIP_ERROR _SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
67 bool _IsThreadAttached();
68 bool _IsThreadProvisioned();
69 void _ErasePersistentInfo();
70 bool _HaveServiceConnectivityViaThread();
72 // ===== Members for use by the implementation subclass.
74 void UpdateServiceConnectivity();
77 // ===== Private members reserved for use by this class only.
79 enum class Flags : uint8_t
81 kHaveServiceConnectivity = 0x01,
82 kIsApplicationControlled = 0x02
85 BitFlags<Flags> mFlags;
87 ImplClass * Impl() { return static_cast<ImplClass *>(this); }
90 template <class ImplClass>
91 inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_Init()
96 template <class ImplClass>
97 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadEnabled()
99 return ThreadStackMgrImpl().IsThreadEnabled();
102 template <class ImplClass>
103 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadApplicationControlled()
105 return mFlags.Has(Flags::kIsApplicationControlled);
108 template <class ImplClass>
109 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadAttached()
111 return ThreadStackMgrImpl().IsThreadAttached();
114 template <class ImplClass>
115 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadProvisioned()
117 return ThreadStackMgrImpl().IsThreadProvisioned();
120 template <class ImplClass>
121 inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ErasePersistentInfo()
123 ThreadStackMgrImpl().ErasePersistentInfo();
126 template <class ImplClass>
127 inline ConnectivityManager::ThreadDeviceType GenericConnectivityManagerImpl_Thread<ImplClass>::_GetThreadDeviceType()
129 return ThreadStackMgrImpl().GetThreadDeviceType();
132 template <class ImplClass>
134 GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType)
136 return ThreadStackMgrImpl().SetThreadDeviceType(deviceType);
139 template <class ImplClass>
141 GenericConnectivityManagerImpl_Thread<ImplClass>::_GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig)
143 ThreadStackMgrImpl().GetThreadPollingConfig(pollingConfig);
146 template <class ImplClass>
147 inline CHIP_ERROR GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadPollingConfig(
148 const ConnectivityManager::ThreadPollingConfig & pollingConfig)
150 return ThreadStackMgrImpl().SetThreadPollingConfig(pollingConfig);
153 template <class ImplClass>
154 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_HaveServiceConnectivityViaThread()
156 return mFlags.Has(Flags::kHaveServiceConnectivity);
159 } // namespace Internal
160 } // namespace DeviceLayer