1// 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// 16 17#ifndef UPDATE_ENGINE_DAEMON_H_ 18#define UPDATE_ENGINE_DAEMON_H_ 19 20#include <memory> 21#include <string> 22 23#if USE_WEAVE || USE_BINDER 24#include <brillo/binder_watcher.h> 25#endif // USE_WEAVE || USE_BINDER 26#include <brillo/daemons/daemon.h> 27#if USE_DBUS 28#include <brillo/dbus/dbus_connection.h> 29#endif // USE_DBUS 30 31#if USE_BINDER 32#if defined(__BRILLO__) || defined(__CHROMEOS__) 33#include "update_engine/binder_service_brillo.h" 34#else // !(defined(__BRILLO__) || defined(__CHROMEOS__)) 35#include "update_engine/binder_service_android.h" 36#endif // defined(__BRILLO__) || defined(__CHROMEOS__) 37#endif // USE_BINDER 38#include "update_engine/common/subprocess.h" 39#include "update_engine/daemon_state_interface.h" 40#if USE_DBUS 41#include "update_engine/dbus_service.h" 42#endif // USE_DBUS 43 44namespace chromeos_update_engine { 45 46class UpdateEngineDaemon : public brillo::Daemon { 47 public: 48 UpdateEngineDaemon() = default; 49 50 protected: 51 int OnInit() override; 52 53 private: 54#if USE_DBUS 55 // Run from the main loop when the |dbus_adaptor_| object is registered. At 56 // this point we can request ownership of the DBus service name and continue 57 // initialization. 58 void OnDBusRegistered(bool succeeded); 59 60 // Main D-Bus connection and service adaptor. 61 brillo::DBusConnection dbus_connection_; 62 std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_; 63#endif // USE_DBUS 64 65 // The Subprocess singleton class requires a brillo::MessageLoop in the 66 // current thread, so we need to initialize it from this class instead of 67 // the main() function. 68 Subprocess subprocess_; 69 70#if USE_WEAVE || USE_BINDER 71 brillo::BinderWatcher binder_watcher_; 72#endif // USE_WEAVE || USE_BINDER 73 74#if USE_BINDER 75#if defined(__BRILLO__) || defined(__CHROMEOS__) 76 android::sp<BinderUpdateEngineBrilloService> binder_service_; 77#else // !(defined(__BRILLO__) || defined(__CHROMEOS__)) 78 android::sp<BinderUpdateEngineAndroidService> binder_service_; 79#endif // defined(__BRILLO__) || defined(__CHROMEOS__) 80#endif // USE_BINDER 81 82 // The daemon state with all the required daemon classes for the configured 83 // platform. 84 std::unique_ptr<DaemonStateInterface> daemon_state_; 85 86 DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon); 87}; 88 89} // namespace chromeos_update_engine 90 91#endif // UPDATE_ENGINE_DAEMON_H_ 92