Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020-2021 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 generic implementation of ConnectivityManager features
22 : * for use on platforms that support Thread.
23 : */
24 :
25 : #pragma once
26 :
27 : #include <app/icd/server/ICDServerConfig.h>
28 : #include <lib/support/BitFlags.h>
29 : #include <platform/ThreadStackManager.h>
30 :
31 : #include <cstdint>
32 :
33 : namespace chip {
34 : namespace DeviceLayer {
35 :
36 : class ConnectivityManagerImpl;
37 :
38 : namespace Internal {
39 :
40 : /**
41 : * Provides a generic implementation of WiFi-specific ConnectivityManager features for
42 : * use on platforms that support Thread.
43 : *
44 : * This class is intended to be inherited (directly or indirectly) by the ConnectivityManagerImpl
45 : * class, which also appears as the template's ImplClass parameter.
46 : *
47 : * The GenericConnectivityManagerImpl_Thread<> class is designed to be independent of the particular
48 : * Thread stack in use, implying, for example, that the code does not make direct use of any OpenThread
49 : * APIs. This is achieved by delegating all stack-specific operations to the ThreadStackManager class.
50 : *
51 : */
52 : template <class ImplClass>
53 : class GenericConnectivityManagerImpl_Thread
54 : {
55 : protected:
56 : // ===== Methods that implement the ConnectivityManager abstract interface.
57 :
58 : void _Init();
59 : void _OnPlatformEvent(const ChipDeviceEvent * event);
60 : bool _IsThreadEnabled();
61 : ConnectivityManager::ThreadDeviceType _GetThreadDeviceType();
62 : CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
63 : #if CHIP_CONFIG_ENABLE_ICD_SERVER
64 : CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);
65 : #endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */
66 : bool _IsThreadAttached();
67 : bool _IsThreadProvisioned();
68 : void _ErasePersistentInfo();
69 : void _ResetThreadNetworkDiagnosticsCounts();
70 :
71 : // ===== Members for use by the implementation subclass.
72 :
73 : void UpdateServiceConnectivity();
74 :
75 : private:
76 : // ===== Private members reserved for use by this class only.
77 :
78 : enum class Flags : uint8_t
79 : {
80 : kHaveServiceConnectivity = 0x01,
81 : };
82 :
83 : BitFlags<Flags> mFlags;
84 :
85 : ImplClass * Impl() { return static_cast<ImplClass *>(this); }
86 : };
87 :
88 : template <class ImplClass>
89 48 : inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_Init()
90 : {
91 48 : mFlags.ClearAll();
92 48 : }
93 :
94 : template <class ImplClass>
95 : inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadEnabled()
96 : {
97 : return ThreadStackMgrImpl().IsThreadEnabled();
98 : }
99 :
100 : template <class ImplClass>
101 0 : inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadAttached()
102 : {
103 0 : return ThreadStackMgrImpl().IsThreadAttached();
104 : }
105 :
106 : template <class ImplClass>
107 0 : inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadProvisioned()
108 : {
109 0 : return ThreadStackMgrImpl().IsThreadProvisioned();
110 : }
111 :
112 : template <class ImplClass>
113 : inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ErasePersistentInfo()
114 : {
115 : ThreadStackMgrImpl().ErasePersistentInfo();
116 : }
117 :
118 : template <class ImplClass>
119 : inline ConnectivityManager::ThreadDeviceType GenericConnectivityManagerImpl_Thread<ImplClass>::_GetThreadDeviceType()
120 : {
121 : return ThreadStackMgrImpl().GetThreadDeviceType();
122 : }
123 :
124 : template <class ImplClass>
125 : inline CHIP_ERROR
126 : GenericConnectivityManagerImpl_Thread<ImplClass>::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType)
127 : {
128 : return ThreadStackMgrImpl().SetThreadDeviceType(deviceType);
129 : }
130 :
131 : #if CHIP_CONFIG_ENABLE_ICD_SERVER
132 : template <class ImplClass>
133 : inline CHIP_ERROR
134 : GenericConnectivityManagerImpl_Thread<ImplClass>::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval)
135 : {
136 : return ThreadStackMgrImpl().SetPollingInterval(pollingInterval);
137 : }
138 : #endif // CHIP_CONFIG_ENABLE_ICD_SERVER
139 :
140 : template <class ImplClass>
141 : inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ResetThreadNetworkDiagnosticsCounts()
142 : {
143 : ThreadStackMgrImpl().ResetThreadNetworkDiagnosticsCounts();
144 : }
145 :
146 : } // namespace Internal
147 : } // namespace DeviceLayer
148 : } // namespace chip
|