connection_utils.cc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // Copyright (C) 2016 The Android Open Source Project
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #include "update_engine/connection_utils.h"
  17. #include <shill/dbus-constants.h>
  18. namespace {
  19. // Not defined by shill since we don't use this outside of UE.
  20. constexpr char kTypeDisconnected[] = "Disconnected";
  21. constexpr char kTypeUnknown[] = "Unknown";
  22. } // namespace
  23. namespace chromeos_update_engine {
  24. namespace connection_utils {
  25. ConnectionType ParseConnectionType(const std::string& type_str) {
  26. if (type_str == shill::kTypeEthernet) {
  27. return ConnectionType::kEthernet;
  28. } else if (type_str == shill::kTypeWifi) {
  29. return ConnectionType::kWifi;
  30. } else if (type_str == shill::kTypeWimax) {
  31. return ConnectionType::kWimax;
  32. } else if (type_str == shill::kTypeBluetooth) {
  33. return ConnectionType::kBluetooth;
  34. } else if (type_str == shill::kTypeCellular) {
  35. return ConnectionType::kCellular;
  36. } else if (type_str == kTypeDisconnected) {
  37. return ConnectionType::kDisconnected;
  38. }
  39. return ConnectionType::kUnknown;
  40. }
  41. ConnectionTethering ParseConnectionTethering(const std::string& tethering_str) {
  42. if (tethering_str == shill::kTetheringNotDetectedState) {
  43. return ConnectionTethering::kNotDetected;
  44. } else if (tethering_str == shill::kTetheringSuspectedState) {
  45. return ConnectionTethering::kSuspected;
  46. } else if (tethering_str == shill::kTetheringConfirmedState) {
  47. return ConnectionTethering::kConfirmed;
  48. }
  49. return ConnectionTethering::kUnknown;
  50. }
  51. const char* StringForConnectionType(ConnectionType type) {
  52. switch (type) {
  53. case ConnectionType::kEthernet:
  54. return shill::kTypeEthernet;
  55. case ConnectionType::kWifi:
  56. return shill::kTypeWifi;
  57. case ConnectionType::kWimax:
  58. return shill::kTypeWimax;
  59. case ConnectionType::kBluetooth:
  60. return shill::kTypeBluetooth;
  61. case ConnectionType::kCellular:
  62. return shill::kTypeCellular;
  63. case ConnectionType::kDisconnected:
  64. return kTypeDisconnected;
  65. case ConnectionType::kUnknown:
  66. return kTypeUnknown;
  67. }
  68. return kTypeUnknown;
  69. }
  70. } // namespace connection_utils
  71. } // namespace chromeos_update_engine