daemon.h 2.4 KB

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