6b3e41bdcfe110cfaccc54be823d0cc626dd25d2
[iec.git] / src / type3_AndroidCloud / anbox-master / android / service / daemon.cpp
1 /*
2  * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3, as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranties of
10  * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17
18 #include "android/service/daemon.h"
19 #include "android/service/host_connector.h"
20 #include "android/service/platform_service.h"
21
22 #include "core/posix/signal.h"
23
24 #include <memory>
25
26 #include <cstdlib>
27
28 #include <binder/IPCThreadState.h>
29 #include <binder/ProcessState.h>
30 #include <binder/IServiceManager.h>
31
32 namespace anbox {
33 Daemon::Daemon() {
34 }
35
36 Daemon::~Daemon() {
37 }
38
39 int Daemon::run() {
40     auto trap = core::posix::trap_signals_for_process({core::posix::Signal::sig_term,
41                                                        core::posix::Signal::sig_int});
42     trap->signal_raised().connect([trap](const core::posix::Signal&) {
43         trap->stop();
44     });
45
46     auto host_connector = std::make_shared<HostConnector>();
47     host_connector->start();
48
49     android::defaultServiceManager()->addService(
50                 android::String16(android::PlatformService::service_name()),
51                 new android::PlatformService(host_connector->platform_api_stub()));
52
53     android::ProcessState::self()->startThreadPool();
54
55     trap->run();
56
57     android::IPCThreadState::self()->joinThreadPool();
58
59     return EXIT_SUCCESS;
60 }
61 } // namespace anbox