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

Side by Side Diff: update_engine_client.cc

Issue 2847054: AU: land http://codereview.chromium.org/2931008/show for tfarina (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 years, 5 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 | « no previous file | 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
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/marshal.glibmarshal.h" 8 #include "update_engine/marshal.glibmarshal.h"
9 #include "update_engine/dbus_constants.h" 9 #include "update_engine/dbus_constants.h"
10 #include "update_engine/subprocess.h" 10 #include "update_engine/subprocess.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 LOG(INFO) << " last_checked_time: " << last_checked_time; 61 LOG(INFO) << " last_checked_time: " << last_checked_time;
62 LOG(INFO) << " progress: " << progress; 62 LOG(INFO) << " progress: " << progress;
63 LOG(INFO) << " current_operation: " << current_operation; 63 LOG(INFO) << " current_operation: " << current_operation;
64 LOG(INFO) << " new_version: " << new_version; 64 LOG(INFO) << " new_version: " << new_version;
65 LOG(INFO) << " new_size: " << new_size; 65 LOG(INFO) << " new_size: " << new_size;
66 } 66 }
67 67
68 bool GetStatus() { 68 bool GetStatus() {
69 DBusGProxy* proxy; 69 DBusGProxy* proxy;
70 GError* error = NULL; 70 GError* error = NULL;
71 71
72 CHECK(GetProxy(&proxy)); 72 CHECK(GetProxy(&proxy));
73 73
74 gint64 last_checked_time = 0; 74 gint64 last_checked_time = 0;
75 gdouble progress = 0.0; 75 gdouble progress = 0.0;
76 char* current_op = NULL; 76 char* current_op = NULL;
77 char* new_version = NULL; 77 char* new_version = NULL;
78 gint64 new_size = 0; 78 gint64 new_size = 0;
79 79
80 gboolean rc = org_chromium_UpdateEngineInterface_get_status( 80 gboolean rc = org_chromium_UpdateEngineInterface_get_status(
81 proxy, 81 proxy,
(...skipping 12 matching lines...) Expand all
94 progress, 94 progress,
95 current_op, 95 current_op,
96 new_version, 96 new_version,
97 new_size); 97 new_size);
98 return true; 98 return true;
99 } 99 }
100 100
101 // Should never return. 101 // Should never return.
102 void WatchForUpdates() { 102 void WatchForUpdates() {
103 DBusGProxy* proxy; 103 DBusGProxy* proxy;
104 104
105 CHECK(GetProxy(&proxy)); 105 CHECK(GetProxy(&proxy));
106 106
107 // Register marshaller 107 // Register marshaller
108 dbus_g_object_register_marshaller( 108 dbus_g_object_register_marshaller(
109 update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64, 109 update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64,
110 G_TYPE_NONE, 110 G_TYPE_NONE,
111 G_TYPE_INT64, 111 G_TYPE_INT64,
112 G_TYPE_DOUBLE, 112 G_TYPE_DOUBLE,
113 G_TYPE_STRING, 113 G_TYPE_STRING,
114 G_TYPE_STRING, 114 G_TYPE_STRING,
115 G_TYPE_INT64, 115 G_TYPE_INT64,
116 G_TYPE_INVALID); 116 G_TYPE_INVALID);
117 117
118 // TODO(adlr): make StatusUpdate a const string 118 static const char kStatusUpdate[] = "StatusUpdate";
119 dbus_g_proxy_add_signal(proxy, 119 dbus_g_proxy_add_signal(proxy,
120 "StatusUpdate", 120 kStatusUpdate,
121 G_TYPE_INT64, 121 G_TYPE_INT64,
122 G_TYPE_DOUBLE, 122 G_TYPE_DOUBLE,
123 G_TYPE_STRING, 123 G_TYPE_STRING,
124 G_TYPE_STRING, 124 G_TYPE_STRING,
125 G_TYPE_INT64, 125 G_TYPE_INT64,
126 G_TYPE_INVALID); 126 G_TYPE_INVALID);
127 GMainLoop* loop = g_main_loop_new (NULL, TRUE); 127 GMainLoop* loop = g_main_loop_new (NULL, TRUE);
128 dbus_g_proxy_connect_signal(proxy, 128 dbus_g_proxy_connect_signal(proxy,
129 "StatusUpdate", 129 kStatusUpdate,
130 G_CALLBACK(StatusUpdateSignalHandler), 130 G_CALLBACK(StatusUpdateSignalHandler),
131 NULL, 131 NULL,
132 NULL); 132 NULL);
133 g_main_loop_run(loop); 133 g_main_loop_run(loop);
134 g_main_loop_unref(loop); 134 g_main_loop_unref(loop);
135 } 135 }
136 136
137 bool CheckForUpdates(bool force) { 137 bool CheckForUpdates(bool force) {
138 DBusGProxy* proxy; 138 DBusGProxy* proxy;
139 GError* error = NULL; 139 GError* error = NULL;
140 140
141 CHECK(GetProxy(&proxy)); 141 CHECK(GetProxy(&proxy));
142 142
143 gboolean rc = 143 gboolean rc =
144 org_chromium_UpdateEngineInterface_check_for_update(proxy, &error); 144 org_chromium_UpdateEngineInterface_check_for_update(proxy, &error);
145 CHECK_EQ(rc, TRUE) << "Error checking for update: " 145 CHECK_EQ(rc, TRUE) << "Error checking for update: "
146 << GetGErrorMessage(error); 146 << GetGErrorMessage(error);
147 return true; 147 return true;
148 } 148 }
149 149
150 } // namespace {} 150 } // namespace {}
151 151
152 int main(int argc, char** argv) { 152 int main(int argc, char** argv) {
153 // Boilerplate init commands. 153 // Boilerplate init commands.
154 g_type_init(); 154 g_type_init();
155 g_thread_init(NULL); 155 g_thread_init(NULL);
156 dbus_g_thread_init(); 156 dbus_g_thread_init();
157 chromeos_update_engine::Subprocess::Init(); 157 chromeos_update_engine::Subprocess::Init();
158 google::ParseCommandLineFlags(&argc, &argv, true); 158 google::ParseCommandLineFlags(&argc, &argv, true);
159 159
160 if (FLAGS_status) { 160 if (FLAGS_status) {
161 LOG(INFO) << "Querying Update Engine status..."; 161 LOG(INFO) << "Querying Update Engine status...";
162 if (!GetStatus()) { 162 if (!GetStatus()) {
163 LOG(FATAL) << "GetStatus() failed."; 163 LOG(FATAL) << "GetStatus() failed.";
164 } 164 }
165 return 0; 165 return 0;
166 } 166 }
167 if (FLAGS_force_update || FLAGS_check_for_update) { 167 if (FLAGS_force_update || FLAGS_check_for_update) {
168 LOG(INFO) << "Initiating update check and install."; 168 LOG(INFO) << "Initiating update check and install.";
169 if (FLAGS_force_update) { 169 if (FLAGS_force_update) {
170 LOG(INFO) << "Will not abort due to being on expensive network."; 170 LOG(INFO) << "Will not abort due to being on expensive network.";
171 } 171 }
172 CHECK(CheckForUpdates(FLAGS_force_update)) 172 CHECK(CheckForUpdates(FLAGS_force_update))
173 << "Update check/initiate update failed."; 173 << "Update check/initiate update failed.";
174 return 0; 174 return 0;
175 } 175 }
176 if (FLAGS_watch_for_updates) { 176 if (FLAGS_watch_for_updates) {
177 LOG(INFO) << "Watching for status updates."; 177 LOG(INFO) << "Watching for status updates.";
178 WatchForUpdates(); // Should never return. 178 WatchForUpdates(); // Should never return.
179 return 1; 179 return 1;
180 } 180 }
181 181
182 LOG(INFO) << "No flags specified. Exiting."; 182 LOG(INFO) << "No flags specified. Exiting.";
183 return 0; 183 return 0;
184 } 184 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698