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

Side by Side 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, 7 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 unified diff | Download patch
« no previous file with comments | « src/platform/update_engine/update_engine.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <gflags/gflags.h>
6 #include <glib.h>
7
8 #include "update_engine/dbus_constants.h"
9 #include "update_engine/subprocess.h"
10 #include "update_engine/utils.h"
11
12 extern "C" {
13 #include "update_engine/update_engine.dbusclient.h"
14 }
15
16 using chromeos_update_engine::kUpdateEngineServiceName;
17 using chromeos_update_engine::kUpdateEngineServicePath;
18 using chromeos_update_engine::kUpdateEngineServiceInterface;
19
20 DEFINE_bool(status, false, "Print the status to stdout.");
21 DEFINE_bool(force_update, false,
22 "Force an update, even over an expensive network.");
23 DEFINE_bool(check_for_update, false,
24 "Initiate check for updates.");
25
26 namespace {
27
28 const char* GetErrorMessage(const GError* error) {
29 if (!error)
30 return "Unknown error.";
31 return error->message;
32 }
33
34 bool GetStatus() {
35 DBusGConnection *bus;
36 DBusGProxy *proxy;
37 GError *error = NULL;
38
39 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
40 if (!bus) {
41 LOG(FATAL) << "Failed to get bus";
42 }
43 proxy = dbus_g_proxy_new_for_name_owner(bus,
44 kUpdateEngineServiceName,
45 kUpdateEngineServicePath,
46 kUpdateEngineServiceInterface,
47 &error);
48 if (!proxy) {
49 LOG(FATAL) << "Error getting proxy: " << GetErrorMessage(error);
50 }
51
52 gint64 last_checked_time = 0;
53 gdouble progress = 0.0;
54 char* current_op = NULL;
55 char* new_version = NULL;
56 gint64 new_size = 0;
57
58 gboolean rc = org_chromium_UpdateEngineInterface_get_status(
59 proxy,
60 &last_checked_time,
61 &progress,
62 &current_op,
63 &new_version,
64 &new_size,
65 &error);
66 if (rc == FALSE) {
67 LOG(INFO) << "Error getting status: " << GetErrorMessage(error);
68 }
69 printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n"
70 "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n",
71 last_checked_time,
72 progress,
73 current_op,
74 new_version,
75 new_size);
76 return true;
77 }
78
79 bool CheckForUpdates(bool force) {
80 return true;
81 }
82
83 } // namespace {}
84
85 int main(int argc, char** argv) {
86 // Boilerplate init commands.
87 g_type_init();
88 g_thread_init(NULL);
89 dbus_g_thread_init();
90 chromeos_update_engine::Subprocess::Init();
91 google::ParseCommandLineFlags(&argc, &argv, true);
92
93 if (FLAGS_status) {
94 LOG(INFO) << "Querying Update Engine status...";
95 if (!GetStatus()) {
96 LOG(FATAL) << "GetStatus() failed.";
97 }
98 return 0;
99 }
100 if (FLAGS_force_update || FLAGS_check_for_update) {
101 LOG(INFO) << "Initiating update check and install.";
102 if (FLAGS_force_update) {
103 LOG(INFO) << "Will not abort due to being on expensive network.";
104 }
105 CHECK(CheckForUpdates(FLAGS_force_update))
106 << "Update check/initiate update failed.";
107 return 0;
108 }
109
110 LOG(INFO) << "No flags specified. Exiting.";
111 return 0;
112 }
OLDNEW
« 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