blob: 32437cbf967e69a990ba0fcd615dd6c54cc1119c [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>
Alex Deymoe97b39c2016-01-20 13:22:17 -080027#if USE_DBUS
Alex Deymoa91cc482016-01-20 16:51:56 -080028#include <brillo/dbus/dbus_connection.h>
Alex Deymoe97b39c2016-01-20 13:22:17 -080029#endif // USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070030
Casey Dahlina93cd532016-01-14 16:55:11 -080031#if USE_BINDER
Alex Deymoe97b39c2016-01-20 13:22:17 -080032#if defined(__BRILLO__) || defined(__CHROMEOS__)
Casey Dahlina93cd532016-01-14 16:55:11 -080033#include "update_engine/binder_service.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080034#else // !(defined(__BRILLO__) || defined(__CHROMEOS__))
35#include "update_engine/binder_service_android.h"
36#endif // defined(__BRILLO__) || defined(__CHROMEOS__)
Casey Dahlina93cd532016-01-14 16:55:11 -080037#endif // USE_BINDER
Alex Deymo39910dc2015-11-09 17:04:30 -080038#include "update_engine/common/subprocess.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080039#if USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070040#include "update_engine/dbus_service.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080041#endif // USE_DBUS
42#if defined(__BRILLO__) || defined(__CHROMEOS__)
Alex Deymob7ca0962014-10-01 17:58:07 -070043#include "update_engine/real_system_state.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080044#endif // defined(__BRILLO__) || defined(__CHROMEOS__)
Alex Deymob7ca0962014-10-01 17:58:07 -070045
46namespace chromeos_update_engine {
47
Alex Deymoa91cc482016-01-20 16:51:56 -080048class UpdateEngineDaemon : public brillo::Daemon {
Alex Deymob7ca0962014-10-01 17:58:07 -070049 public:
50 UpdateEngineDaemon() = default;
51
52 protected:
53 int OnInit() override;
54
55 private:
Alex Deymoe97b39c2016-01-20 13:22:17 -080056#if USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070057 // Run from the main loop when the |dbus_adaptor_| object is registered. At
58 // this point we can request ownership of the DBus service name and continue
59 // initialization.
60 void OnDBusRegistered(bool succeeded);
61
Alex Deymoa91cc482016-01-20 16:51:56 -080062 // Main D-Bus connection and service adaptor.
63 brillo::DBusConnection dbus_connection_;
64 std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_;
Alex Deymoe97b39c2016-01-20 13:22:17 -080065#endif // USE_DBUS
Alex Deymoa91cc482016-01-20 16:51:56 -080066
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070067 // The Subprocess singleton class requires a brillo::MessageLoop in the
Alex Deymob7ca0962014-10-01 17:58:07 -070068 // current thread, so we need to initialize it from this class instead of
69 // the main() function.
70 Subprocess subprocess_;
71
Casey Dahlina93cd532016-01-14 16:55:11 -080072#if USE_WEAVE || USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080073 brillo::BinderWatcher binder_watcher_;
Casey Dahlina93cd532016-01-14 16:55:11 -080074#endif // USE_WEAVE || USE_BINDER
75
76#if USE_BINDER
Alex Deymoe97b39c2016-01-20 13:22:17 -080077#if defined(__BRILLO__) || defined(__CHROMEOS__)
Casey Dahlina93cd532016-01-14 16:55:11 -080078 android::sp<BinderUpdateEngineService> service_;
Alex Deymoe97b39c2016-01-20 13:22:17 -080079#else // !(defined(__BRILLO__) || defined(__CHROMEOS__))
80 android::sp<BinderUpdateEngineAndroidService> service_;
81#endif // defined(__BRILLO__) || defined(__CHROMEOS__)
Casey Dahlina93cd532016-01-14 16:55:11 -080082#endif // USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080083
Alex Deymoe97b39c2016-01-20 13:22:17 -080084#if defined(__BRILLO__) || defined(__CHROMEOS__)
Alex Deymo2b4268c2015-12-04 13:56:25 -080085 // The RealSystemState uses the previous classes so it should be defined last.
86 std::unique_ptr<RealSystemState> real_system_state_;
Alex Deymoe97b39c2016-01-20 13:22:17 -080087#else // !(defined(__BRILLO__) || defined(__CHROMEOS__))
88 //TODO(deymo): Define non-Brillo state.
89#endif // defined(__BRILLO__) || defined(__CHROMEOS__)
Alex Deymo2b4268c2015-12-04 13:56:25 -080090
Alex Deymob7ca0962014-10-01 17:58:07 -070091 DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon);
92};
93
94} // namespace chromeos_update_engine
95
96#endif // UPDATE_ENGINE_DAEMON_H_