//do nothing
break;
case BT_ERROR_NOW_IN_PROGRESS:
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is busy");
+ ret = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is busy",
+ ("StateChangedCB result: %d (%s)", result, get_error_message(result)));
break;
default:
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("StateChangedCB result: %d (%s)", result, get_error_message(result)));
}
adapter->instance_.AsyncResponse(adapter->user_request_callback_[SET_POWERED], ret);
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (BT_ERROR_NONE != result) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("VisibilityChangedCB error: %d (%s)", result, get_error_message(result)));
}
adapter->instance_.AsyncResponse(adapter->user_request_callback_[SET_VISIBLE], ret);
data_obj->insert(std::make_pair(kAction, picojson::value(kOnDiscoverStarted)));
adapter->instance_.FireEvent(kAdapterDiscoverSuccessEvent, value);
} else {
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), data_obj);
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), data_obj,
+ ("Wrong discovery state: %d", discovery_state));
adapter->instance_.FireEvent(kAdapterDiscoverErrorEvent, value);
adapter->user_request_list_[DISCOVER_DEVICES] = false;
}
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
instance_.AsyncResponse(callback_handle, result);
return;
}
}
if (this->user_request_list_[SET_NAME]) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
instance_.AsyncResponse(callback_handle, result);
return;
}
this->requested_name_ = name;
break;
case BT_ERROR_INVALID_PARAMETER:
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_adapter_set_name error: %d (%s)", ret, get_error_message(ret)));
break;
default:
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_adapter_set_name error: %d (%s)", ret, get_error_message(ret)));
}
} else {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
if (result.IsError()) {
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (ret.IsSuccess() && this->user_request_list_[SET_POWERED]) {
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ ret = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
}
bool cur_powered = this->get_powered();
int err = 0;
if ((err = app_control_create(&service)) != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control create failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control create failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control create failed",
+ ("app control create failed: %d", err));
}
if (ret.IsSuccess()) {
err = app_control_set_operation(service, "http://tizen.org/appcontrol/operation/edit");
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set operation failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set operation failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control set operation failed",
+ ("app control set operation failed: %d", err));
}
}
if (ret.IsSuccess()) {
err = app_control_set_mime(service, "application/x-bluetooth-on-off");
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set mime failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set mime failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control set mime failed",
+ ("app control set mime failed: %d", err));
}
}
free(result);
} else {
LoggerE("app control setPowered failed");
- data->adapter->instance_.AsyncResponse(data->callback_handle, PlatformResult(ErrorCode::UNKNOWN_ERR, "app control setPowered failed"));
+ data->adapter->instance_.AsyncResponse(
+ data->callback_handle,
+ LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control setPowered failed"));
}
delete data;
}, user_data);
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set launch request failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set launch request failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control set launch request failed",
+ ("app control set launch request failed: %d", err));
} else {
this->requested_powered_ = new_powered;
this->user_request_list_[SET_POWERED] = true;
err = app_control_destroy(service);
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control destroy failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control destroy failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control destroy failed",
+ ("app control destroy failed: %d", err));
}
if (!ret) {
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (ret.IsSuccess() && this->user_request_list_[SET_VISIBLE]) {
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ ret = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
}
if (ret.IsSuccess() && this->get_powered()) {
bt_adapter_visibility_mode_e cur_mode = BT_ADAPTER_VISIBILITY_MODE_NON_DISCOVERABLE;
int cur_timeout = 0;
- if (BT_ERROR_NONE != bt_adapter_get_visibility(&cur_mode , &cur_timeout)) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ int ntv_ret = bt_adapter_get_visibility(&cur_mode , &cur_timeout);
+ if (BT_ERROR_NONE != ntv_ret) {
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_adapter_get_visibility error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
if (ret.IsSuccess() && new_mode == cur_mode) {
int err = 0;
if ((err = app_control_create(&service)) != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control create failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control create failed");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control create failed",
+ ("app control create failed: %d (%s)", err, get_error_message(err)));
}
if (ret.IsSuccess()) {
err = app_control_set_operation(service, "http://tizen.org/appcontrol/operation/edit");
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set operation failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set operation failed");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control set operation failed",
+ ("app control set operation failed: %d (%s)", err, get_error_message(err)));
}
}
if (ret.IsSuccess()) {
err = app_control_set_mime(service, "application/x-bluetooth-visibility");
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set mime failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set mime failed");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control set mime failed",
+ ("app control set mime failed: %d (%s)", err, get_error_message(err)));
}
}
self->user_request_list_[SET_VISIBLE] = true;
self->user_request_callback_[SET_VISIBLE] = *p_callback_handle;
} else {
- LoggerE("app control setVisible failed");
- *p_ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control setVisible failed");
+ *p_ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control setVisible failed");
}
}, t_param);
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control set launch request failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control set launch request failed");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "app control set launch request failed",
+ ("app control set launch request failed: %d (%s)", err, get_error_message(err)));
}
}
err = app_control_destroy(service);
if (err != APP_CONTROL_ERROR_NONE) {
- LoggerE("app control destroy failed: %d", err);
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "app control destroy failed");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "app control destroy failed",
+ ("app control destroy failed: %d (%s)", err, get_error_message(err)));
}
#else
this->requested_visibility_ = new_mode;
this->user_request_list_[SET_VISIBLE] = true;
this->user_request_callback_[SET_VISIBLE] = callback_handle;
- int ret = bt_adapter_set_visibility(new_mode, new_timeout);
+ int ntv_ret = bt_adapter_set_visibility(new_mode, new_timeout);
- switch(ret) {
+ switch(ntv_ret) {
case BT_ERROR_NONE:
//bt_adapter_visibility_mode_changed_cb() will be invoked
//if this function returns #BT_ERROR_NONE
break;
case BT_ERROR_INVALID_PARAMETER:
- ret = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ ret = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_adapter_set_visibility error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
break;
default:
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_adapter_set_visibility error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
#endif
}
} else if (ret.IsSuccess()){
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ ret = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
instance_.AsyncResponse(callback_handle, ret);
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!is_initialized_) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (result.IsSuccess() && this->user_request_list_[DISCOVER_DEVICES]) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
}
if (result.IsSuccess() && !get_powered()) {
- result = PlatformResult(
+ result = LogAndCreateResult(
ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
std::shared_ptr<picojson::value> response =
std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- ReportError(result, &response->get<picojson::object>());
+ LogAndReportError(result, &response->get<picojson::object>());
TaskQueue::GetInstance().Async<picojson::value>([this](const std::shared_ptr<picojson::value>& result) {
instance_.FireEvent(kAdapterDiscoverErrorEvent, result);
}, response);
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (result.IsSuccess() && this->user_request_list_[STOP_DISCOVERY]) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
}
if (result.IsSuccess() && this->get_powered()) {
}
default: {
this->user_request_list_[STOP_DISCOVERY] = false;
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_adapter_stop_device_discovery error: %d (%s)", ret, get_error_message(ret)));
}
}
} else if (result.IsSuccess()) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
if (result.IsError()) {
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (ret.IsSuccess() && this->get_powered()) {
array = discovered_devices_;
- if (BT_ERROR_NONE == bt_adapter_foreach_bonded_device(ForeachBondedDevicesCB, &array)) {
+ int ntv_ret = bt_adapter_foreach_bonded_device(ForeachBondedDevicesCB, &array);
+ if (BT_ERROR_NONE == ntv_ret) {
ReportSuccess(result, response_obj);
} else {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_adapter_foreach_bonded_device error %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
} else if (ret.IsSuccess()) {
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ ret = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
if (ret.IsError()) {
- ReportError(ret, &response->get<picojson::object>());
+ LogAndReportError(ret, &response->get<picojson::object>());
}
};
auto get_known_devices_response = [this, callback_handle](
auto get_device = [this, address](const std::shared_ptr<picojson::value>& response) -> void {
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (!IsValidAddress(address)) {
- ret = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Wrong address");
+ ret = LogAndCreateResult(ErrorCode::NOT_FOUND_ERR, "Wrong address");
}
if (ret.IsSuccess() && !this->is_initialized()) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ ret = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (ret.IsSuccess() && this->get_powered()) {
picojson::object& response_obj = response->get<picojson::object>();
}
}
} else {
- ret = PlatformResult(ErrorCode::NOT_FOUND_ERR, "There is no device with the given address");
+ ret = LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "There is no device with the given address",
+ ("There is no device with the given address: %s", address.c_str()));
}
} else if (ret.IsSuccess()) {
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ ret = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
if (ret.IsError()) {
- ReportError(ret, &response->get<picojson::object>());
+ LogAndReportError(ret, &response->get<picojson::object>());
}
};
LoggerD("Entered");
if (result.IsError()) {
- ReportError(result, &response->get<picojson::object>());
+ LogAndReportError(result, &response->get<picojson::object>());
} else {
ReportSuccess(response->get<picojson::object>());
}
auto create_bonding = [address, callback_handle, this]() -> void {
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if(!IsValidAddress(address)) {
- result = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Wrong address");
+ result = LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "Wrong address",
+ ("Wrong address: %s", address.c_str()));
}
if (result.IsSuccess() && !this->is_initialized()) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (result.IsSuccess() && this->get_powered()) {
result_obj["address"] = picojson::value(handler->address());
ReportSuccess(result, response_obj);
} else if (BT_ERROR_REMOTE_DEVICE_NOT_FOUND == callback_result) {
- LoggerE("Not found");
- ret = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Not found");
+ ret = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Not found",
+ ("bond_create_callback result: %d (%s)", callback_result,
+ get_error_message(callback_result)));
} else {
- LoggerE("Unknown exception");
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bond_create_callback result: %d (%s)", callback_result,
+ get_error_message(callback_result)));
}
handler->Invoke(ret, response);
}
case BT_ERROR_INVALID_PARAMETER:
{
- LoggerE("Not found");
bt_device_unset_bond_created_cb();
delete handler;
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_device_create_bond error: %d (%s)", ret, get_error_message(ret)));
break;
}
default:
{
- LoggerE("Unknown exception");
bt_device_unset_bond_created_cb();
delete handler;
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_device_create_bond error: %d (%s)", ret, get_error_message(ret)));
}
}
} else if (result.IsSuccess()) {
- LoggerE("Bluetooth device is turned off");
- result = PlatformResult(
- ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR,
+ "Bluetooth device is turned off");
}
if (result.IsError()) {
auto destroy_bonding = [address, callback_handle, this]() -> void {
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if(!IsValidAddress(address)) {
- result = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Wrong address");
+ result = LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "Wrong address",
+ ("Wrong address: %s", address.c_str()));
}
if (result.IsSuccess() && !this->is_initialized()) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (result.IsSuccess() && this->get_powered()) {
int ret = bt_adapter_get_bonded_device_info(address.c_str(), &device_info);
if (BT_ERROR_NONE != ret || nullptr == device_info) {
- LoggerD("There is no bonding");
- result = PlatformResult(ErrorCode::NOT_FOUND_ERR, "Not found");
+ result = LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "Not found",
+ ("There is no bonding %d (%s)", ret, get_error_message(ret)));
} else {
bt_adapter_free_device_info(device_info);
if (!strcmp(address.c_str(), r_address.c_str())) { // requested event
if (BT_ERROR_NONE != callback_result) {
- LoggerE("Unknown exception");
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bond_destroy_callback result error: %d (%s)",
+ callback_result,
+ get_error_message(callback_result)));
}
handler->Invoke(ret, response);
}
case BT_ERROR_INVALID_PARAMETER:
{
- LoggerE("Not found");
bt_device_unset_bond_destroyed_cb();
delete handler;
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_device_destroy_bond error: %d (%s)", ret, get_error_message(ret)));
break;
}
default:
{
- LoggerE("Unknown exception");
bt_device_unset_bond_destroyed_cb();
delete handler;
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_device_destroy_bond error: %d (%s)", ret, get_error_message(ret)));
}
}
}
} else if (result.IsSuccess()) {
- LoggerE("Bluetooth device is turned off");
- result = PlatformResult(
+ result = LogAndCreateResult(
ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
auto rfcomm = [this, uuid, name](const std::shared_ptr<picojson::value>& response) -> void {
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!this->is_initialized()) {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ result = LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
}
if (result.IsSuccess() && !IsValidUUID(uuid)) {
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Wrong UUID",
+ ("Wrong UUID: %s", uuid.c_str()));
}
if (result.IsSuccess() && this->get_powered()) {
int ret = bt_adapter_is_service_used(uuid.c_str(), &is_registered);
if (BT_ERROR_NONE == ret && is_registered) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested");
+ result = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Already requested",
+ ("bt_adapter_is_service_used error: %d (%s)", ret, get_error_message(ret)));
} else {
int socket = -1;
ret = bt_socket_create_rfcomm(uuid.c_str(), &socket);
}
case BT_ERROR_INVALID_PARAMETER: {
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_socket_listen_and_accept_rfcomm error: %d (%s)", ret_in, get_error_message(ret_in)));
break;
}
default: {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error",
+ ("bt_socket_listen_and_accept_rfcomm error: %d (%s)", ret_in, get_error_message(ret_in)));
break;
}
}
break;
}
case BT_ERROR_INVALID_PARAMETER:
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_socket_create_rfcomm error: %d (%s)", ret, get_error_message(ret)));
break;
default:
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error",
+ ("bt_socket_create_rfcomm error: %d (%s)", ret, get_error_message(ret)));
break;
}
}
} else if (result.IsSuccess()) {
- result = PlatformResult(
+ result = LogAndCreateResult(
ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
if (result.IsError()) {
- ReportError(result, &response->get<picojson::object>());
+ LogAndReportError(result, &response->get<picojson::object>());
}
};
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!IsValidUUID(uuid)) {
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Wrong UUID",
+ ("Wrong UUID: %s", uuid.c_str()));
}
if (result.IsSuccess() && is_powered_) {
auto iter = registered_uuids_.find(uuid);
if (iter != registered_uuids_.end()) {
- if (BT_ERROR_NONE == bt_socket_destroy_rfcomm(iter->second.first)) {
+ int ntv_ret = bt_socket_destroy_rfcomm(iter->second.first);
+ if (BT_ERROR_NONE == ntv_ret) {
registered_uuids_.erase(iter);
} else {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_socket_destroy_rfcomm error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
}
bt_socket_unset_connection_state_changed_cb();
}
} else if (result.IsSuccess()){
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
instance_.AsyncResponse(callback_handle, result);
}
if (!supported) {
- result = PlatformResult(
+ result = LogAndCreateResult(
ErrorCode::NOT_SUPPORTED_ERR, "Bluetooth health profile is not supported");
} else {
LoggerD("BT health profile is supported");
}
} else {
- result = PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Wrong profile type.");
+ result = LogAndCreateResult(ErrorCode::TYPE_MISMATCH_ERR, "Wrong profile type.");
}
if (result.IsSuccess()) {
ReportSuccess(out);
} else {
- ReportError(result, &out);
+ LogAndReportError(result, &out);
}
}
LoggerD("Entered");
if (!is_initialized_) {
- ReportError(PlatformResult(
+ LogAndReportError(PlatformResult(
ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized."), &out);
return;
}
ReportSuccess(BluetoothSocket::ToJson(connection), response->get<picojson::object>());
} else {
- ReportError(PlatformResult(
+ LogAndReportError(PlatformResult(
ErrorCode::NOT_FOUND_ERR, "Not found"), &response->get<picojson::object>());
}
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!IsValidUUID(uuid)) {
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Wrong UUID",
+ ("Wrong UUID: %s", uuid.c_str()));
}
if (result.IsSuccess() && is_powered_) {
case BT_ERROR_INVALID_PARAMETER:
case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_socket_connect_rfcomm error: %d (%s)", ret, get_error_message(ret)));
break;
default:
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error",
+ ("bt_socket_connect_rfcomm error: %d (%s)", ret, get_error_message(ret)));
break;
}
} else if (result.IsSuccess()) {
- result = PlatformResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(ErrorCode::SERVICE_NOT_AVAILABLE_ERR,
+ "Bluetooth device is turned off");
}
if (result.IsError()) {
auto iter = registered_uuids_.find(uuid);
if (iter == registered_uuids_.end()) {
- ReportError(PlatformResult(
- ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed."), &out);
+ LogAndReportError(PlatformResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed."), &out,
+ ("Invalid uuid was passed: %s", uuid.c_str()));
return;
}
PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
bool value = false;
bt_device_info_s *info = nullptr;
- if (bt_adapter_get_bonded_device_info(address.c_str(), &info) == BT_ERROR_NONE &&
- info != nullptr) {
+ int ntv_ret = bt_adapter_get_bonded_device_info(address.c_str(), &info);
+ if (BT_ERROR_NONE == ntv_ret && info != nullptr) {
if (kDeviceIsBonded == field) {
value = info->is_bonded;
} else if (kDeviceIsTrusted == field) {
} else if (kDeviceIsConnected == field) {
value = info->is_connected;
} else {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Wrong field passed.");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Wrong field passed.",
+ ("Wrong field passed: %s", field.c_str()));
}
bt_adapter_free_device_info(info);
} else {
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error",
+ ("bt_adapter_get_bonded_device_info error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
}
if (result.IsSuccess()) {
ReportSuccess(picojson::value(value), out);
} else {
- ReportError(result, &out);
+ LogAndReportError(result, &out);
}
}
bt_gatt_client_h client = GetGattClient(address);
if (nullptr == client) {
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to create the GATT client's handle");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
+ "Failed to create the GATT client's handle");
}
bt_gatt_h service = nullptr;
LoggerE("bt_gatt_client_get_service() error: %d", ret);
switch (ret) {
case BT_ERROR_NO_DATA:
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Service not found");
+ return LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "Service not found",
+ ("bt_gatt_client_get_service error: %d (%s)", ret, get_error_message(ret)));
case BT_ERROR_INVALID_PARAMETER:
- return PlatformResult(ErrorCode::NOT_FOUND_ERR, "Service UUID is invalid");
+ return LogAndCreateResult(
+ ErrorCode::NOT_FOUND_ERR, "Service UUID is invalid",
+ ("bt_gatt_client_get_service error: %d (%s)", ret, get_error_message(ret)));
default:
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get a service's GATT handle");
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to get a service's GATT handle",
+ ("bt_gatt_client_get_service error: %d (%s)", ret, get_error_message(ret)));
}
}
picojson::array array;
PlatformResult ret = GetServicesHelper(handle, address, &array);
if (ret.IsError()) {
- LoggerE("Error while getting services");
- ReportError(ret, &out);
+ LogAndReportError(ret, &out, ("Error while getting services"));
} else {
ReportSuccess(picojson::value(array), out);
}
LoggerD("Entered");
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- return PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected");
+ return LogAndCreateResult(
+ ErrorCode::INVALID_STATE_ERR, "Device is not connected",
+ ("Device with address %s is no longer connected", address.c_str()));
}
int ret = bt_gatt_service_foreach_included_services(
picojson::array array;
PlatformResult ret = GetCharacteristicsHelper(handle, address, uuid, &array);
if (ret.IsError()) {
- LoggerE("Error while getting characteristics");
- ReportError(ret, &out);
+ LogAndReportError(ret, &out, ("Error while getting characteristics"));
} else {
ReportSuccess(picojson::value(array), out);
}
LoggerD("Entered");
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- return PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected");
+ return LogAndCreateResult(
+ ErrorCode::INVALID_STATE_ERR, "Device is not connected",
+ ("Device with address %s is no longer connected", address.c_str()));
}
struct Data {
const std::string& address = args.get("address").get<std::string>();
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
+ ("Device with address %s is no longer connected", address.c_str()));
return;
}
if (plarform_res.IsSuccess()) {
ReportSuccess(byte_array, response->get<picojson::object>());
} else {
- ReportError(plarform_res, &response->get<picojson::object>());
+ LogAndReportError(plarform_res, &response->get<picojson::object>());
}
TaskQueue::GetInstance().Async<picojson::value>(
[service, callback_handle](const std::shared_ptr<picojson::value>& response) {
};
int ret = bt_gatt_client_read_value(handle, read_value, (void*)user_data);
if (BT_ERROR_NONE != ret) {
- LOGE("Couldn't register callback for read value");
+ LoggerE("Couldn't register callback for read value %d (%s)",
+ ret, get_error_message(ret));
}
ReportSuccess(out);
}
const std::string& address = args.get("address").get<std::string>();
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
+ ("Device with address %s is no longer connected", address.c_str()));
return;
}
if (ret.IsSuccess()) {
ReportSuccess(response->get<picojson::object>());
} else {
- ReportError(ret, &response->get<picojson::object>());
+ LogAndReportError(ret, &response->get<picojson::object>());
}
TaskQueue::GetInstance().Async<picojson::value>(
[service, callback_handle](const std::shared_ptr<picojson::value>& response) {
int ret = bt_gatt_set_value(handle, value_data.get(), value_size);
if (BT_ERROR_NONE != ret) {
- LoggerE("Couldn't set value");
std::shared_ptr<picojson::value> response =
std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- ReportError(util::GetBluetoothError(ret, "Failed to set value"),
- &response->get<picojson::object>());
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to set value"),
+ &response->get<picojson::object>(),
+ ("bt_gatt_set_value error: %d (%s)", ret, get_error_message(ret)));
TaskQueue::GetInstance().Async<picojson::value>(
[this, callback_handle](const std::shared_ptr<picojson::value>& response) {
instance_.SyncResponse(callback_handle, response);
ret = bt_gatt_client_write_value(handle, write_value, user_data);
if (BT_ERROR_NONE != ret) {
delete user_data;
- LoggerE("Couldn't register callback for write value");
+ LoggerE("Couldn't register callback for write value %d (%s)",
+ ret, get_error_message(ret));
}
}
ReportSuccess(out);
LoggerD("Entered");
const auto& address = args.get("address").get<std::string>();
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
+ ("Device with address %s is no longer connected", address.c_str()));
return;
}
int ret = bt_gatt_client_set_characteristic_value_changed_cb(handle, OnCharacteristicValueChanged, this);
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_gatt_client_set_characteristic_value_changed_cb() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to register listener"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to register listener"), &out,
+ ("bt_gatt_client_set_characteristic_value_changed_cb() failed with: %d (%s)",
+ ret, get_error_message(ret)));
} else {
gatt_characteristic_.push_back(handle);
ReportSuccess(out);
LoggerD("Entered");
const auto& address = args.get("address").get<std::string>();
if (!IsStillConnected(address)) {
- LoggerE("Device with address %s is no longer connected", address.c_str());
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Device is not connected"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Device is not connected"), &out,
+ ("Device with address %s is no longer connected", address.c_str()));
return;
}
int ret = bt_gatt_client_unset_characteristic_value_changed_cb(handle);
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to unregister listener"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to unregister listener"), &out,
+ ("bt_gatt_client_unset_characteristic_value_changed_cb() failed with: %d (%s)",
+ ret, get_error_message(ret)));
} else {
gatt_characteristic_.erase(std::remove(gatt_characteristic_.begin(), gatt_characteristic_.end(), handle), gatt_characteristic_.end());
ReportSuccess(out);
bt_gatt_client_h client = GetGattClient(address);
if (nullptr == client) {
- return PlatformResult(ErrorCode::UNKNOWN_ERR, "Unable to create client");
+ return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to create client");
}
auto foreach_callback = [](int total, int index, bt_gatt_h gatt_handle, void* user_data) -> bool {
if (BT_ERROR_NONE == ret) {
return PlatformResult(ErrorCode::NO_ERROR);
} else {
- LoggerE("Failed to get UUIDS: %d", ret);
return util::GetBluetoothError(ret, "Failed to get UUIDS");
}
}
unsigned int channel = common::stol(FromJson<std::string>(args, "channel"));
const auto& address = FromJson<std::string>(args, "address");
- if (BT_ERROR_NONE != bt_hdp_disconnect(address.c_str(), channel)) {
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ int ntv_ret = bt_hdp_disconnect(address.c_str(), channel);
+ if (BT_ERROR_NONE != ntv_ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out,
+ ("bt_hdp_disconnect error: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
return;
}
data_ptr[i] = static_cast<char>(binary_data[i].get<double>());
}
- if (BT_ERROR_NONE != bt_hdp_send_data(channel, data_ptr.get(), data_size)) {
- LoggerE("bt_hdp_send_data() failed");
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ int ntv_ret = bt_hdp_send_data(channel, data_ptr.get(), data_size);
+ if (BT_ERROR_NONE != ntv_ret) {
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out,
+ ("bt_hdp_send_data() failed: %d (%s)", ntv_ret, get_error_message(ntv_ret)));
return;
}
ReportSuccess(result, response->get<picojson::object>());
} else {
- LoggerE("Failed to establish a connection with health profile");
- ReportError(PlatformResult(
- ErrorCode::UNKNOWN_ERR, "Failed to establish a connection with health profile"),
- &response->get<picojson::object>());
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to establish a connection with health profile"),
+ &response->get<picojson::object>(),
+ ("OnConnected result: %d (%s)", result, get_error_message(result)));
}
object->instance_.AsyncResponse(request->second, response);
}
case BT_ERROR_NOT_ENABLED:
- LoggerE("Bluetooth device is turned off");
- platform_result = PlatformResult(
- ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ platform_result = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off",
+ ("bt_hdp_register_sink_app error %d (%s)", ret, get_error_message(ret)));
break;
default:
- LoggerE("bt_hdp_register_sink_app() failed: %d", ret);
- platform_result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ platform_result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown error",
+ ("bt_hdp_register_sink_app() failed: %d (%s)", ret, get_error_message(ret)));
break;
}
- ReportError(platform_result, &response->get<picojson::object>());
+ LogAndReportError(platform_result, &response->get<picojson::object>());
};
auto register_app_response = [this, callback_handle](const std::shared_ptr<picojson::value>& response) -> void {
}
case BT_ERROR_NOT_ENABLED:
- result = PlatformResult(
- ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off",
+ ("bt_hdp_connect_to_source error: %d (%s)", ret, get_error_message(ret)));
break;
case BT_ERROR_INVALID_PARAMETER:
case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
- result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ result = LogAndCreateResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value",
+ ("bt_hdp_connect_to_source error: %d (%s)", ret, get_error_message(ret)));
break;
default:
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("bt_hdp_connect_to_source error: %d (%s)", ret, get_error_message(ret)));
break;
}
break;
case BT_ERROR_NOT_ENABLED:
- LoggerE("Bluetooth device is turned off");
- result = PlatformResult(
- ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ result = LogAndCreateResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off",
+ ("Bluetooth device is turned off %d (%s)", ret, get_error_message(ret)));
break;
default:
LoggerE("bt_hdp_unregister_sink_app() failed: %d", ret);
- result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ result = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unknown exception",
+ ("Bluetooth device is turned off %d (%s)", ret, get_error_message(ret)));
break;
}
} else {
if (result.IsSuccess()) {
ReportSuccess(response->get<picojson::object>());
} else {
- ReportError(result, &response->get<picojson::object>());
+ LogAndReportError(result, &response->get<picojson::object>());
}
};
std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
if (result.IsError()) {
- tools::ReportError(result, &response->get<picojson::object>());
+ LogAndReportError(result, &response->get<picojson::object>());
} else {
- tools::ReportSuccess(response->get<picojson::object>());
+ ReportSuccess(response->get<picojson::object>());
}
TaskQueue::GetInstance().Async<picojson::value>([this, callback_handle](const std::shared_ptr<picojson::value>& response) {
if (BT_ERROR_NONE != ret) {
if (BT_ERROR_NOW_IN_PROGRESS == ret) {
- LoggerE("Scan in progress");
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Scan already in progress"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Scan already in progress"), &out,
+ ("Scan in progress %d (%s)", ret, get_error_message(ret)));
} else {
- LoggerE("Failed to start scan: %d", ret);
// other errors are reported asynchronously
picojson::value value = picojson::value(picojson::object());
picojson::object* data_obj = &value.get<picojson::object>();
data_obj->insert(std::make_pair(kAction, picojson::value(kOnScanError)));
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to start scan"), data_obj);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to start scan"), data_obj,
+ ("Failed to start scan: %d (%s)", ret, get_error_message(ret)));
instance_.FireEvent(kScanEvent, value);
}
} else {
int ret = bt_adapter_le_stop_scan();
if (BT_ERROR_NONE != ret && BT_ERROR_NOT_IN_PROGRESS != ret) {
- LoggerE("Failed to stop scan: %d", ret);
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to stop scan"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to stop scan"), &out,
+ ("Failed to stop scan: %d (%s)", ret, get_error_message(ret)));
} else {
scanning_ = false;
ReportSuccess(out);
!json_packet_type.is<std::string>() ||
!json_mode.is<std::string>() ||
!json_connectable.is<bool>()) {
- ReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected parameter type"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected parameter type"), &out);
return;
}
BluetoothLEAdvertiseData advertise_data;
if (!BluetoothLEAdvertiseData::Construct(json_advertise_data, &advertise_data)) {
- ReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of advertise data"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of advertise data"), &out);
return;
}
} 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);
+ LogAndReportError(
+ PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of packet type"), &out,
+ ("Wrong packet_type: %s", str_packet_type.c_str()));
return;
}
}
} else if ("LOW_ENERGY" == str_mode) {
mode = BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY;
} else {
- ReportError(PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of mode"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Unexpected value of mode"), &out,
+ ("Wrong mode: %s", str_mode.c_str()));
return;
}
}
if (nullptr != bt_advertiser_) {
- LoggerE("Advertise in progress");
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Advertise already in progress"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Advertise already in progress"), &out);
return;
}
int ret = bt_adapter_le_create_advertiser(&advertiser);
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_create_advertiser() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_create_advertiser() failed with: %d, (%s)", ret, get_error_message(ret)));
return;
}
ret = bt_adapter_le_set_advertising_device_name(advertiser, packet_type,
advertise_data.include_name());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_set_advertising_device_name() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_set_advertising_device_name() failed with: %d (%s)", ret, get_error_message(ret)));
return;
}
}
ret = bt_adapter_le_add_advertising_service_uuid(advertiser, packet_type,
i.c_str());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_add_advertising_service_uuid() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_add_advertising_service_uuid() failed with: %d (%s)", ret, get_error_message(ret)));
return;
}
}
packet_type,
i.c_str());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_add_advertising_service_solicitation_uuid() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_add_advertising_service_solicitation_uuid() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
}
ret = bt_adapter_le_set_advertising_appearance(advertiser, packet_type,
advertise_data.appearance());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_set_advertising_appearance() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_set_advertising_appearance() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
ret = bt_adapter_le_set_advertising_tx_power_level(advertiser, packet_type,
advertise_data.include_tx_power_level());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_set_advertising_tx_power_level() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_set_advertising_tx_power_level() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
}
service_data.data().c_str(),
service_data.data().length());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_add_advertising_service_data() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_add_advertising_service_data() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
}
(const char*)manufacturer_data.data(),
manufacturer_data.data_length());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_add_advertising_manufacturer_data() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_add_advertising_manufacturer_data() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
}
ret = bt_adapter_le_set_advertising_mode(advertiser, mode);
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_set_advertising_mode() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_set_advertising_mode() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
ret = bt_adapter_le_set_advertising_connectable(advertiser, json_connectable.get<bool>());
if (BT_ERROR_NONE != ret) {
- LoggerE("bt_adapter_le_set_advertising_connectable() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to create advertiser"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to create advertiser"), &out,
+ ("bt_adapter_le_set_advertising_connectable() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
ret = bt_adapter_le_start_advertising_new(advertiser, OnAdvertiseResult, this);
if (BT_ERROR_NONE != ret) {
if (BT_ERROR_NOW_IN_PROGRESS == ret) {
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR, "Advertise already in progress"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR, "Advertise already in progress"), &out,
+ ("bt_adapter_le_start_advertising_new error: %d (%s)", ret, get_error_message(ret)));
return;
}
- LoggerE("bt_adapter_le_start_advertising_new() failed with: %d", ret);
- ReportError(util::GetBluetoothError(ret, "Failed to start advertising"), &out);
+ LogAndReportError(
+ util::GetBluetoothError(ret, "Failed to start advertising"), &out,
+ ("bt_adapter_le_start_advertising_new() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
if (nullptr != bt_advertiser_) {
int ret = bt_adapter_le_stop_advertising(bt_advertiser_);
if (BT_ERROR_NONE != ret && BT_ERROR_NOT_IN_PROGRESS != ret) {
- LoggerE("bt_adapter_le_stop_advertising() failed with: %d", ret);
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to stop advertising"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to stop advertising"), &out,
+ ("bt_adapter_le_stop_advertising() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
ret = bt_adapter_le_destroy_advertiser(bt_advertiser_);
if (BT_ERROR_NONE != ret && BT_ERROR_NOT_IN_PROGRESS != ret) {
- LoggerE("bt_adapter_le_destroy_advertiser() failed with: %d", ret);
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to destroy advertiser"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to destroy advertiser"), &out,
+ ("bt_adapter_le_destroy_advertiser() failed with: %d (%s)",
+ ret, get_error_message(ret)));
return;
}
picojson::object* data_obj = &value.get<picojson::object>();
if (BT_ERROR_NONE != result) {
- LoggerE("Error during scanning: %d", result);
- ReportError(util::GetBluetoothError(result, "Error during scanning"), data_obj);
+ LogAndReportError(
+ util::GetBluetoothError(result, "Error during scanning"), data_obj,
+ ("Error during scanning: %d (%s)", result, get_error_message(result)));
data_obj->insert(std::make_pair(kAction, picojson::value(kOnScanError)));
} else {
// this is probably capi-network-bluetooth error: when scan is stopped info has 0x1 value
data_obj->insert(std::make_pair(kAction, picojson::value(kOnScanSuccess)));
data_obj->insert(std::make_pair(kData, data));
} else {
- LoggerE("Failed to parse Bluetooth LE device");
- ReportError(r, data_obj);
+ LogAndReportError(r, data_obj, ("Failed to parse Bluetooth LE device"));
data_obj->insert(std::make_pair(kAction, picojson::value(kOnScanError)));
}
}
picojson::object* data_obj = &value.get<picojson::object>();
if (BT_ERROR_NONE != result) {
- LoggerE("Error during advertising: %d", result);
- ReportError(util::GetBluetoothError(result, "Error during advertising"), data_obj);
+ LogAndReportError(
+ util::GetBluetoothError(result, "Error during advertising"), data_obj,
+ ("Error during advertising: %d (%s)", result, get_error_message(result)));
data_obj->insert(std::make_pair(kAction, picojson::value(kOnAdvertiseError)));
} else {
const char* state = (BT_ADAPTER_LE_ADVERTISING_STARTED == adv_state) ? "STARTED" : "STOPPED";
bool connected = false;
int ret = bt_device_is_profile_connected(address.c_str(), BT_PROFILE_GATT, &connected);
if (BT_ERROR_NONE != ret) {
- instance_.AsyncResponse(callback_handle,
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to disconnect."));
+ instance_.AsyncResponse(
+ callback_handle,
+ LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to disconnect.",
+ ("bt_device_is_profile_connected error: %d (%s)", ret, get_error_message(ret))));
return;
}
if (connected) {
- instance_.AsyncResponse(callback_handle,
- PlatformResult(ErrorCode::NO_ERROR));
+ instance_.AsyncResponse(
+ callback_handle,
+ PlatformResult(ErrorCode::NO_ERROR));
} else { // not connected yet
ret = bt_gatt_connect(address.c_str(), false);
if (BT_ERROR_NONE != ret) {
instance_.AsyncResponse(
callback_handle,
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to connect."));
+ LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to connect.",
+ ("bt_gatt_connect error: %d (%s)", ret, get_error_message(ret))));
return;
}
connecting_[address] = callback_handle;
if (BT_ERROR_NONE != ret) {
instance_.AsyncResponse(
callback_handle,
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to disconnect."));
+ LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to disconnect.",
+ ("bt_device_is_profile_connected error: %d (%s)", ret, get_error_message(ret))));
return;
}
if (!connected) {
- ReportError(PlatformResult(ErrorCode::INVALID_STATE_ERR,
- "Bluetooth low energy device is not connected"),
- &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::INVALID_STATE_ERR,
+ "Bluetooth low energy device is not connected"),
+ &out,
+ ("bt_device_is_profile_connected error: %d (%s)", ret, get_error_message(ret)));
return;
}
if (BT_ERROR_NONE != ret) {
instance_.AsyncResponse(
callback_handle,
- PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to disconnect."));
+ LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to disconnect.",
+ ("bt_gatt_disconnect error: %d (%s)", ret, get_error_message(ret))));
return;
}
auto it = is_connected_.find(address);
if (it == is_connected_.end()) {
- LoggerE("Bluetooth low energy device is not connected");
- ReportError(
+ LogAndReportError(
PlatformResult(ErrorCode::INVALID_STATE_ERR,
"Bluetooth low energy device is not connected"),
&out);
data_obj);
if (result.IsError()) {
- ReportError(result, &out);
+ LogAndReportError(result, &out);
} else {
ReportSuccess(response, out);
}
if (result) {
ReportSuccess(response, out);
} else {
- ReportError(result, &out);
+ LogAndReportError(result, &out);
}
}
PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR);
if (BT_ERROR_NONE != result) {
- ret = PlatformResult(ErrorCode::UNKNOWN_ERR,
- "Failed to get connection state");
+ ret = LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Failed to get connection state",
+ ("GattConnectionState error: %d (%s)", result, get_error_message(result)));
}
le_device->instance_.AsyncResponse(it->second, ret);
}
if (kBluetoothError == bt_socket_send_data(socket, data_ptr.get(), data_size)) {
- LoggerE("bt_socket_send_data() failed");
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out,
+ ("bt_socket_send_data() failed"));
return;
}
int socket = common::stol(FromJson<std::string>(args, "id"));
if (BT_ERROR_NONE != bt_socket_disconnect_rfcomm(socket)) {
- LoggerE("bt_socket_disconnect_rfcomm() failed");
- ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ LogAndReportError(
+ PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out,
+ ("bt_socket_disconnect_rfcomm() failed"));
return;
}
break;
}
- return PlatformResult(error,
- hint + " : " + GetBluetoothErrorMessage(error_code));
+ std::string message = hint + " : " + GetBluetoothErrorMessage(error_code);
+
+ return LogAndCreateResult(
+ error, message.c_str(),
+ ("%s %d (%s)", message.c_str(), error_code, get_error_message(error_code)));
}
std::string GetBluetoothErrorMessage(int error_code) {