• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BINDER
24 #include <brillo/binder_watcher.h>
25 #endif  // USE_BINDER
26 #include <brillo/daemons/daemon.h>
27 
28 #if USE_BINDER
29 #if USE_OMAHA
30 #include "update_engine/binder_service_brillo.h"
31 #else  // !USE_OMAHA
32 #include "update_engine/binder_service_android.h"
33 #endif  // USE_OMAHA
34 #endif  // USE_BINDER
35 #include "update_engine/common/subprocess.h"
36 #include "update_engine/daemon_state_interface.h"
37 #if USE_DBUS
38 #include "update_engine/dbus_service.h"
39 #endif  // USE_DBUS
40 
41 namespace chromeos_update_engine {
42 
43 class UpdateEngineDaemon : public brillo::Daemon {
44  public:
45   UpdateEngineDaemon() = default;
46 
47  protected:
48   int OnInit() override;
49 
50  private:
51 #if USE_DBUS
52   // 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 
57   // Main D-Bus service adaptor.
58   std::unique_ptr<UpdateEngineAdaptor> dbus_adaptor_;
59 #endif  // USE_DBUS
60 
61   // The Subprocess singleton class requires a brillo::MessageLoop in the
62   // current thread, so we need to initialize it from this class instead of
63   // the main() function.
64   Subprocess subprocess_;
65 
66 #if USE_BINDER
67   brillo::BinderWatcher binder_watcher_;
68 #endif  // USE_BINDER
69 
70 #if USE_BINDER
71 #if USE_OMAHA
72   android::sp<BinderUpdateEngineBrilloService> binder_service_;
73 #else  // !USE_OMAHA
74   android::sp<BinderUpdateEngineAndroidService> binder_service_;
75 #endif  // USE_OMAHA
76 #endif  // USE_BINDER
77 
78   // The daemon state with all the required daemon classes for the configured
79   // platform.
80   std::unique_ptr<DaemonStateInterface> daemon_state_;
81 
82   DISALLOW_COPY_AND_ASSIGN(UpdateEngineDaemon);
83 };
84 
85 }  // namespace chromeos_update_engine
86 
87 #endif  // UPDATE_ENGINE_DAEMON_H_
88