*/
#include "bluetooth_class.h"
+#include "common/logger.h"
#include <map>
unsigned long BluetoothClass::GetMajorValue(bt_major_device_class_e major)
{
+ LoggerD("Enter");
auto iter = g_major_enum_map.find(major);
if (iter != g_major_enum_map.end()) {
return iter->second;
unsigned long BluetoothClass::GetMinorValue(bt_minor_device_class_e minor)
{
+ LoggerD("Enter");
auto iter = g_minor_enum_map.find(minor);
if (iter != g_minor_enum_map.end()) {
return iter->second;
std::vector<unsigned long> BluetoothClass::getServiceValues(int serviceMask)
{
+ LoggerD("Enter");
std::vector<unsigned long> ret;
for (auto iter = g_service_enum_map.begin(); iter != g_service_enum_map.end(); iter++) {
if (iter->first & serviceMask) {
return true;
}, static_cast<void*>(&user_data));
if (BT_ERROR_NONE != ret) {
+ LoggerE("Failed bt_gatt_service_foreach_included_services() (%d)", ret);
return util::GetBluetoothError(ret, "Failed to set a service's GATT callback");
}
}, static_cast<void*>(&desc_array));
if (BT_ERROR_NONE != ret) {
*platform_result = util::GetBluetoothError(ret, "Failed to get descriptors");
+ LoggerE("Failed bt_gatt_characteristic_foreach_descriptors() (%d)", ret);
return false;
}
return platform_result;
}
if (BT_ERROR_NONE != ret) {
+ LoggerE("Failed (%d)", ret);
return util::GetBluetoothError(ret, "Failed while getting characteristic");
}
void BluetoothHealthChannel::ToJson(unsigned int channel,
bt_hdp_channel_type_e type,
picojson::object* out) {
+ LoggerD("Enter");
const char* type_str = "UNKNOWN";
switch (type) {
bt_device_info_s* device_info,
const char* app_id,
picojson::object* out) {
+ LoggerD("Enter");
ToJson(channel, type, out);
auto& device = out->insert(
std::make_pair(kPeer, picojson::value(picojson::object()))) .first->second.get<picojson::object>();
BluetoothHealthProfileHandler::BluetoothHealthProfileHandler(BluetoothInstance& instance)
: instance_(instance) {
// initialize listeners
+ LoggerD("Entered");
if (BT_ERROR_NONE != bt_hdp_set_connection_state_changed_cb(OnConnected, OnDisconnected, this)) {
LoggerE("bt_hdp_set_connection_state_changed_cb() failed");
}
}
BluetoothHealthProfileHandler::~BluetoothHealthProfileHandler() {
+ LoggerD("Entered");
bt_hdp_unset_connection_state_changed_cb();
bt_hdp_unset_data_received_cb();
BluetoothHealthProfileHandler* object = static_cast<BluetoothHealthProfileHandler*>(user_data);
if (!object) {
- LoggerW("user_data is NULL");
+ LoggerE("user_data is NULL");
return;
}
BluetoothHealthProfileHandler* object = static_cast<BluetoothHealthProfileHandler*>(user_data);
if (!object) {
- LoggerW("user_data is NULL");
+ LoggerE("user_data is NULL");
return;
}
} // namespace
void BluetoothInstance::AsyncResponse(double callback_handle, const std::shared_ptr<picojson::value>& response) {
+ LoggerD("Entered");
common::TaskQueue::GetInstance().Async<picojson::value>([this, callback_handle](const std::shared_ptr<picojson::value>& response) {
SyncResponse(callback_handle, response);
}, response);
}
void BluetoothInstance::AsyncResponse(double callback_handle, const PlatformResult& result) {
+ LoggerD("Entered");
std::shared_ptr<picojson::value> response =
std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
}
void BluetoothInstance::SyncResponse(double callback_handle, const std::shared_ptr<picojson::value>& response) {
+ LoggerD("Entered");
auto& obj = response->get<picojson::object>();
obj[JSON_CALLBACK_ID] = picojson::value(callback_handle);
PostMessage(response->serialize().c_str());
}
void BluetoothInstance::FireEvent(const std::string& event, picojson::value& value) {
+ LoggerD("Entered");
auto& obj = value.get<picojson::object>();
obj[JSON_LISTENER_ID] = picojson::value(event);
PostMessage(value.serialize().c_str());
}
void BluetoothInstance::FireEvent(const std::string& event, const picojson::value& value) {
+ LoggerD("Entered");
picojson::value v{value};
FireEvent(event, v);
}
void BluetoothInstance::FireEvent(const std::string& event, const std::shared_ptr<picojson::value>& value) {
+ LoggerD("Entered");
FireEvent(event, *value.get());
}
private:
static bool ParseUUID(const picojson::value& obj,
BluetoothLEServiceData* out) {
+ LoggerD("Entered");
const auto& uuid = obj.get("serviceuuid");
if (uuid.is<std::string>()) {
out->uuid_ = uuid.get<std::string>();
static bool ParseData(const picojson::value& obj,
BluetoothLEServiceData* out) {
+ LoggerD("Entered");
const auto& data = obj.get("data");
if (data.is<std::string>()) {
out->data_ = data.get<std::string>();
static bool Construct(const picojson::value& obj,
BluetoothLEManufacturerData* out) {
+ LoggerD("Entered");
if (!obj.is<picojson::object>() ||
!ParseId(obj, out) ||
!ParseData(obj, out)) {
private:
static bool ParseId(const picojson::value& obj,
BluetoothLEManufacturerData* out) {
+ LoggerD("Entered");
const auto& id = obj.get("id");
if (id.is<std::string>()) {
try {
static bool ParseData(const picojson::value& obj,
BluetoothLEManufacturerData* out) {
+ LoggerD("Entered");
const auto& data = obj.get("data");
if (data.is<std::string>()) {
out->data_ = data.get<std::string>();
static bool Construct(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
if (!obj.is<picojson::object>() ||
!ParseIncludeName(obj, out) ||
!ParseServiceUUIDs(obj, out) ||
private:
static bool ParseIncludeName(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& include_name = obj.get("includeName");
if (include_name.is<bool>()) {
out->include_name_ = include_name.get<bool>();
static bool ParseServiceUUIDs(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& service_uuids = obj.get("serviceuuids");
if (service_uuids.is<picojson::array>()) {
for (const auto& i : service_uuids.get<picojson::array>()) {
static bool ParseSolicitationUUIDs(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& solicitation_uuids = obj.get("solicitationuuids");
if (solicitation_uuids.is<picojson::array>()) {
for (const auto& i : solicitation_uuids.get<picojson::array>()) {
static bool ParseAppearance(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& appearance = obj.get("appearance");
if (appearance.is<double>()) {
out->appearance_ = static_cast<decltype(appearance_)>(appearance.get<double>());
static bool ParseIncludeTxPowerLevel(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& include_tx_power_level = obj.get("includeTxPowerLevel");
if (include_tx_power_level.is<bool>()) {
out->include_tx_power_level_ = include_tx_power_level.get<bool>();
static bool ParseServiceData(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& service_data = obj.get("serviceData");
if (service_data.is<picojson::array>()) {
for (const auto& i : service_data.get<picojson::array>()) {
static bool ParseManufacturerData(const picojson::value& obj,
BluetoothLEAdvertiseData* out) {
+ LoggerD("Entered");
const auto& manufacturer_data = obj.get("manufacturerData");
BluetoothLEManufacturerData data;
if (BluetoothLEManufacturerData::Construct(manufacturer_data, &data)) {
}
BluetoothLEAdapter::~BluetoothLEAdapter() {
+ LoggerD("Entered");
bt_adapter_le_unset_state_changed_cb();
if (scanning_) {
bt_adapter_le_stop_scan();
} else if ("SCAN_RESPONSE" == str_packet_type) {
packet_type = BT_ADAPTER_LE_PACKET_SCAN_RESPONSE;
} else {
+ LoggerE("Fail: json_packet_type.get");
ReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of packet type"), &out);
return;
}
: instance_(instance),
service_(service),
is_listener_set_(false) {
+ LoggerD("Entered");
int ret = bt_gatt_set_connection_state_changed_cb(GattConnectionState, this);
if (BT_ERROR_NONE != ret && BT_ERROR_ALREADY_DONE != ret) {
LoggerE("Can't add connection state listener: %d", ret);
}
BluetoothLEDevice::~BluetoothLEDevice() {
+ LoggerD("Entered");
int ret = bt_gatt_unset_connection_state_changed_cb();
if (ret != BT_ERROR_NONE) {
LoggerW("Failed to unset listener: %d", ret);
PlatformResult BluetoothLEDevice::ToJson(
bt_adapter_le_device_scan_result_info_s* info,
picojson::object* le_device) {
+
LoggerD("Entered");
le_device->insert(