blob: 5980a7743a92affc652b9e986f60fc7d6b5ce374 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
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 Qiu5dd242d2014-10-14 12:23:21 -070016
17#include "apmanager/daemon.h"
18
19#include <sysexits.h>
20
Peter Qiu5dd242d2014-10-14 12:23:21 -070021#include <base/logging.h>
Peter Qiu5dd242d2014-10-14 12:23:21 -070022
Peter Qiu58083962015-11-05 14:29:50 -080023#include "apmanager/dbus/dbus_control.h"
Peter Qiube128822015-10-13 13:55:03 -070024
Peter Qiu5dd242d2014-10-14 12:23:21 -070025namespace apmanager {
26
27// static
Peter Qiu2a9f3482015-09-28 15:00:04 -070028#if !defined(__ANDROID__)
Peter Qiu5dd242d2014-10-14 12:23:21 -070029const char Daemon::kAPManagerGroupName[] = "apmanager";
30const char Daemon::kAPManagerUserName[] = "apmanager";
Peter Qiu2a9f3482015-09-28 15:00:04 -070031#else
32const char Daemon::kAPManagerGroupName[] = "system";
33const char Daemon::kAPManagerUserName[] = "system";
34#endif // __ANDROID__
Peter Qiu5dd242d2014-10-14 12:23:21 -070035
36Daemon::Daemon(const base::Closure& startup_callback)
Peter Qiu0d70fa72015-11-12 10:31:40 -080037 : startup_callback_(startup_callback) {
Vitaly Bukaa4630922014-12-11 18:46:46 -080038}
Peter Qiu5dd242d2014-10-14 12:23:21 -070039
40int Daemon::OnInit() {
Peter Qiu0d70fa72015-11-12 10:31:40 -080041 int return_code = brillo::Daemon::OnInit();
Peter Qiu5dd242d2014-10-14 12:23:21 -070042 if (return_code != EX_OK) {
43 return return_code;
44 }
45
Peter Qiu0d70fa72015-11-12 10:31:40 -080046 // 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 Qiu5dd242d2014-10-14 12:23:21 -070051 // Signal that we've acquired all resources.
52 startup_callback_.Run();
Peter Qiufb39ba42014-11-21 09:09:59 -080053
Peter Qiu5dd242d2014-10-14 12:23:21 -070054 return EX_OK;
55}
56
57void Daemon::OnShutdown(int* return_code) {
Peter Qiu0d70fa72015-11-12 10:31:40 -080058 control_interface_->Shutdown();
Peter Qiu376e4042014-11-13 09:40:28 -080059}
60
Peter Qiu5dd242d2014-10-14 12:23:21 -070061} // namespace apmanager