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