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; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 24 | |
| 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 | |
| 50 | gboolean update_engine_service_get_status(UpdateEngineService* self, |
| 51 | int64_t* last_checked_time, |
| 52 | double* progress, |
| 53 | gchar** current_operation, |
| 54 | gchar** new_version, |
| 55 | int64_t* new_size, |
| 56 | GError **error) { |
| 57 | string current_op; |
| 58 | string new_version_str; |
| 59 | |
| 60 | CHECK(self->update_attempter_->GetStatus(last_checked_time, |
| 61 | progress, |
| 62 | ¤t_op, |
| 63 | &new_version_str, |
| 64 | new_size)); |
| 65 | |
| 66 | *current_operation = strdup(current_op.c_str()); |
| 67 | *new_version = strdup(new_version_str.c_str()); |
| 68 | return TRUE; |
| 69 | } |
| 70 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame^] | 71 | gboolean update_engine_service_check_for_update(UpdateEngineService* self, |
| 72 | GError **error) { |
| 73 | self->update_attempter_->CheckForUpdate(); |
| 74 | return TRUE; |
| 75 | } |
| 76 | |
| 77 | gboolean update_engine_service_emit_status_update( |
| 78 | UpdateEngineService* self, |
| 79 | gint64 last_checked_time, |
| 80 | gdouble progress, |
| 81 | const gchar* current_operation, |
| 82 | const gchar* new_version, |
| 83 | gint64 new_size) { |
| 84 | g_signal_emit(self, |
| 85 | status_update_signal, |
| 86 | 0, |
| 87 | last_checked_time, |
| 88 | progress, |
| 89 | current_operation, |
| 90 | new_version, |
| 91 | new_size); |
| 92 | return TRUE; |
| 93 | } |