| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <gflags/gflags.h> | 5 #include <gflags/gflags.h> |
| 6 #include <glib.h> | 6 #include <glib.h> |
| 7 | 7 |
| 8 #include "update_engine/dbus_constants.h" | 8 #include "update_engine/dbus_constants.h" |
| 9 #include "update_engine/subprocess.h" | 9 #include "update_engine/subprocess.h" |
| 10 #include "update_engine/utils.h" | 10 #include "update_engine/utils.h" |
| 11 | 11 |
| 12 extern "C" { | 12 extern "C" { |
| 13 #include "update_engine/update_engine.dbusclient.h" | 13 #include "update_engine/update_engine.dbusclient.h" |
| 14 } | 14 } |
| 15 | 15 |
| 16 using chromeos_update_engine::kUpdateEngineServiceName; | 16 using chromeos_update_engine::kUpdateEngineServiceName; |
| 17 using chromeos_update_engine::kUpdateEngineServicePath; | 17 using chromeos_update_engine::kUpdateEngineServicePath; |
| 18 using chromeos_update_engine::kUpdateEngineServiceInterface; | 18 using chromeos_update_engine::kUpdateEngineServiceInterface; |
| 19 using chromeos_update_engine::utils::GetGErrorMessage; |
| 19 | 20 |
| 20 DEFINE_bool(status, false, "Print the status to stdout."); | 21 DEFINE_bool(status, false, "Print the status to stdout."); |
| 21 DEFINE_bool(force_update, false, | 22 DEFINE_bool(force_update, false, |
| 22 "Force an update, even over an expensive network."); | 23 "Force an update, even over an expensive network."); |
| 23 DEFINE_bool(check_for_update, false, | 24 DEFINE_bool(check_for_update, false, |
| 24 "Initiate check for updates."); | 25 "Initiate check for updates."); |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const char* GetErrorMessage(const GError* error) { | |
| 29 if (!error) | |
| 30 return "Unknown error."; | |
| 31 return error->message; | |
| 32 } | |
| 33 | |
| 34 bool GetStatus() { | 29 bool GetStatus() { |
| 35 DBusGConnection *bus; | 30 DBusGConnection *bus; |
| 36 DBusGProxy *proxy; | 31 DBusGProxy *proxy; |
| 37 GError *error = NULL; | 32 GError *error = NULL; |
| 38 | 33 |
| 39 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 34 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
| 40 if (!bus) { | 35 if (!bus) { |
| 41 LOG(FATAL) << "Failed to get bus"; | 36 LOG(FATAL) << "Failed to get bus"; |
| 42 } | 37 } |
| 43 proxy = dbus_g_proxy_new_for_name_owner(bus, | 38 proxy = dbus_g_proxy_new_for_name_owner(bus, |
| 44 kUpdateEngineServiceName, | 39 kUpdateEngineServiceName, |
| 45 kUpdateEngineServicePath, | 40 kUpdateEngineServicePath, |
| 46 kUpdateEngineServiceInterface, | 41 kUpdateEngineServiceInterface, |
| 47 &error); | 42 &error); |
| 48 if (!proxy) { | 43 if (!proxy) { |
| 49 LOG(FATAL) << "Error getting proxy: " << GetErrorMessage(error); | 44 LOG(FATAL) << "Error getting proxy: " << GetGErrorMessage(error); |
| 50 } | 45 } |
| 51 | 46 |
| 52 gint64 last_checked_time = 0; | 47 gint64 last_checked_time = 0; |
| 53 gdouble progress = 0.0; | 48 gdouble progress = 0.0; |
| 54 char* current_op = NULL; | 49 char* current_op = NULL; |
| 55 char* new_version = NULL; | 50 char* new_version = NULL; |
| 56 gint64 new_size = 0; | 51 gint64 new_size = 0; |
| 57 | 52 |
| 58 gboolean rc = org_chromium_UpdateEngineInterface_get_status( | 53 gboolean rc = org_chromium_UpdateEngineInterface_get_status( |
| 59 proxy, | 54 proxy, |
| 60 &last_checked_time, | 55 &last_checked_time, |
| 61 &progress, | 56 &progress, |
| 62 ¤t_op, | 57 ¤t_op, |
| 63 &new_version, | 58 &new_version, |
| 64 &new_size, | 59 &new_size, |
| 65 &error); | 60 &error); |
| 66 if (rc == FALSE) { | 61 if (rc == FALSE) { |
| 67 LOG(INFO) << "Error getting status: " << GetErrorMessage(error); | 62 LOG(INFO) << "Error getting status: " << GetGErrorMessage(error); |
| 68 } | 63 } |
| 69 printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n" | 64 printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n" |
| 70 "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", | 65 "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", |
| 71 last_checked_time, | 66 last_checked_time, |
| 72 progress, | 67 progress, |
| 73 current_op, | 68 current_op, |
| 74 new_version, | 69 new_version, |
| 75 new_size); | 70 new_size); |
| 76 return true; | 71 return true; |
| 77 } | 72 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 103 LOG(INFO) << "Will not abort due to being on expensive network."; | 98 LOG(INFO) << "Will not abort due to being on expensive network."; |
| 104 } | 99 } |
| 105 CHECK(CheckForUpdates(FLAGS_force_update)) | 100 CHECK(CheckForUpdates(FLAGS_force_update)) |
| 106 << "Update check/initiate update failed."; | 101 << "Update check/initiate update failed."; |
| 107 return 0; | 102 return 0; |
| 108 } | 103 } |
| 109 | 104 |
| 110 LOG(INFO) << "No flags specified. Exiting."; | 105 LOG(INFO) << "No flags specified. Exiting."; |
| 111 return 0; | 106 return 0; |
| 112 } | 107 } |
| OLD | NEW |