blob: 54dde41e0de827c8a5cc29ccb21e43573cdef615 [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
50gboolean 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;
Darin Petkov5a7f5652010-07-22 21:40:09 -070059
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070060 CHECK(self->update_attempter_->GetStatus(last_checked_time,
61 progress,
62 &current_op,
63 &new_version_str,
64 new_size));
Darin Petkov5a7f5652010-07-22 21:40:09 -070065
Andrew de los Reyes4e9b9f42010-04-26 15:06:43 -070066 *current_operation = strdup(current_op.c_str());
67 *new_version = strdup(new_version_str.c_str());
68 return TRUE;
69}
70
Darin Petkov5a7f5652010-07-22 21:40:09 -070071gboolean update_engine_service_attempt_update(UpdateEngineService* self,
72 gchar* app_version,
73 gchar* omaha_url,
74 GError **error) {
75 const string update_app_version = app_version ? app_version : "";
76 const string update_omaha_url = omaha_url ? omaha_url : "";
77 LOG(INFO) << "Attempt update: app_version=\"" << update_app_version << "\" "
78 << "omaha_url=\"" << update_omaha_url << "\"";
79 self->update_attempter_->CheckForUpdate(app_version, omaha_url);
80 return TRUE;
81}
82
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070083gboolean update_engine_service_check_for_update(UpdateEngineService* self,
84 GError **error) {
Darin Petkov5a7f5652010-07-22 21:40:09 -070085 self->update_attempter_->CheckForUpdate("", "");
Andrew de los Reyes63b96d72010-05-10 13:08:54 -070086 return TRUE;
87}
88
89gboolean update_engine_service_emit_status_update(
90 UpdateEngineService* self,
91 gint64 last_checked_time,
92 gdouble progress,
93 const gchar* current_operation,
94 const gchar* new_version,
95 gint64 new_size) {
96 g_signal_emit(self,
97 status_update_signal,
98 0,
99 last_checked_time,
100 progress,
101 current_operation,
102 new_version,
103 new_size);
104 return TRUE;
105}