[NBS] Added checking is service available 20/78720/3
authorLukasz Bardeli <l.bardeli@samsung.com>
Thu, 7 Jul 2016 09:14:31 +0000 (11:14 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Thu, 7 Jul 2016 09:14:31 +0000 (11:14 +0200)
Change-Id: I4238b53dbe09646966308f213a6c397e2d921bfd
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
src/networkbearerselection/networkbearerselection_instance.cc
src/networkbearerselection/networkbearerselection_manager.cc
src/networkbearerselection/networkbearerselection_manager.h

index 809c83610b8f80ef7addacfe800b2ce1e632b52c..babbebf137b5949f7faa8cf97b1d735b6b0b7235 100644 (file)
@@ -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<std::string>();
   const int listenerId = static_cast<int>(args.get("id").get<double>());
 
index c77a37aff9ba363d9eec0b4054db0184de9e008e..9d145ca6583c8445f509361542c5e379153ba385 100644 (file)
@@ -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
index baddec504cd7b62ae12c2e99c5359eb3bf0b5153..7e45a58f6eff4396fa6410e3ea411c4b0a244d42 100644 (file)
@@ -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);