blob: 4a05160eb234bae50433a59eed2e2a6d988330f5 [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
62gboolean update_engine_service_check_for_update(UpdateEngineService* self,
63 GError **error) {
64 self->update_attempter_->CheckForUpdate("", "");
65 return TRUE;
66}
67
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070068gboolean update_engine_service_get_status(UpdateEngineService* self,
69 int64_t* last_checked_time,
70 double* progress,
71 gchar** current_operation,
72 gchar** new_version,
73 int64_t* new_size,
74 GError **error) {
75 string current_op;
76 string new_version_str;
Darin Petkov5a7f5652010-07-22 21:40:09 -070077
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070078 CHECK(self->update_attempter_->GetStatus(last_checked_time,
79 progress,
80 &current_op,
81 &new_version_str,
82 new_size));
Darin Petkov5a7f5652010-07-22 21:40:09 -070083
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070084 *current_operation = strdup(current_op.c_str());
85 *new_version = strdup(new_version_str.c_str());
86 return TRUE;
87}
88
Darin Petkov296889c2010-07-23 16:20:54 -070089gboolean update_engine_service_reboot_if_needed(UpdateEngineService* self,
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070090 GError **error) {
Darin Petkov296889c2010-07-23 16:20:54 -070091 if (!self->update_attempter_->RebootIfNeeded()) {
92 *error = NULL;
93 return FALSE;
94 }
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070095 return TRUE;
96}
97
98gboolean update_engine_service_emit_status_update(
99 UpdateEngineService* self,
100 gint64 last_checked_time,
101 gdouble progress,
102 const gchar* current_operation,
103 const gchar* new_version,
104 gint64 new_size) {
105 g_signal_emit(self,
106 status_update_signal,
107 0,
108 last_checked_time,
109 progress,
110 current_operation,
111 new_version,
112 new_size);
113 return TRUE;
114}