blob: 623306414c9262c1b0a629b4469eeb36df862df8 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2015 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Alex Deymob7ca0962014-10-01 17:58:07 -070016
17#ifndef UPDATE_ENGINE_DAEMON_H_
18#define UPDATE_ENGINE_DAEMON_H_
19
20#include <memory>
21#include <string>
22
Casey Dahlina93cd532016-01-14 16:55:11 -080023#if USE_WEAVE || USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080024#include <brillo/binder_watcher.h>
Casey Dahlina93cd532016-01-14 16:55:11 -080025#endif // USE_WEAVE || USE_BINDER
Alex Deymoa91cc482016-01-20 16:51:56 -080026#include <brillo/daemons/daemon.h>
27#include <brillo/dbus/dbus_connection.h>
Alex Deymob7ca0962014-10-01 17:58:07 -070028
Casey Dahlina93cd532016-01-14 16:55:11 -080029#if USE_BINDER
30#include "update_engine/binder_service.h"
31#endif // USE_BINDER
Alex Deymo39910dc2015-11-09 17:04:30 -080032#include "update_engine/common/subprocess.h"
Alex Deymob7ca0962014-10-01 17:58:07 -070033#include "update_engine/dbus_service.h"
34#include "update_engine/real_system_state.h"
Alex Deymob7ca0962014-10-01 17:58:07 -070035
36namespace chromeos_update_engine {
37
Alex Deymoa91cc482016-01-20 16:51:56 -080038class UpdateEngineDaemon : public brillo::Daemon {
Alex Deymob7ca0962014-10-01 17:58:07 -070039 public:
40 UpdateEngineDaemon() = default;
41
42 protected:
43 int OnInit() override;
44
45 private:
46 // Run from the main loop when the |dbus_adaptor_| object is registered. At
47 // this point we can request ownership of the DBus service name and continue
48 // initialization.
49 void OnDBusRegistered(bool succeeded);
50
Alex Deymoa91cc482016-01-20 16:51:56 -080051 // Main D-Bus connection and service adaptor.
52 brillo::DBusConnection dbus_connection_;
53 std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_;
54
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070055 // The Subprocess singleton class requires a brillo::MessageLoop in the
Alex Deymob7ca0962014-10-01 17:58:07 -070056 // current thread, so we need to initialize it from this class instead of
57 // the main() function.
58 Subprocess subprocess_;
59
Casey Dahlina93cd532016-01-14 16:55:11 -080060#if USE_WEAVE || USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080061 brillo::BinderWatcher binder_watcher_;
Casey Dahlina93cd532016-01-14 16:55:11 -080062#endif // USE_WEAVE || USE_BINDER
63
64#if USE_BINDER
65 android::sp<BinderUpdateEngineService> service_;
66#endif // USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080067
Alex Deymo2b4268c2015-12-04 13:56:25 -080068 // The RealSystemState uses the previous classes so it should be defined last.
69 std::unique_ptr<RealSystemState> real_system_state_;
70
Alex Deymob7ca0962014-10-01 17:58:07 -070071 DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon);
72};
73
74} // namespace chromeos_update_engine
75
76#endif // UPDATE_ENGINE_DAEMON_H_