Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(761)

Unified Diff: src/platform/update_engine/update_engine_client.cc

Issue 1733013: AU: Beginnings of dbus support. (Closed)
Patch Set: fixes for wad's review Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/platform/update_engine/update_engine.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/update_engine/update_engine_client.cc
diff --git a/src/platform/update_engine/update_engine_client.cc b/src/platform/update_engine/update_engine_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e273ed036bcfe28104cc9636c627c4885974429
--- /dev/null
+++ b/src/platform/update_engine/update_engine_client.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <gflags/gflags.h>
+#include <glib.h>
+
+#include "update_engine/dbus_constants.h"
+#include "update_engine/subprocess.h"
+#include "update_engine/utils.h"
+
+extern "C" {
+#include "update_engine/update_engine.dbusclient.h"
+}
+
+using chromeos_update_engine::kUpdateEngineServiceName;
+using chromeos_update_engine::kUpdateEngineServicePath;
+using chromeos_update_engine::kUpdateEngineServiceInterface;
+
+DEFINE_bool(status, false, "Print the status to stdout.");
+DEFINE_bool(force_update, false,
+ "Force an update, even over an expensive network.");
+DEFINE_bool(check_for_update, false,
+ "Initiate check for updates.");
+
+namespace {
+
+const char* GetErrorMessage(const GError* error) {
+ if (!error)
+ return "Unknown error.";
+ return error->message;
+}
+
+bool GetStatus() {
+ DBusGConnection *bus;
+ DBusGProxy *proxy;
+ GError *error = NULL;
+
+ bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ LOG(FATAL) << "Failed to get bus";
+ }
+ proxy = dbus_g_proxy_new_for_name_owner(bus,
+ kUpdateEngineServiceName,
+ kUpdateEngineServicePath,
+ kUpdateEngineServiceInterface,
+ &error);
+ if (!proxy) {
+ LOG(FATAL) << "Error getting proxy: " << GetErrorMessage(error);
+ }
+
+ gint64 last_checked_time = 0;
+ gdouble progress = 0.0;
+ char* current_op = NULL;
+ char* new_version = NULL;
+ gint64 new_size = 0;
+
+ gboolean rc = org_chromium_UpdateEngineInterface_get_status(
+ proxy,
+ &last_checked_time,
+ &progress,
+ &current_op,
+ &new_version,
+ &new_size,
+ &error);
+ if (rc == FALSE) {
+ LOG(INFO) << "Error getting status: " << GetErrorMessage(error);
+ }
+ printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n"
+ "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n",
+ last_checked_time,
+ progress,
+ current_op,
+ new_version,
+ new_size);
+ return true;
+}
+
+bool CheckForUpdates(bool force) {
+ return true;
+}
+
+} // namespace {}
+
+int main(int argc, char** argv) {
+ // Boilerplate init commands.
+ g_type_init();
+ g_thread_init(NULL);
+ dbus_g_thread_init();
+ chromeos_update_engine::Subprocess::Init();
+ google::ParseCommandLineFlags(&argc, &argv, true);
+
+ if (FLAGS_status) {
+ LOG(INFO) << "Querying Update Engine status...";
+ if (!GetStatus()) {
+ LOG(FATAL) << "GetStatus() failed.";
+ }
+ return 0;
+ }
+ if (FLAGS_force_update || FLAGS_check_for_update) {
+ LOG(INFO) << "Initiating update check and install.";
+ if (FLAGS_force_update) {
+ LOG(INFO) << "Will not abort due to being on expensive network.";
+ }
+ CHECK(CheckForUpdates(FLAGS_force_update))
+ << "Update check/initiate update failed.";
+ return 0;
+ }
+
+ LOG(INFO) << "No flags specified. Exiting.";
+ return 0;
+}
« no previous file with comments | « src/platform/update_engine/update_engine.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698