Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 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 "update_engine/dbus_service.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame^] | 6 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 7 | #include <string> |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame^] | 8 | |
| 9 | #include <base/logging.h> |
| 10 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 11 | #include "update_engine/marshal.glibmarshal.h" |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame^] | 12 | #include "update_engine/utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 13 | |
| 14 | using std::string; |
| 15 | |
| 16 | G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT) |
| 17 | |
| 18 | static void update_engine_service_finalize(GObject* object) { |
| 19 | G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object); |
| 20 | } |
| 21 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 22 | static guint status_update_signal = 0; |
| 23 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 24 | static void update_engine_service_class_init(UpdateEngineServiceClass* klass) { |
| 25 | GObjectClass *object_class; |
| 26 | object_class = G_OBJECT_CLASS(klass); |
| 27 | object_class->finalize = update_engine_service_finalize; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 28 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 29 | status_update_signal = g_signal_new( |
| 30 | "status_update", |
| 31 | G_OBJECT_CLASS_TYPE(klass), |
| 32 | G_SIGNAL_RUN_LAST, |
| 33 | 0, // 0 == no class method associated |
| 34 | NULL, // Accumulator |
| 35 | NULL, // Accumulator data |
| 36 | update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64, |
| 37 | G_TYPE_NONE, // Return type |
| 38 | 5, // param count: |
| 39 | G_TYPE_INT64, |
| 40 | G_TYPE_DOUBLE, |
| 41 | G_TYPE_STRING, |
| 42 | G_TYPE_STRING, |
| 43 | G_TYPE_INT64); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void update_engine_service_init(UpdateEngineService* object) { |
| 47 | } |
| 48 | |
| 49 | UpdateEngineService* update_engine_service_new(void) { |
| 50 | return reinterpret_cast<UpdateEngineService*>( |
| 51 | g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
| 52 | } |
| 53 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 54 | gboolean update_engine_service_attempt_update(UpdateEngineService* self, |
| 55 | gchar* app_version, |
| 56 | gchar* omaha_url, |
| 57 | GError **error) { |
Darin Petkov | a07586b | 2010-10-20 13:41:15 -0700 | [diff] [blame^] | 58 | string update_app_version; |
| 59 | string update_omaha_url; |
| 60 | // Only non-official (e.g., dev and test) builds can override the current |
| 61 | // version and update server URL over D-Bus. |
| 62 | if (!chromeos_update_engine::utils::IsOfficialBuild()) { |
| 63 | if (app_version) { |
| 64 | update_app_version = app_version; |
| 65 | } |
| 66 | if (omaha_url) { |
| 67 | update_omaha_url = omaha_url; |
| 68 | } |
| 69 | } |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 70 | LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" " |
| 71 | << "omaha_url=\"" << update_omaha_url << "\""; |
| 72 | self->update_attempter_->CheckForUpdate(app_version, omaha_url); |
| 73 | return TRUE; |
| 74 | } |
| 75 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 76 | gboolean update_engine_service_get_status(UpdateEngineService* self, |
| 77 | int64_t* last_checked_time, |
| 78 | double* progress, |
| 79 | gchar** current_operation, |
| 80 | gchar** new_version, |
| 81 | int64_t* new_size, |
| 82 | GError **error) { |
| 83 | string current_op; |
| 84 | string new_version_str; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 85 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 86 | CHECK(self->update_attempter_->GetStatus(last_checked_time, |
| 87 | progress, |
| 88 | ¤t_op, |
| 89 | &new_version_str, |
| 90 | new_size)); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 91 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 92 | *current_operation = strdup(current_op.c_str()); |
| 93 | *new_version = strdup(new_version_str.c_str()); |
Chris Masone | c6c57a5 | 2010-09-23 13:06:14 -0700 | [diff] [blame] | 94 | if (!(*current_operation && *new_version)) { |
| 95 | *error = NULL; |
| 96 | return FALSE; |
| 97 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 98 | return TRUE; |
| 99 | } |
| 100 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 101 | gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 102 | GError **error) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 103 | if (!self->update_attempter_->RebootIfNeeded()) { |
| 104 | *error = NULL; |
| 105 | return FALSE; |
| 106 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 107 | return TRUE; |
| 108 | } |
| 109 | |
| 110 | gboolean update_engine_service_emit_status_update( |
| 111 | UpdateEngineService* self, |
| 112 | gint64 last_checked_time, |
| 113 | gdouble progress, |
| 114 | const gchar* current_operation, |
| 115 | const gchar* new_version, |
| 116 | gint64 new_size) { |
| 117 | g_signal_emit(self, |
| 118 | status_update_signal, |
| 119 | 0, |
| 120 | last_checked_time, |
| 121 | progress, |
| 122 | current_operation, |
| 123 | new_version, |
| 124 | new_size); |
| 125 | return TRUE; |
| 126 | } |