3 * Copyright (c) 2020 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>
30 namespace DeviceLayer {
32 class ConnectivityManagerImpl;
37 * Provides a generic implementation of WiFi-specific ConnectivityManager features for
38 * use on platforms that support Thread.
40 * This class is intended to be inherited (directly or indirectly) by the ConnectivityManagerImpl
41 * class, which also appears as the template's ImplClass parameter.
43 * The GenericConnectivityManagerImpl_Thread<> class is designed to be independent of the particular
44 * Thread stack in use, implying, for example, that the code does not make direct use of any OpenThread
45 * APIs. This is achieved by delegating all stack-specific operations to the ThreadStackManager class.
48 template <class ImplClass>
49 class GenericConnectivityManagerImpl_Thread
52 // ===== Methods that implement the ConnectivityManager abstract interface.
55 void _OnPlatformEvent(const ChipDeviceEvent * event);
56 ConnectivityManager::ThreadMode _GetThreadMode();
57 CHIP_ERROR _SetThreadMode(ConnectivityManager::ThreadMode val);
58 bool _IsThreadEnabled();
59 bool _IsThreadApplicationControlled();
60 ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();
61 CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
62 void _GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
63 CHIP_ERROR _SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
64 bool _IsThreadAttached();
65 bool _IsThreadProvisioned();
66 void _ErasePersistentInfo();
67 bool _HaveServiceConnectivityViaThread();
69 // ===== Members for use by the implementation subclass.
71 void UpdateServiceConnectivity();
74 // ===== Private members reserved for use by this class only.
78 kFlag_HaveServiceConnectivity = 0x01,
79 kFlag_IsApplicationControlled = 0x02
84 ImplClass * Impl() { return static_cast<ImplClass *>(this); }
87 template <class ImplClass>
88 inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_Init()
93 template <class ImplClass>
94 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadEnabled()
96 return ThreadStackMgrImpl().IsThreadEnabled();
99 template <class ImplClass>
100 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadApplicationControlled()
102 return GetFlag(mFlags, kFlag_IsApplicationControlled);
105 template <class ImplClass>
106 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadAttached()
108 return ThreadStackMgrImpl().IsThreadAttached();
111 template <class ImplClass>
112 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadProvisioned()
114 return ThreadStackMgrImpl().IsThreadProvisioned();
117 template <class ImplClass>
118 inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ErasePersistentInfo()
120 ThreadStackMgrImpl().ErasePersistentInfo();
123 template <class ImplClass>
124 inline ConnectivityManager::ThreadDeviceType GenericConnectivityManagerImpl_Thread<ImplClass>::_GetThreadDeviceType()
126 return ThreadStackMgrImpl().GetThreadDeviceType();
129 template <class ImplClass>
131 GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType)
133 return ThreadStackMgrImpl().SetThreadDeviceType(deviceType);
136 template <class ImplClass>
138 GenericConnectivityManagerImpl_Thread<ImplClass>::_GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig)
140 ThreadStackMgrImpl().GetThreadPollingConfig(pollingConfig);
143 template <class ImplClass>
144 inline CHIP_ERROR GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadPollingConfig(
145 const ConnectivityManager::ThreadPollingConfig & pollingConfig)
147 return ThreadStackMgrImpl().SetThreadPollingConfig(pollingConfig);
150 template <class ImplClass>
151 inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_HaveServiceConnectivityViaThread()
153 return GetFlag(mFlags, kFlag_HaveServiceConnectivity);
156 } // namespace Internal
157 } // namespace DeviceLayer