#include <base/logging.h>
#include "service/adapter.h"
+#include "service/hal/bluetooth_gatt_interface.h"
#include "service/hal/bluetooth_interface.h"
#include "service/ipc/ipc_manager.h"
#include "service/settings.h"
}
private:
+ bool StartUpBluetoothInterfaces() {
+ if (!hal::BluetoothInterface::Initialize())
+ goto failed;
+
+ if (!hal::BluetoothGattInterface::Initialize())
+ goto failed;
+
+ return true;
+
+ failed:
+ ShutDownBluetoothInterfaces();
+ return false;
+ }
+
+ void ShutDownBluetoothInterfaces() {
+ if (hal::BluetoothGattInterface::IsInitialized())
+ hal::BluetoothGattInterface::CleanUp();
+ if (hal::BluetoothInterface::IsInitialized())
+ hal::BluetoothInterface::CleanUp();
+ }
+
void CleanUpBluetoothStack() {
// The Adapter object needs to be cleaned up before the HAL interfaces.
ipc_manager_.reset();
adapter_.reset();
- hal::BluetoothInterface::CleanUp();
+ ShutDownBluetoothInterfaces();
}
bool SetUpIPC() {
// If an IPC socket path was given, initialize IPC with it. Otherwise
// initialize Binder IPC.
if (settings_->UseSocketIPC()) {
- if (!ipc_manager_->Start(ipc::IPCManager::TYPE_UNIX, nullptr)) {
+ if (!ipc_manager_->Start(ipc::IPCManager::TYPE_LINUX, nullptr)) {
LOG(ERROR) << "Failed to set up UNIX domain-socket IPCManager";
return false;
}
return false;
}
- if (!hal::BluetoothInterface::Initialize()) {
- LOG(ERROR) << "Failed to set up BluetoothInterface";
+ if (!StartUpBluetoothInterfaces()) {
+ LOG(ERROR) << "Failed to set up HAL Bluetooth interfaces";
return false;
}
- adapter_.reset(new Adapter());
+ adapter_ = Adapter::Create();
ipc_manager_.reset(new ipc::IPCManager(adapter_.get()));
if (!SetUpIPC()) {