Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2014 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 | // |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 16 | |
| 17 | #include "apmanager/daemon.h" |
| 18 | |
| 19 | #include <sysexits.h> |
| 20 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 21 | #include <base/logging.h> |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 22 | |
Peter Qiu | 5808396 | 2015-11-05 14:29:50 -0800 | [diff] [blame] | 23 | #include "apmanager/dbus/dbus_control.h" |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 24 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 25 | namespace apmanager { |
| 26 | |
| 27 | // static |
Peter Qiu | 2a9f348 | 2015-09-28 15:00:04 -0700 | [diff] [blame] | 28 | #if !defined(__ANDROID__) |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 29 | const char Daemon::kAPManagerGroupName[] = "apmanager"; |
| 30 | const char Daemon::kAPManagerUserName[] = "apmanager"; |
Peter Qiu | 2a9f348 | 2015-09-28 15:00:04 -0700 | [diff] [blame] | 31 | #else |
| 32 | const char Daemon::kAPManagerGroupName[] = "system"; |
| 33 | const char Daemon::kAPManagerUserName[] = "system"; |
| 34 | #endif // __ANDROID__ |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 35 | |
| 36 | Daemon::Daemon(const base::Closure& startup_callback) |
Peter Qiu | 0d70fa7 | 2015-11-12 10:31:40 -0800 | [diff] [blame] | 37 | : startup_callback_(startup_callback) { |
Vitaly Buka | a463092 | 2014-12-11 18:46:46 -0800 | [diff] [blame] | 38 | } |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 39 | |
| 40 | int Daemon::OnInit() { |
Peter Qiu | 0d70fa7 | 2015-11-12 10:31:40 -0800 | [diff] [blame] | 41 | int return_code = brillo::Daemon::OnInit(); |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 42 | if (return_code != EX_OK) { |
| 43 | return return_code; |
| 44 | } |
| 45 | |
Peter Qiu | 0d70fa7 | 2015-11-12 10:31:40 -0800 | [diff] [blame] | 46 | // Setup control interface. The control interface will expose |
| 47 | // our service (Manager) through its RPC interface. |
| 48 | control_interface_.reset(new DBusControl()); |
| 49 | control_interface_->Init(); |
| 50 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 51 | // Signal that we've acquired all resources. |
| 52 | startup_callback_.Run(); |
Peter Qiu | fb39ba4 | 2014-11-21 09:09:59 -0800 | [diff] [blame] | 53 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 54 | return EX_OK; |
| 55 | } |
| 56 | |
| 57 | void Daemon::OnShutdown(int* return_code) { |
Peter Qiu | 0d70fa7 | 2015-11-12 10:31:40 -0800 | [diff] [blame] | 58 | control_interface_->Shutdown(); |
Peter Qiu | 376e404 | 2014-11-13 09:40:28 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Peter Qiu | 5dd242d | 2014-10-14 12:23:21 -0700 | [diff] [blame] | 61 | } // namespace apmanager |