Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / include / platform / internal / BLEManager.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2018 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  *          Defines the abstract interface for the Device Layer's
22  *          internal BLEManager object.
23  */
24
25 #pragma once
26
27 #include <platform/ConnectivityManager.h>
28 #include <support/CodeUtils.h>
29
30 #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
31
32 namespace chip {
33 namespace DeviceLayer {
34 namespace Internal {
35
36 class BLEManagerImpl;
37
38 /**
39  * Provides control over CHIPoBLE services and connectivity for a chip device.
40  *
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.
45  */
46 class BLEManager
47 {
48     using ImplClass = BLEManagerImpl;
49
50 public:
51     // ===== Members that define the internal interface of the BLEManager
52
53     using CHIPoBLEServiceMode = ConnectivityManager::CHIPoBLEServiceMode;
54     using BLEAdvertisingMode  = ConnectivityManager::BLEAdvertisingMode;
55
56     CHIP_ERROR Init();
57     CHIPoBLEServiceMode GetCHIPoBLEServiceMode();
58     CHIP_ERROR SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val);
59     bool IsAdvertisingEnabled();
60     CHIP_ERROR SetAdvertisingEnabled(bool val);
61     bool IsAdvertising();
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();
68
69 protected:
70     // Construction/destruction limited to subclasses.
71     BLEManager()  = default;
72     ~BLEManager() = default;
73
74     // No copy, move or assignment.
75     BLEManager(const BLEManager &)  = delete;
76     BLEManager(const BLEManager &&) = delete;
77     BLEManager & operator=(const BLEManager &) = delete;
78 };
79
80 /**
81  * Returns a reference to the public interface of the BLEManager singleton object.
82  *
83  * Internal components should use this to access features of the BLEManager object
84  * that are common to all platforms.
85  */
86 extern BLEManager & BLEMgr();
87
88 /**
89  * Returns the platform-specific implementation of the BLEManager singleton object.
90  *
91  * chip applications can use this to gain access to features of the BLEManager
92  * that are specific to the selected platform.
93  */
94 extern BLEManagerImpl & BLEMgrImpl();
95
96 } // namespace Internal
97 } // namespace DeviceLayer
98 } // namespace chip
99
100 /* Include a header file containing the implementation of the BLEManager
101  * object for the selected platform.
102  */
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)
109
110 namespace chip {
111 namespace DeviceLayer {
112 namespace Internal {
113
114 inline CHIP_ERROR BLEManager::Init()
115 {
116     return static_cast<ImplClass *>(this)->_Init();
117 }
118
119 inline BLEManager::CHIPoBLEServiceMode BLEManager::GetCHIPoBLEServiceMode()
120 {
121     return static_cast<ImplClass *>(this)->_GetCHIPoBLEServiceMode();
122 }
123
124 inline CHIP_ERROR BLEManager::SetCHIPoBLEServiceMode(CHIPoBLEServiceMode val)
125 {
126     return static_cast<ImplClass *>(this)->_SetCHIPoBLEServiceMode(val);
127 }
128
129 inline bool BLEManager::IsAdvertisingEnabled()
130 {
131     return static_cast<ImplClass *>(this)->_IsAdvertisingEnabled();
132 }
133
134 inline CHIP_ERROR BLEManager::SetAdvertisingEnabled(bool val)
135 {
136     return static_cast<ImplClass *>(this)->_SetAdvertisingEnabled(val);
137 }
138
139 inline bool BLEManager::IsAdvertising()
140 {
141     return static_cast<ImplClass *>(this)->_IsAdvertising();
142 }
143
144 inline CHIP_ERROR BLEManager::SetAdvertisingMode(BLEAdvertisingMode mode)
145 {
146     return static_cast<ImplClass *>(this)->_SetAdvertisingMode(mode);
147 }
148
149 inline CHIP_ERROR BLEManager::GetDeviceName(char * buf, size_t bufSize)
150 {
151     return static_cast<ImplClass *>(this)->_GetDeviceName(buf, bufSize);
152 }
153
154 inline CHIP_ERROR BLEManager::SetDeviceName(const char * deviceName)
155 {
156     return static_cast<ImplClass *>(this)->_SetDeviceName(deviceName);
157 }
158
159 inline uint16_t BLEManager::NumConnections()
160 {
161     return static_cast<ImplClass *>(this)->_NumConnections();
162 }
163
164 inline void BLEManager::OnPlatformEvent(const ChipDeviceEvent * event)
165 {
166     return static_cast<ImplClass *>(this)->_OnPlatformEvent(event);
167 }
168
169 inline chip::Ble::BleLayer * BLEManager::GetBleLayer()
170 {
171     return static_cast<ImplClass *>(this)->_GetBleLayer();
172 }
173
174 } // namespace Internal
175 } // namespace DeviceLayer
176 } // namespace chip
177
178 #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE