AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
PulseAudioBluetoothInitializer.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #ifndef ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_PULSEAUDIOBLUETOOTHINITIALIZER_H_
17 #define ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_PULSEAUDIOBLUETOOTHINITIALIZER_H_
18 
19 #include <condition_variable>
20 #include <memory>
21 #include <mutex>
22 
25 
26 #include "pulse/pulseaudio.h"
27 
28 namespace alexaClientSDK {
29 namespace bluetoothImplementations {
30 namespace blueZ {
31 
56  , public std::enable_shared_from_this<PulseAudioBluetoothInitializer> {
57 public:
59  enum class ModuleState {
61  UNKNOWN,
65  UNLOADED,
68  };
69 
77  static std::shared_ptr<PulseAudioBluetoothInitializer> create(
78  std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> eventBus);
79 
84 
85 protected:
90 
91 private:
98  static void onStateChanged(pa_context* context, void* userdata);
99 
108  static void onModuleFound(pa_context* context, const pa_module_info* info, int eol, void* userData);
109 
117  static void onLoadPolicyResult(pa_context* context, uint32_t index, void* userdata);
118 
126  static void onLoadDiscoverResult(pa_context* context, uint32_t index, void* userdata);
127 
135  static void onUnloadPolicyResult(pa_context* context, int success, void* userdata);
136 
144  static void onUnloadDiscoverResult(pa_context* context, int success, void* userdata);
145 
153  void handleLoadModuleResult(pa_context* context, uint32_t index, const std::string& moduleName);
154 
162  void handleUnloadModuleResult(pa_context* context, int success, const std::string& moduleName);
163 
172  bool updateStateLocked(const ModuleState& state, const std::string& module);
173 
180  void setStateAndNotify(pa_context_state_t state);
181 
185  void init();
186 
190  void run();
191 
195  void cleanup();
196 
202  PulseAudioBluetoothInitializer(std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> eventBus);
203 
205  std::condition_variable m_mainThreadCv;
206 
208  std::mutex m_mutex;
209 
211  std::shared_ptr<avsCommon::utils::bluetooth::BluetoothEventBus> m_eventBus;
212 
214  pa_threaded_mainloop* m_paLoop;
215 
218  bool m_paLoopStarted;
219 
221  pa_context* m_context;
222 
224  ModuleState m_policyState;
225 
227  ModuleState m_discoverState;
228 
230  bool m_connected;
231 
234 };
235 
243  switch (state) {
245  return "UNKNOWN";
247  return "INITIALLY_LOADED";
249  return "UNLOADED";
251  return "LOADED_BY_SDK";
252  }
253 
254  return "INVALID";
255 }
256 
265 inline std::ostream& operator<<(std::ostream& stream, const PulseAudioBluetoothInitializer::ModuleState& state) {
266  return stream << moduleStateToString(state);
267 }
268 
269 } // namespace blueZ
270 } // namespace bluetoothImplementations
271 } // namespace alexaClientSDK
272 
273 #endif // ALEXA_CLIENT_SDK_BLUETOOTHIMPLEMENTATIONS_BLUEZ_INCLUDE_BLUEZ_PULSEAUDIOBLUETOOTHINITIALIZER_H_
std::string moduleStateToString(const PulseAudioBluetoothInitializer::ModuleState &state)
Definition: PulseAudioBluetoothInitializer.h:242
std::ostream & operator<<(std::ostream &stream, const BlueZBluetoothDevice::BlueZDeviceState &state)
Definition: BlueZBluetoothDevice.h:371
void onEventFired(const avsCommon::utils::bluetooth::BluetoothEvent &event) override
::std::string string
Definition: gtest-port.h:1097
Single-thread executor implementation.
Definition: Executor.h:45
static int index
Mock buffer index.
Definition: AndroidSLESMediaQueueTest.cpp:70
ModuleState
The state of each module.
Definition: PulseAudioBluetoothInitializer.h:59
static std::shared_ptr< PulseAudioBluetoothInitializer > create(std::shared_ptr< avsCommon::utils::bluetooth::BluetoothEventBus > eventBus)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
Base class for a BluetoothEvent.
Definition: BluetoothEvents.h:66

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0