Home | History | Annotate | Download | only in daemon
      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 #include <sysexits.h>
     18 
     19 #include <base/logging.h>
     20 #include <base/macros.h>
     21 #include <binderwrapper/binder_wrapper.h>
     22 #include <brillo/binder_watcher.h>
     23 #include <brillo/daemons/daemon.h>
     24 #include <brillo/flag_helper.h>
     25 
     26 #include "power_manager.h"
     27 
     28 namespace {
     29 
     30 class PowerManagerDaemon : public brillo::Daemon {
     31  public:
     32   PowerManagerDaemon() = default;
     33   ~PowerManagerDaemon() override = default;
     34 
     35  private:
     36   // brillo::Daemon:
     37   int OnInit() override {
     38     int result = brillo::Daemon::OnInit();
     39     if (result != EX_OK)
     40       return result;
     41 
     42     android::BinderWrapper::Create();
     43     if (!binder_watcher_.Init())
     44       return EX_OSERR;
     45     if (!power_manager_.Init())
     46       return EX_OSERR;
     47 
     48     LOG(INFO) << "Initialization complete";
     49     return EX_OK;
     50   }
     51 
     52   brillo::BinderWatcher binder_watcher_;
     53   android::PowerManager power_manager_;
     54 
     55   DISALLOW_COPY_AND_ASSIGN(PowerManagerDaemon);
     56 };
     57 
     58 }  // namespace
     59 
     60 int main(int argc, char *argv[]) {
     61   // This also initializes base::CommandLine(), which is needed for logging.
     62   brillo::FlagHelper::Init(argc, argv, "Power management daemon");
     63   logging::InitLogging(logging::LoggingSettings());
     64   return PowerManagerDaemon().Run();
     65 }
     66