blob: c10bb284d0c8e7500e6879dbb67855a2a1529979 [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
Alex Deymodc066f12017-03-27 13:01:29 -070023#if USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080024#include <brillo/binder_watcher.h>
Alex Deymodc066f12017-03-27 13:01:29 -070025#endif // USE_BINDER
Alex Deymoa91cc482016-01-20 16:51:56 -080026#include <brillo/daemons/daemon.h>
Alex Deymob7ca0962014-10-01 17:58:07 -070027
Casey Dahlina93cd532016-01-14 16:55:11 -080028#if USE_BINDER
Sen Jiang192a86a2016-05-19 17:21:24 -070029#if USE_OMAHA
Alex Deymofa78f142016-01-26 21:36:16 -080030#include "update_engine/binder_service_brillo.h"
Sen Jiang192a86a2016-05-19 17:21:24 -070031#else // !USE_OMAHA
Alex Deymoe97b39c2016-01-20 13:22:17 -080032#include "update_engine/binder_service_android.h"
Sen Jiang192a86a2016-05-19 17:21:24 -070033#endif // USE_OMAHA
Casey Dahlina93cd532016-01-14 16:55:11 -080034#endif // USE_BINDER
Alex Deymo39910dc2015-11-09 17:04:30 -080035#include "update_engine/common/subprocess.h"
Alex Deymofa78f142016-01-26 21:36:16 -080036#include "update_engine/daemon_state_interface.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080037#if USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070038#include "update_engine/dbus_service.h"
Alex Deymoe97b39c2016-01-20 13:22:17 -080039#endif // USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070040
41namespace chromeos_update_engine {
42
Alex Deymoa91cc482016-01-20 16:51:56 -080043class UpdateEngineDaemon : public brillo::Daemon {
Alex Deymob7ca0962014-10-01 17:58:07 -070044 public:
45 UpdateEngineDaemon() = default;
46
47 protected:
48 int OnInit() override;
49
50 private:
Alex Deymoe97b39c2016-01-20 13:22:17 -080051#if USE_DBUS
Alex Deymob7ca0962014-10-01 17:58:07 -070052 // Run from the main loop when the |dbus_adaptor_| object is registered. At
53 // this point we can request ownership of the DBus service name and continue
54 // initialization.
55 void OnDBusRegistered(bool succeeded);
56
Sen Jiang299128e2016-06-03 17:48:18 -070057 // Main D-Bus service adaptor.
Alex Deymoa91cc482016-01-20 16:51:56 -080058 std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_;
Alex Deymoe97b39c2016-01-20 13:22:17 -080059#endif // USE_DBUS
Alex Deymoa91cc482016-01-20 16:51:56 -080060
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070061 // The Subprocess singleton class requires a brillo::MessageLoop in the
Alex Deymob7ca0962014-10-01 17:58:07 -070062 // current thread, so we need to initialize it from this class instead of
63 // the main() function.
64 Subprocess subprocess_;
65
Alex Deymodc066f12017-03-27 13:01:29 -070066#if USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080067 brillo::BinderWatcher binder_watcher_;
Alex Deymodc066f12017-03-27 13:01:29 -070068#endif // USE_BINDER
Casey Dahlina93cd532016-01-14 16:55:11 -080069
70#if USE_BINDER
Sen Jiang192a86a2016-05-19 17:21:24 -070071#if USE_OMAHA
Alex Deymofa78f142016-01-26 21:36:16 -080072 android::sp<BinderUpdateEngineBrilloService> binder_service_;
Sen Jiang192a86a2016-05-19 17:21:24 -070073#else // !USE_OMAHA
Alex Deymofa78f142016-01-26 21:36:16 -080074 android::sp<BinderUpdateEngineAndroidService> binder_service_;
Sen Jiang192a86a2016-05-19 17:21:24 -070075#endif // USE_OMAHA
Casey Dahlina93cd532016-01-14 16:55:11 -080076#endif // USE_BINDER
Alex Vakulenkoe119e6a2016-01-06 17:13:11 -080077
Alex Deymofa78f142016-01-26 21:36:16 -080078 // The daemon state with all the required daemon classes for the configured
79 // platform.
80 std::unique_ptr<DaemonStateInterface> daemon_state_;
Alex Deymo2b4268c2015-12-04 13:56:25 -080081
Alex Deymob7ca0962014-10-01 17:58:07 -070082 DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon);
83};
84
85} // namespace chromeos_update_engine
86
87#endif // UPDATE_ENGINE_DAEMON_H_