3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2018 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 * Defines the abstract interface for the Device Layer's
22 * internal BLEManager object.
27 #include <platform/ConnectivityManager.h>
28 #include <support/CodeUtils.h>
30 #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
33 namespace DeviceLayer {
39 * Provides control over CHIPoBLE services and connectivity for a chip device.
41 * BLEManager defines the abstract interface of a singleton object that provides
42 * control over CHIPoBLE services and connectivity for a chip device. BLEManager
43 * is an internal object that is used by other components with the chip Device
44 * Layer, but is not directly accessible to the application.
48 using ImplClass = BLEManagerImpl;
51 // ===== Members that define the internal interface of the BLEManager
53 using CHIPoBLEServiceMode = ConnectivityManager::CHIPoBLEServiceMode;
54 using BLEAdvertisingMode = ConnectivityManager::BLEAdvertisingMode;
57 CHIPoBLEServiceMode GetCHIPoBLEServiceMode();
58 CHIP_ERROR SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
59 bool IsAdvertisingEnabled();
60 CHIP_ERROR SetAdvertisingEnabled(bool val);
62 CHIP_ERROR SetAdvertisingMode(BLEAdvertisingMode mode);
63 CHIP_ERROR GetDeviceName(char * buf, size_t bufSize);
64 CHIP_ERROR SetDeviceName(const char * deviceName);
65 uint16_t NumConnections();
66 void OnPlatformEvent(const ChipDeviceEvent * event);
67 chip::Ble::BleLayer * GetBleLayer();
70 // Construction/destruction limited to subclasses.
71 BLEManager() = default;
72 ~BLEManager() = default;
74 // No copy, move or assignment.
75 BLEManager(const BLEManager &) = delete;
76 BLEManager(const BLEManager &&) = delete;
77 BLEManager & operator=(const BLEManager &) = delete;
81 * Returns a reference to the public interface of the BLEManager singleton object.
83 * Internal components should use this to access features of the BLEManager object
84 * that are common to all platforms.
86 extern BLEManager & BLEMgr();
89 * Returns the platform-specific implementation of the BLEManager singleton object.
91 * chip applications can use this to gain access to features of the BLEManager
92 * that are specific to the selected platform.
94 extern BLEManagerImpl & BLEMgrImpl();
96 } // namespace Internal
97 } // namespace DeviceLayer
100 /* Include a header file containing the implementation of the BLEManager
101 * object for the selected platform.
103 #ifdef EXTERNAL_BLEMANAGERIMPL_HEADER
104 #include EXTERNAL_BLEMANAGERIMPL_HEADER
105 #elif defined(CHIP_DEVICE_LAYER_TARGET)
106 #define BLEMANAGERIMPL_HEADER <platform/CHIP_DEVICE_LAYER_TARGET/BLEManagerImpl.h>
107 #include BLEMANAGERIMPL_HEADER
108 #endif // defined(CHIP_DEVICE_LAYER_TARGET)
111 namespace DeviceLayer {
114 inline CHIP_ERROR BLEManager::Init()
116 return static_cast<ImplClass *>(this)->_Init();
119 inline BLEManager::CHIPoBLEServiceMode BLEManager::GetCHIPoBLEServiceMode()
121 return static_cast<ImplClass *>(this)->_GetCHIPoBLEServiceMode();
124 inline CHIP_ERROR BLEManager::SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val)
126 return static_cast<ImplClass *>(this)->_SetCHIPoBLEServiceMode(val);
129 inline bool BLEManager::IsAdvertisingEnabled()
131 return static_cast<ImplClass *>(this)->_IsAdvertisingEnabled();
134 inline CHIP_ERROR BLEManager::SetAdvertisingEnabled(bool val)
136 return static_cast<ImplClass *>(this)->_SetAdvertisingEnabled(val);
139 inline bool BLEManager::IsAdvertising()
141 return static_cast<ImplClass *>(this)->_IsAdvertising();
144 inline CHIP_ERROR BLEManager::SetAdvertisingMode(BLEAdvertisingMode mode)
146 return static_cast<ImplClass *>(this)->_SetAdvertisingMode(mode);
149 inline CHIP_ERROR BLEManager::GetDeviceName(char * buf, size_t bufSize)
151 return static_cast<ImplClass *>(this)->_GetDeviceName(buf, bufSize);
154 inline CHIP_ERROR BLEManager::SetDeviceName(const char * deviceName)
156 return static_cast<ImplClass *>(this)->_SetDeviceName(deviceName);
159 inline uint16_t BLEManager::NumConnections()
161 return static_cast<ImplClass *>(this)->_NumConnections();
164 inline void BLEManager::OnPlatformEvent(const ChipDeviceEvent * event)
166 return static_cast<ImplClass *>(this)->_OnPlatformEvent(event);
169 inline chip::Ble::BleLayer * BLEManager::GetBleLayer()
171 return static_cast<ImplClass *>(this)->_GetBleLayer();
174 } // namespace Internal
175 } // namespace DeviceLayer
178 #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE