Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020 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 BLE.
23 : */
24 :
25 : #pragma once
26 :
27 : #include <platform/internal/BLEManager.h>
28 :
29 : namespace chip {
30 : namespace DeviceLayer {
31 :
32 : class ConnectivityManagerImpl;
33 :
34 : namespace Internal {
35 :
36 : /**
37 : * Provides a generic implementation of BLE-specific ConnectivityManager features for
38 : * platforms where BLE functionality is implemented by the BLEManager class.
39 : *
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.
42 : *
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.
47 : */
48 : template <class ImplClass>
49 : class GenericConnectivityManagerImpl_BLE
50 : {
51 : public:
52 : // ===== Methods that implement the ConnectivityManager abstract interface.
53 :
54 : Ble::BleLayer * _GetBleLayer();
55 : bool _IsBLEAdvertisingEnabled();
56 : CHIP_ERROR _SetBLEAdvertisingEnabled(bool val);
57 : bool _IsBLEAdvertising();
58 : CHIP_ERROR _SetBLEAdvertisingMode(ConnectivityManager::BLEAdvertisingMode mode);
59 : CHIP_ERROR _GetBLEDeviceName(char * buf, size_t bufSize);
60 : CHIP_ERROR _SetBLEDeviceName(const char * deviceName);
61 : uint16_t _NumBLEConnections();
62 : static const char * _CHIPoBLEServiceModeToStr(ConnectivityManager::CHIPoBLEServiceMode mode);
63 :
64 : private:
65 0 : ImplClass * Impl() { return static_cast<ImplClass *>(this); }
66 : };
67 :
68 : // Instruct the compiler to instantiate the template only when explicitly told to do so.
69 : extern template class GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>;
70 :
71 : template <class ImplClass>
72 2 : inline Ble::BleLayer * GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBleLayer()
73 : {
74 2 : return BLEMgr().GetBleLayer();
75 : }
76 :
77 : template <class ImplClass>
78 5 : inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertisingEnabled()
79 : {
80 5 : return BLEMgr().IsAdvertisingEnabled();
81 : }
82 :
83 : template <class ImplClass>
84 2 : inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingEnabled(bool val)
85 : {
86 2 : return BLEMgr().SetAdvertisingEnabled(val);
87 : }
88 :
89 : template <class ImplClass>
90 0 : inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertising()
91 : {
92 0 : return BLEMgr().IsAdvertising();
93 : }
94 :
95 : template <class ImplClass>
96 : inline CHIP_ERROR
97 0 : GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingMode(ConnectivityManager::BLEAdvertisingMode mode)
98 : {
99 0 : return BLEMgr().SetAdvertisingMode(mode);
100 : }
101 :
102 : template <class ImplClass>
103 0 : inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBLEDeviceName(char * buf, size_t bufSize)
104 : {
105 0 : return BLEMgr().GetDeviceName(buf, bufSize);
106 : }
107 :
108 : template <class ImplClass>
109 0 : inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEDeviceName(const char * deviceName)
110 : {
111 0 : return BLEMgr().SetDeviceName(deviceName);
112 : }
113 :
114 : template <class ImplClass>
115 0 : inline uint16_t GenericConnectivityManagerImpl_BLE<ImplClass>::_NumBLEConnections()
116 : {
117 0 : return BLEMgr().NumConnections();
118 : }
119 :
120 : } // namespace Internal
121 : } // namespace DeviceLayer
122 : } // namespace chip
|