[Verification] Code compiles without errors.
Change-Id: I8a0a558ae8ed8969cdcfe80290f648bcd436e775
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
const auto& name = FromJson<std::string>(args, "name");
auto rfcomm = [this, uuid, name](const std::shared_ptr<picojson::value>& response) -> void {
- try {
- if (!this->is_initialized()) {
- throw UnknownException("Bluetooth service is not initialized.");
- }
-
- if (!IsValidUUID(uuid)) {
- throw InvalidValuesException("Wrong UUID");
- }
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+ if (!this->is_initialized()) {
+ result = PlatformResult(
+ ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized.");
+ }
- if (this->get_powered()) {
- bool is_registered = false;
- int ret = bt_adapter_is_service_used(uuid.c_str(), &is_registered);
+ if (result.IsSuccess() && !IsValidUUID(uuid)) {
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
+ }
- if (BT_ERROR_NONE == ret && is_registered) {
- throw InvalidValuesException("Already registered");
- }
+ if (result.IsSuccess() && this->get_powered()) {
+ bool is_registered = false;
+ 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");
+ } else {
int socket = -1;
ret = bt_socket_create_rfcomm(uuid.c_str(), &socket);
registered_uuids_.insert(std::make_pair(uuid,
std::make_pair(socket, false)));
- util::ReportSuccess(response->get<picojson::object>());
+ ReportSuccess(response->get<picojson::object>());
break;
}
case BT_ERROR_INVALID_PARAMETER: {
- throw InvalidValuesException("Invalid value");
+ result = PlatformResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid value");
break;
}
default: {
- throw UnknownException("Unknown error");
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
break;
}
}
break;
}
-
case BT_ERROR_INVALID_PARAMETER:
- throw InvalidValuesException("Invalid value");
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
break;
-
default:
- throw UnknownException("Unknown error");
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
break;
}
- } else {
- throw ServiceNotAvailableException("Bluetooth device is turned off");
}
- } catch (const PlatformException& err) {
- util::ReportError(err, response->get<picojson::object>());
+ } else if (result.IsSuccess()) {
+ result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ }
+
+ if (result.IsError()) {
+ ReportError(result, &response->get<picojson::object>());
}
};
TaskQueue::GetInstance().Queue<picojson::value>(rfcomm, rfcomm_response,
std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
- util::ReportSuccess(out);
+ ReportSuccess(out);
}
void BluetoothAdapter::UnregisterUUID(const std::string& uuid, int callback_handle) {
LoggerD("Entered");
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
if (!IsValidUUID(uuid)) {
- throw InvalidValuesException("Wrong UUID");
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
}
- std::shared_ptr<picojson::value> response =
- std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
-
- try {
- if (is_powered_) {
- auto iter = registered_uuids_.find(uuid);
- if (iter != registered_uuids_.end()) {
- if (BT_ERROR_NONE == bt_socket_destroy_rfcomm(iter->second.first)) {
- registered_uuids_.erase(iter);
- } else {
- throw UnknownException("Unknown error");
- }
- }
-
- if (registered_uuids_.size() == 0 &&
- connection_requests_.size() == 0 &&
- connected_sockets_.size() == 0) {
- bt_socket_unset_connection_state_changed_cb();
+ 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)) {
+ registered_uuids_.erase(iter);
+ } else {
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
}
- } else {
- throw ServiceNotAvailableException("Bluetooth device is turned off");
}
- util::ReportSuccess(response->get<picojson::object>());
- } catch (const PlatformException& err) {
- util::ReportError(err, response->get<picojson::object>());
+ if (registered_uuids_.size() == 0 &&
+ connection_requests_.size() == 0 &&
+ connected_sockets_.size() == 0) {
+ bt_socket_unset_connection_state_changed_cb();
+ }
+ } else if (result.IsSuccess()){
+ result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
}
- util::AsyncResponse(callback_handle, response);
+ util::AsyncResponse(callback_handle, result);
}
void BluetoothAdapter::GetBluetoothProfileHandler(const picojson::value& data,
const auto& args = util::GetArguments(data);
auto profile = FromJson<std::string>(args, "profileType");
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+
if (kBluetoothProfileHealth == profile) {
bool supported = false;
if (SYSTEM_INFO_ERROR_NONE != system_info_get_platform_bool(kFeatureBluetoothHealth.c_str(),
}
if (!supported) {
- throw NotSupportedException("Bluetooth health profile is not supported");
+ result = PlatformResult(
+ ErrorCode::NOT_SUPPORTED_ERR, "Bluetooth health profile is not supported");
} else {
LoggerD("BT health profile is supported");
}
} else {
- throw TypeMismatchException("Wrong profile type.");
+ result = PlatformResult(ErrorCode::TYPE_MISMATCH_ERR, "Wrong profile type.");
}
- util::ReportSuccess(out);
+ if (result.IsSuccess()) {
+ ReportSuccess(out);
+ } else {
+ ReportError(result, &out);
+ }
}
void BluetoothAdapter::GetName(const picojson::value& /* data */, picojson::object& out) {
LoggerD("Entered");
if (!is_initialized_) {
- throw UnknownException("Bluetooth service is not initialized.");
+ ReportError(PlatformResult(
+ ErrorCode::UNKNOWN_ERR, "Bluetooth service is not initialized."), &out);
+ return;
}
std::string str_address = "";
double callback_handle) {
LoggerD("Entered");
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+
if (!IsValidUUID(uuid)) {
- throw InvalidValuesException("Wrong UUID");
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Wrong UUID");
}
- try {
- if (is_powered_) {
- int ret = bt_socket_connect_rfcomm(address.c_str(), uuid.c_str());
-
- switch (ret) {
- case BT_ERROR_NONE: {
- LoggerD("bt_socket_connect_rfcomm() succeeded");
+ if (result.IsSuccess() && is_powered_) {
+ int ret = bt_socket_connect_rfcomm(address.c_str(), uuid.c_str());
- ConnectionRequestPtr request{new ConnectionRequest()};
- request->uuid_ = uuid;
- request->callback_handle_ = callback_handle;
- connection_requests_.insert(std::make_pair(address, request));
-
- bt_socket_set_connection_state_changed_cb(OnSocketConnected, this);
- break;
- }
+ switch (ret) {
+ case BT_ERROR_NONE: {
+ LoggerD("bt_socket_connect_rfcomm() succeeded");
- case BT_ERROR_INVALID_PARAMETER:
- case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
- throw InvalidValuesException("Invalid value");
- break;
+ ConnectionRequestPtr request{new ConnectionRequest()};
+ request->uuid_ = uuid;
+ request->callback_handle_ = callback_handle;
+ connection_requests_.insert(std::make_pair(address, request));
- default:
- throw UnknownException("Unknown error");
- break;
+ bt_socket_set_connection_state_changed_cb(OnSocketConnected, this);
+ break;
}
- } else {
- throw ServiceNotAvailableException("Bluetooth device is turned off");
+
+ case BT_ERROR_INVALID_PARAMETER:
+ case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ break;
+ default:
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ break;
}
- } catch (const PlatformException& e) {
- std::shared_ptr<picojson::value> response =
- std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- util::ReportError(e, response->get<picojson::object>());
- util::AsyncResponse(callback_handle, response);
+ } else if (result.IsSuccess()) {
+ result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ }
+
+ if (result.IsError()) {
+ util::AsyncResponse(callback_handle, result);
}
}
auto iter = registered_uuids_.find(uuid);
if (iter == registered_uuids_.end()) {
- throw InvalidValuesException("Invalid parameter was passed.");
+ ReportError(PlatformResult(
+ ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed."), &out);
+ return;
}
util::ReportSuccess(picojson::value(iter->second.second), out);
#include "common/converter.h"
#include "common/logger.h"
+#include "common/extension.h"
#include "bluetooth_adapter.h"
#include "bluetooth_class.h"
namespace bluetooth {
using namespace common;
+using namespace common::tools;
namespace {
//device
const auto& address = FromJson<std::string>(args, "address");
const auto& field = FromJson<std::string>(args, "field");
+ 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 &&
} else if (kDeviceIsConnected == field) {
value = info->is_connected;
} else {
- bt_adapter_free_device_info(info);
- throw UnknownException("Wrong field passed.");
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Wrong field passed.");
}
bt_adapter_free_device_info(info);
} else {
- throw UnknownException("Unknown error");
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
}
- util::ReportSuccess(picojson::value(value), out);
+ if (result.IsSuccess()) {
+ ReportSuccess(picojson::value(value), out);
+ } else {
+ ReportError(result, &out);
+ }
}
} // namespace bluetooth
#include "common/converter.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/extension.h"
#include "bluetooth_device.h"
#include "bluetooth_privilege.h"
namespace bluetooth {
using namespace common;
+using namespace common::tools;
namespace {
const std::string kPeer = "peer";
const auto& address = FromJson<std::string>(args, "address");
if (BT_ERROR_NONE != bt_hdp_disconnect(address.c_str(), channel)) {
- throw UnknownException("Unknown error");
+ ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ return;
}
util::ReportSuccess(out);
if (BT_ERROR_NONE != bt_hdp_send_data(channel, data_ptr.get(), data_size)) {
LoggerE("bt_hdp_send_data() failed");
- throw UnknownException("Unknown error");
+ ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ return;
}
util::ReportSuccess(picojson::value(static_cast<double>(data_size)), out);
#include "common/converter.h"
#include "common/logger.h"
-#include "common/platform_exception.h"
+#include "common/extension.h"
#include "common/task-queue.h"
#include "bluetooth_adapter.h"
namespace bluetooth {
using namespace common;
+using namespace common::tools;
namespace {
const std::string kId = "id";
auto register_app = [data_type, name, this](const std::shared_ptr<picojson::value>& response) -> void {
LoggerD("Entered");
- try {
- char* app_id = nullptr;
- const int ret = bt_hdp_register_sink_app(data_type, &app_id);
+ PlatformResult platform_result = PlatformResult(ErrorCode::NO_ERROR);
+ char* app_id = nullptr;
+ const int ret = bt_hdp_register_sink_app(data_type, &app_id);
- switch (ret) {
- case BT_ERROR_NONE:
- {
- LoggerD("Registered app: %s", app_id);
+ switch (ret) {
+ case BT_ERROR_NONE:
+ {
+ LoggerD("Registered app: %s", app_id);
- this->registered_health_apps_.insert(app_id);
+ this->registered_health_apps_.insert(app_id);
- picojson::value result = picojson::value(picojson::object());
- BluetoothHealthApplication::ToJson(data_type,
- name,
- app_id,
- &result.get<picojson::object>());
- util::ReportSuccess(result, response->get<picojson::object>());
- }
- break;
+ picojson::value result = picojson::value(picojson::object());
+ BluetoothHealthApplication::ToJson(data_type,
+ name,
+ app_id,
+ &result.get<picojson::object>());
+ util::ReportSuccess(result, response->get<picojson::object>());
+ return;
+ }
- case BT_ERROR_NOT_ENABLED:
- LoggerE("Bluetooth device is turned off");
- throw ServiceNotAvailableException("Bluetooth device is turned off");
- break;
+ case BT_ERROR_NOT_ENABLED:
+ LoggerE("Bluetooth device is turned off");
+ platform_result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ break;
- default:
- LoggerE("bt_hdp_register_sink_app() failed: %d", ret);
- throw UnknownException("Unknown error");
- break;
- }
- } catch (const PlatformException& e) {
- util::ReportError(e, response->get<picojson::object>());
+ default:
+ LoggerE("bt_hdp_register_sink_app() failed: %d", ret);
+ platform_result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error");
+ break;
}
+
+ ReportError(platform_result, &response->get<picojson::object>());
};
auto register_app_response = [callback_handle](const std::shared_ptr<picojson::value>& response) -> void {
const auto callback_handle = util::GetAsyncCallbackHandle(data);
- try {
- const int ret = bt_hdp_connect_to_source(address.c_str(), app_id.c_str());
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
+ const int ret = bt_hdp_connect_to_source(address.c_str(), app_id.c_str());
- switch (ret) {
- case BT_ERROR_NONE: {
- LoggerD("bt_hdp_connect_to_source() succeeded");
+ switch (ret) {
+ case BT_ERROR_NONE: {
+ LoggerD("bt_hdp_connect_to_source() succeeded");
- connection_requests_.insert(std::make_pair(app_id, callback_handle));
- break;
- }
+ connection_requests_.insert(std::make_pair(app_id, callback_handle));
+ break;
+ }
- case BT_ERROR_NOT_ENABLED:
- throw ServiceNotAvailableException("Bluetooth device is turned off");
- break;
+ case BT_ERROR_NOT_ENABLED:
+ result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ break;
- case BT_ERROR_INVALID_PARAMETER:
- case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
- throw InvalidValuesException("Invalid value");
- break;
+ case BT_ERROR_INVALID_PARAMETER:
+ case BT_ERROR_REMOTE_DEVICE_NOT_BONDED:
+ result = PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid value");
+ break;
- default:
- throw UnknownException("Unknown error");
- break;
- }
- } catch (const PlatformException& e) {
- LoggerD("Exception: %s", e.message().c_str());
- std::shared_ptr<picojson::value> response{new picojson::value(picojson::object())};
- util::ReportError(e, response->get<picojson::object>());
- util::AsyncResponse(callback_handle, response);
+ default:
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ break;
+ }
+
+ if (result.IsError()) {
+ util::AsyncResponse(callback_handle, result);
}
util::ReportSuccess(out);
auto unregister_app = [app_id, this](const std::shared_ptr<picojson::value>& response) -> void {
LoggerD("Entered");
+ PlatformResult result = PlatformResult(ErrorCode::NO_ERROR);
auto iter = this->registered_health_apps_.find(app_id);
if (iter != this->registered_health_apps_.end()) {
LoggerD("Found registered Health Application: %s", app_id.c_str());
- try {
- const int ret = bt_hdp_unregister_sink_app(app_id.c_str());
-
- switch(ret) {
- case BT_ERROR_NONE:
- this->registered_health_apps_.erase(iter);
- break;
-
- case BT_ERROR_NOT_ENABLED:
- LoggerE("Bluetooth device is turned off");
- throw ServiceNotAvailableException("Bluetooth device is turned off");
- break;
-
- default:
- LoggerE("bt_hdp_unregister_sink_app() failed: %d", ret);
- throw UnknownException("Unknown error");
- break;
- }
- } catch (const PlatformException& e) {
- util::ReportError(e, response->get<picojson::object>());
- return;
+ const int ret = bt_hdp_unregister_sink_app(app_id.c_str());
+
+ switch(ret) {
+ case BT_ERROR_NONE:
+ this->registered_health_apps_.erase(iter);
+ break;
+
+ case BT_ERROR_NOT_ENABLED:
+ LoggerE("Bluetooth device is turned off");
+ result = PlatformResult(
+ ErrorCode::SERVICE_NOT_AVAILABLE_ERR, "Bluetooth device is turned off");
+ break;
+
+ default:
+ LoggerE("bt_hdp_unregister_sink_app() failed: %d", ret);
+ result = PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown exception");
+ break;
}
} else {
LoggerD("Already unregistered");
}
- util::ReportSuccess(response->get<picojson::object>());
+ if (result.IsSuccess()) {
+ ReportSuccess(response->get<picojson::object>());
+ } else {
+ ReportError(result, &response->get<picojson::object>());
+ }
};
auto unregister_app_response = [callback_handle](const std::shared_ptr<picojson::value>& response) -> void {
#include "common/converter.h"
#include "common/logger.h"
+#include "common/extension.h"
#include "bluetooth_adapter.h"
#include "bluetooth_device.h"
}
using namespace common;
+using namespace common::tools;
void BluetoothSocket::WriteData(const picojson::value& data, picojson::object& out) {
LoggerD("Enter");
if (kBluetoothError == bt_socket_send_data(socket, data_ptr.get(), data_size)) {
LoggerE("bt_socket_send_data() failed");
- throw UnknownException("Unknown error");
+ ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ return;
}
util::ReportSuccess(picojson::value(static_cast<double>(data_size)), out);
if (BT_ERROR_NONE != bt_socket_disconnect_rfcomm(socket)) {
LoggerE("bt_socket_disconnect_rfcomm() failed");
- throw UnknownException("Unknown error");
+ ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error"), &out);
+ return;
}
util::ReportSuccess(out);