From: Lukasz Bardeli Date: Thu, 7 Jul 2016 09:14:31 +0000 (+0200) Subject: [NBS] Added checking is service available X-Git-Tag: submit/tizen/20160708.104007~5^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F20%2F78720%2F3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [NBS] Added checking is service available Change-Id: I4238b53dbe09646966308f213a6c397e2d921bfd Signed-off-by: Lukasz Bardeli --- diff --git a/src/networkbearerselection/networkbearerselection_instance.cc b/src/networkbearerselection/networkbearerselection_instance.cc index 809c8361..babbebf1 100644 --- a/src/networkbearerselection/networkbearerselection_instance.cc +++ b/src/networkbearerselection/networkbearerselection_instance.cc @@ -80,6 +80,13 @@ void NetworkBearerSelectionInstance::NetworkBearerSelectionRequestRouteToHost( CHECK_EXIST(args, "domainName", out) CHECK_EXIST(args, "id", out) + const auto status = NetworkBearerSelectionManager::GetInstance()->getCellularState(); + + if (!status) { + LogAndReportError(status, &out, ("Failed to request route to host")); + return; + } + const std::string& domainName = args.get("domainName").get(); const int listenerId = static_cast(args.get("id").get()); diff --git a/src/networkbearerselection/networkbearerselection_manager.cc b/src/networkbearerselection/networkbearerselection_manager.cc index c77a37af..9d145ca6 100644 --- a/src/networkbearerselection/networkbearerselection_manager.cc +++ b/src/networkbearerselection/networkbearerselection_manager.cc @@ -191,6 +191,27 @@ void NetworkBearerSelectionManager::connection_closed_callback( } } +common::PlatformResult NetworkBearerSelectionManager::getCellularState() { + + connection_cellular_state_e state; + + int ret = connection_get_cellular_state(m_connection_handle_, &state); + + if (ret != CONNECTION_ERROR_NONE) { + LoggerE("Fail to get connection state. %d", ret); + return common::PlatformResult(GetNBSErrorCode(ret), + "Fail to get connection state."); + } + + if (state == CONNECTION_CELLULAR_STATE_OUT_OF_SERVICE) { + LoggerE("Network cellular have no service. %d", state); + return common::PlatformResult(common::ErrorCode::NOT_SUPPORTED_ERR, + "Fail to get connection state."); + } + return common::PlatformResult(common::ErrorCode::NO_ERROR); +} + + void NetworkBearerSelectionManager::requestRouteToHost( const std::string& domain_name) { LoggerD("NetworkBearerSelectionManager::requestRouteToHost"); @@ -486,5 +507,24 @@ ReleaseEventPtr NetworkBearerSelectionManager::getReleaseEvent(NetworkBearerSele return nullptr; } +common::ErrorCode NetworkBearerSelectionManager::GetNBSErrorCode(int error_code) { + + common::ErrorCode error = common::ErrorCode::UNKNOWN_ERR; + + switch (error_code) { + case CONNECTION_ERROR_OPERATION_FAILED: + error = common::ErrorCode::UNKNOWN_ERR; + break; + case CONNECTION_ERROR_NOT_SUPPORTED: + error = common::ErrorCode::NOT_SUPPORTED_ERR; + break; + default: + error = common::ErrorCode::UNKNOWN_ERR; + break; + } + + return error; +} + } // namespace networkbearerselection } // namespace extension diff --git a/src/networkbearerselection/networkbearerselection_manager.h b/src/networkbearerselection/networkbearerselection_manager.h index baddec50..7e45a58f 100644 --- a/src/networkbearerselection/networkbearerselection_manager.h +++ b/src/networkbearerselection/networkbearerselection_manager.h @@ -67,6 +67,8 @@ class NetworkBearerSelectionManager { common::PlatformResult releaseRouteToHost(const std::string& domain_name, const ReleaseReplyCallback& reply_cb); + common::PlatformResult getCellularState(); + static NetworkBearerSelectionManager* GetInstance(); NetworkBearerSelectionManager(const NetworkBearerSelectionManager&) = delete; @@ -89,6 +91,7 @@ class NetworkBearerSelectionManager { void makeErrorCallback(const std::string& domain_name, const char* info); void makeErrorCallback(const std::string& domain_name, const std::string& info); + common::ErrorCode GetNBSErrorCode(int error_code); void makeDisconnectCallback(const std::string& domain_name); void destroyProfileHandle(); RequestEventPtr getRequestEvent(NetworkBearerSelectionRequestEvent* event);