openauto/btservice/btservice.cpp
Robert Stanley Judka 23c38158ee
cleanup wireless device connection (#14)
* initial cleanup passthrough

* bad copypaste

* add back ! and more style fixes

* handling ping and voice session
2020-08-28 17:36:43 -05:00

44 lines
1.1 KiB
C++

#include "btservice/btservice.hpp"
namespace openauto
{
namespace btservice
{
btservice::btservice(openauto::configuration::IConfiguration::Pointer config)
: androidBluetoothService_(cServicePortNumber)
, androidBluetoothServer_(config)
{
QBluetoothAddress address;
auto adapters = QBluetoothLocalDevice::allDevices();
if(adapters.size() > 0)
{
address = adapters.at(0).address();
}
else
{
OPENAUTO_LOG(error) << "[btservice] No adapter found.";
}
if(!androidBluetoothServer_.start(address, cServicePortNumber))
{
OPENAUTO_LOG(error) << "[btservice] Server start failed.";
return;
}
OPENAUTO_LOG(info) << "[btservice] Listening for connections, address: " << address.toString().toStdString()
<< ", port: " << cServicePortNumber;
if(!androidBluetoothService_.registerService(address))
{
OPENAUTO_LOG(error) << "[btservice] Service registration failed.";
}
else
{
OPENAUTO_LOG(info) << "[btservice] Service registered, port: " << cServicePortNumber;
}
}
}
}