blob: 677dbc85990469fdb8e1a293bd833b1acf5268ea [file] [log] [blame]
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07001// 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 Reyes63b96d72010-05-10 13:08:54 -07008#include "update_engine/marshal.glibmarshal.h"
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -07009
10using std::string;
11
12G_DEFINE_TYPE(UpdateEngineService, update_engine_service, G_TYPE_OBJECT)
13
14static void update_engine_service_finalize(GObject* object) {
15 G_OBJECT_CLASS(update_engine_service_parent_class)->finalize(object);
16}
17
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070018static guint status_update_signal = 0;
19
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070020static 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 Petkov5a7f5652010-07-22 21:40:09 -070024
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070025 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 Reyes4e9b9f42010-04-26 15:06:43 -070040}
41
42static void update_engine_service_init(UpdateEngineService* object) {
43}
44
45UpdateEngineService* update_engine_service_new(void) {
46 return reinterpret_cast<UpdateEngineService*>(
47 g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL));
48}
49
Darin Petkov296889c2010-07-23 16:20:54 -070050gboolean 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 Reyes4e9b9f42010-04-26 15:06:43 -070062gboolean 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 Petkov5a7f5652010-07-22 21:40:09 -070071
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070072 CHECK(self->update_attempter_->GetStatus(last_checked_time,
73 progress,
74 &current_op,
75 &new_version_str,
76 new_size));
Darin Petkov5a7f5652010-07-22 21:40:09 -070077
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070078 *current_operation = strdup(current_op.c_str());
79 *new_version = strdup(new_version_str.c_str());
Chris Masonec6c57a52010-09-23 13:06:14 -070080 if (!(*current_operation && *new_version)) {
81 *error = NULL;
82 return FALSE;
83 }
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070084 return TRUE;
85}
86
Darin Petkov296889c2010-07-23 16:20:54 -070087gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070088 GError **error) {
Darin Petkov296889c2010-07-23 16:20:54 -070089 if (!self->update_attempter_->RebootIfNeeded()) {
90 *error = NULL;
91 return FALSE;
92 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070093 return TRUE;
94}
95
96gboolean update_engine_service_emit_status_update(
97 UpdateEngineService* self,
98 gint64 last_checked_time,
99 gdouble progress,
100 const gchar* current_operation,
101 const gchar* new_version,
102 gint64 new_size) {
103 g_signal_emit(self,
104 status_update_signal,
105 0,
106 last_checked_time,
107 progress,
108 current_operation,
109 new_version,
110 new_size);
111 return TRUE;
112}