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 BLE.
27 #include <platform/internal/BLEManager.h>
30 namespace DeviceLayer {
32 class ConnectivityManagerImpl;
37 * Provides a generic implementation of BLE-specific ConnectivityManager features for
38 * platforms where BLE functionality is implemented by the BLEManager class.
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 majority of methods on this class simply forward calls to similarly-named methods on
44 * the BLEManager class. This arrangement, where the ConnectivityManager implementation delegates
45 * BLE support to the BLEManager class, is standard on platforms that support BLE, and helps to
46 * limit the complexity of the ConnectivityManagerImpl class.
48 template <class ImplClass>
49 class GenericConnectivityManagerImpl_BLE
52 // ===== Methods that implement the ConnectivityManager abstract interface.
54 Ble::BleLayer * _GetBleLayer();
55 ConnectivityManager::CHIPoBLEServiceMode _GetCHIPoBLEServiceMode();
56 CHIP_ERROR _SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val);
57 bool _IsBLEAdvertisingEnabled();
58 CHIP_ERROR _SetBLEAdvertisingEnabled(bool val);
59 bool _IsBLEAdvertising();
60 CHIP_ERROR _SetBLEAdvertisingMode(ConnectivityManager::BLEAdvertisingMode mode);
61 CHIP_ERROR _GetBLEDeviceName(char * buf, size_t bufSize);
62 CHIP_ERROR _SetBLEDeviceName(const char * deviceName);
63 uint16_t _NumBLEConnections();
64 static const char * _CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode);
67 ImplClass * Impl() { return static_cast<ImplClass *>(this); }
70 // Instruct the compiler to instantiate the template only when explicitly told to do so.
71 extern template class GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>;
73 template <class ImplClass>
74 inline Ble::BleLayer * GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBleLayer()
76 return BLEMgr().GetBleLayer();
79 template <class ImplClass>
80 inline ConnectivityManager::CHIPoBLEServiceMode GenericConnectivityManagerImpl_BLE<ImplClass>::_GetCHIPoBLEServiceMode()
82 return BLEMgr().GetCHIPoBLEServiceMode();
85 template <class ImplClass>
87 GenericConnectivityManagerImpl_BLE<ImplClass>::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val)
89 return BLEMgr().SetCHIPoBLEServiceMode(val);
92 template <class ImplClass>
93 inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertisingEnabled()
95 return BLEMgr().IsAdvertisingEnabled();
98 template <class ImplClass>
99 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingEnabled(bool val)
101 return BLEMgr().SetAdvertisingEnabled(val);
104 template <class ImplClass>
105 inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertising()
107 return BLEMgr().IsAdvertising();
110 template <class ImplClass>
112 GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingMode(ConnectivityManager::BLEAdvertisingMode mode)
114 return BLEMgr().SetAdvertisingMode(mode);
117 template <class ImplClass>
118 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBLEDeviceName(char * buf, size_t bufSize)
120 return BLEMgr().GetDeviceName(buf, bufSize);
123 template <class ImplClass>
124 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEDeviceName(const char * deviceName)
126 return BLEMgr().SetDeviceName(deviceName);
129 template <class ImplClass>
130 inline uint16_t GenericConnectivityManagerImpl_BLE<ImplClass>::_NumBLEConnections()
132 return BLEMgr().NumConnections();
135 } // namespace Internal
136 } // namespace DeviceLayer