OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <string> | 5 #include <string> |
6 #include <tr1/memory> | 6 #include <tr1/memory> |
7 #include <vector> | 7 #include <vector> |
8 #include <gflags/gflags.h> | 8 #include <gflags/gflags.h> |
9 #include <glib.h> | 9 #include <glib.h> |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "chromeos/obsolete_logging.h" | 11 #include "chromeos/obsolete_logging.h" |
12 #include "update_engine/dbus_constants.h" | 12 #include "update_engine/dbus_constants.h" |
13 #include "update_engine/dbus_service.h" | 13 #include "update_engine/dbus_service.h" |
14 #include "update_engine/update_attempter.h" | 14 #include "update_engine/update_attempter.h" |
15 | 15 |
16 extern "C" { | 16 extern "C" { |
17 #include "update_engine/update_engine.dbusserver.h" | 17 #include "update_engine/update_engine.dbusserver.h" |
18 } | 18 } |
19 | 19 |
20 DEFINE_bool(logtostderr, false, | 20 DEFINE_bool(logtostderr, false, |
21 "Write logs to stderr instead of to a file in log_dir."); | 21 "Write logs to stderr instead of to a file in log_dir."); |
22 | 22 |
23 using std::string; | 23 using std::string; |
24 using std::tr1::shared_ptr; | 24 using std::tr1::shared_ptr; |
25 using std::vector; | 25 using std::vector; |
26 | 26 |
27 namespace chromeos_update_engine { | 27 namespace chromeos_update_engine { |
28 | 28 |
29 gboolean SetupInMainLoop(void* arg) { | |
30 // TODO(adlr): Tell update_attempter to start working. | |
31 // Comment this in for that: | |
32 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); | |
33 LOG(INFO) << "Starting update!"; | |
34 update_attempter->Update(false); | |
35 | |
36 return FALSE; // Don't call this callback function again | |
37 } | |
38 | |
39 void SetupDbusService(UpdateEngineService* service) { | 29 void SetupDbusService(UpdateEngineService* service) { |
40 DBusGConnection *bus; | 30 DBusGConnection *bus; |
41 DBusGProxy *proxy; | 31 DBusGProxy *proxy; |
42 GError *error = NULL; | 32 GError *error = NULL; |
43 | 33 |
44 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 34 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
45 if (!bus) { | 35 if (!bus) { |
46 LOG(FATAL) << "Failed to get bus"; | 36 LOG(FATAL) << "Failed to get bus"; |
47 } | 37 } |
48 proxy = dbus_g_proxy_new_for_name(bus, | 38 proxy = dbus_g_proxy_new_for_name(bus, |
(...skipping 26 matching lines...) Expand all Loading... |
75 #include "update_engine/subprocess.h" | 65 #include "update_engine/subprocess.h" |
76 | 66 |
77 int main(int argc, char** argv) { | 67 int main(int argc, char** argv) { |
78 ::g_type_init(); | 68 ::g_type_init(); |
79 g_thread_init(NULL); | 69 g_thread_init(NULL); |
80 dbus_g_thread_init(); | 70 dbus_g_thread_init(); |
81 chromeos_update_engine::Subprocess::Init(); | 71 chromeos_update_engine::Subprocess::Init(); |
82 google::ParseCommandLineFlags(&argc, &argv, true); | 72 google::ParseCommandLineFlags(&argc, &argv, true); |
83 CommandLine::Init(argc, argv); | 73 CommandLine::Init(argc, argv); |
84 logging::InitLogging("logfile.txt", | 74 logging::InitLogging("logfile.txt", |
85 FLAGS_logtostderr ? | 75 (FLAGS_logtostderr ? |
86 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : | 76 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : |
87 logging::LOG_ONLY_TO_FILE, | 77 logging::LOG_ONLY_TO_FILE), |
88 logging::DONT_LOCK_LOG_FILE, | 78 logging::DONT_LOCK_LOG_FILE, |
89 logging::APPEND_TO_OLD_LOG_FILE); | 79 logging::APPEND_TO_OLD_LOG_FILE); |
90 LOG(INFO) << "Chrome OS Update Engine starting"; | 80 LOG(INFO) << "Chrome OS Update Engine starting"; |
91 | 81 |
92 // Create the single GMainLoop | 82 // Create the single GMainLoop |
93 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); | 83 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
94 | 84 |
95 // Create the update attempter: | 85 // Create the update attempter: |
96 chromeos_update_engine::UpdateAttempter update_attempter(loop); | 86 chromeos_update_engine::UpdateAttempter update_attempter; |
97 | 87 |
98 // Create the dbus service object: | 88 // Create the dbus service object: |
99 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, | 89 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, |
100 &dbus_glib_update_engine_service_object_info); | 90 &dbus_glib_update_engine_service_object_info); |
101 UpdateEngineService* service = | 91 UpdateEngineService* service = |
102 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); | 92 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
103 service->update_attempter_ = &update_attempter; | 93 service->update_attempter_ = &update_attempter; |
| 94 update_attempter.set_dbus_service(service); |
104 chromeos_update_engine::SetupDbusService(service); | 95 chromeos_update_engine::SetupDbusService(service); |
105 | 96 |
106 // Set up init routine to run within the main loop. | |
107 g_timeout_add(0, &chromeos_update_engine::SetupInMainLoop, &update_attempter); | |
108 | |
109 // Run the main loop until exit time: | 97 // Run the main loop until exit time: |
110 g_main_loop_run(loop); | 98 g_main_loop_run(loop); |
111 | 99 |
112 // Cleanup: | 100 // Cleanup: |
113 g_main_loop_unref(loop); | 101 g_main_loop_unref(loop); |
| 102 update_attempter.set_dbus_service(NULL); |
114 g_object_unref(G_OBJECT(service)); | 103 g_object_unref(G_OBJECT(service)); |
115 | 104 |
116 LOG(INFO) << "Chrome OS Update Engine terminating"; | 105 LOG(INFO) << "Chrome OS Update Engine terminating"; |
117 return 0; | 106 return 0; |
118 } | 107 } |
OLD | NEW |