| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 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 | // | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 16 |  | 
|  | 17 | #ifndef UPDATE_ENGINE_DAEMON_H_ | 
|  | 18 | #define UPDATE_ENGINE_DAEMON_H_ | 
|  | 19 |  | 
|  | 20 | #include <memory> | 
|  | 21 | #include <string> | 
|  | 22 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 23 | #if USE_WEAVE || USE_BINDER | 
| Alex Vakulenko | e119e6a | 2016-01-06 17:13:11 -0800 | [diff] [blame] | 24 | #include <brillo/binder_watcher.h> | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 25 | #endif  // USE_WEAVE || USE_BINDER | 
| Alex Deymo | a91cc48 | 2016-01-20 16:51:56 -0800 | [diff] [blame] | 26 | #include <brillo/daemons/daemon.h> | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 27 | #if USE_DBUS | 
| Alex Deymo | a91cc48 | 2016-01-20 16:51:56 -0800 | [diff] [blame] | 28 | #include <brillo/dbus/dbus_connection.h> | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 29 | #endif  // USE_DBUS | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 30 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 31 | #if USE_BINDER | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 32 | #if defined(__BRILLO__) || defined(__CHROMEOS__) | 
| Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 33 | #include "update_engine/binder_service_brillo.h" | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 34 | #else  // !(defined(__BRILLO__) || defined(__CHROMEOS__)) | 
|  | 35 | #include "update_engine/binder_service_android.h" | 
|  | 36 | #endif  // defined(__BRILLO__) || defined(__CHROMEOS__) | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 37 | #endif  // USE_BINDER | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 38 | #include "update_engine/common/subprocess.h" | 
| Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 39 | #include "update_engine/daemon_state_interface.h" | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 40 | #if USE_DBUS | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 41 | #include "update_engine/dbus_service.h" | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 42 | #endif  // USE_DBUS | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 43 |  | 
|  | 44 | namespace chromeos_update_engine { | 
|  | 45 |  | 
| Alex Deymo | a91cc48 | 2016-01-20 16:51:56 -0800 | [diff] [blame] | 46 | class UpdateEngineDaemon : public brillo::Daemon { | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 47 | public: | 
|  | 48 | UpdateEngineDaemon() = default; | 
|  | 49 |  | 
|  | 50 | protected: | 
|  | 51 | int OnInit() override; | 
|  | 52 |  | 
|  | 53 | private: | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 54 | #if USE_DBUS | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 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 |  | 
| Alex Deymo | a91cc48 | 2016-01-20 16:51:56 -0800 | [diff] [blame] | 60 | // Main D-Bus connection and service adaptor. | 
|  | 61 | brillo::DBusConnection dbus_connection_; | 
|  | 62 | std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_; | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 63 | #endif  // USE_DBUS | 
| Alex Deymo | a91cc48 | 2016-01-20 16:51:56 -0800 | [diff] [blame] | 64 |  | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 65 | // The Subprocess singleton class requires a brillo::MessageLoop in the | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 66 | // current thread, so we need to initialize it from this class instead of | 
|  | 67 | // the main() function. | 
|  | 68 | Subprocess subprocess_; | 
|  | 69 |  | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 70 | #if USE_WEAVE || USE_BINDER | 
| Alex Vakulenko | e119e6a | 2016-01-06 17:13:11 -0800 | [diff] [blame] | 71 | brillo::BinderWatcher binder_watcher_; | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 72 | #endif  // USE_WEAVE || USE_BINDER | 
|  | 73 |  | 
|  | 74 | #if USE_BINDER | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 75 | #if defined(__BRILLO__) || defined(__CHROMEOS__) | 
| Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 76 | android::sp<BinderUpdateEngineBrilloService> binder_service_; | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 77 | #else  // !(defined(__BRILLO__) || defined(__CHROMEOS__)) | 
| Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 78 | android::sp<BinderUpdateEngineAndroidService> binder_service_; | 
| Alex Deymo | e97b39c | 2016-01-20 13:22:17 -0800 | [diff] [blame] | 79 | #endif  // defined(__BRILLO__) || defined(__CHROMEOS__) | 
| Casey Dahlin | a93cd53 | 2016-01-14 16:55:11 -0800 | [diff] [blame] | 80 | #endif  // USE_BINDER | 
| Alex Vakulenko | e119e6a | 2016-01-06 17:13:11 -0800 | [diff] [blame] | 81 |  | 
| Alex Deymo | fa78f14 | 2016-01-26 21:36:16 -0800 | [diff] [blame] | 82 | // The daemon state with all the required daemon classes for the configured | 
|  | 83 | // platform. | 
|  | 84 | std::unique_ptr<DaemonStateInterface> daemon_state_; | 
| Alex Deymo | 2b4268c | 2015-12-04 13:56:25 -0800 | [diff] [blame] | 85 |  | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 86 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon); | 
|  | 87 | }; | 
|  | 88 |  | 
|  | 89 | }  // namespace chromeos_update_engine | 
|  | 90 |  | 
|  | 91 | #endif  // UPDATE_ENGINE_DAEMON_H_ |