Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / include / platform / internal / GenericConnectivityManagerImpl_BLE.h
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     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);
65
66 private:
67     ImplClass * Impl() { return static_cast<ImplClass *>(this); }
68 };
69
70 // Instruct the compiler to instantiate the template only when explicitly told to do so.
71 extern template class GenericConnectivityManagerImpl_BLE<ConnectivityManagerImpl>;
72
73 template <class ImplClass>
74 inline Ble::BleLayer * GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBleLayer()
75 {
76     return BLEMgr().GetBleLayer();
77 }
78
79 template <class ImplClass>
80 inline ConnectivityManager::CHIPoBLEServiceMode GenericConnectivityManagerImpl_BLE<ImplClass>::_GetCHIPoBLEServiceMode()
81 {
82     return BLEMgr().GetCHIPoBLEServiceMode();
83 }
84
85 template <class ImplClass>
86 inline CHIP_ERROR
87 GenericConnectivityManagerImpl_BLE<ImplClass>::_SetCHIPoBLEServiceMode(ConnectivityManager::CHIPoBLEServiceMode val)
88 {
89     return BLEMgr().SetCHIPoBLEServiceMode(val);
90 }
91
92 template <class ImplClass>
93 inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertisingEnabled()
94 {
95     return BLEMgr().IsAdvertisingEnabled();
96 }
97
98 template <class ImplClass>
99 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingEnabled(bool val)
100 {
101     return BLEMgr().SetAdvertisingEnabled(val);
102 }
103
104 template <class ImplClass>
105 inline bool GenericConnectivityManagerImpl_BLE<ImplClass>::_IsBLEAdvertising()
106 {
107     return BLEMgr().IsAdvertising();
108 }
109
110 template <class ImplClass>
111 inline CHIP_ERROR
112 GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEAdvertisingMode(ConnectivityManager::BLEAdvertisingMode mode)
113 {
114     return BLEMgr().SetAdvertisingMode(mode);
115 }
116
117 template <class ImplClass>
118 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_GetBLEDeviceName(char * buf, size_t bufSize)
119 {
120     return BLEMgr().GetDeviceName(buf, bufSize);
121 }
122
123 template <class ImplClass>
124 inline CHIP_ERROR GenericConnectivityManagerImpl_BLE<ImplClass>::_SetBLEDeviceName(const char * deviceName)
125 {
126     return BLEMgr().SetDeviceName(deviceName);
127 }
128
129 template <class ImplClass>
130 inline uint16_t GenericConnectivityManagerImpl_BLE<ImplClass>::_NumBLEConnections()
131 {
132     return BLEMgr().NumConnections();
133 }
134
135 } // namespace Internal
136 } // namespace DeviceLayer
137 } // namespace chip