service.cpp revision 79a9975d07ec1fc583f4f281469bf3c05c909034
1/*
2 * Copyright (C) 2016 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 <android-base/logging.h>
18#include <hidl/IServiceManager.h>
19#include <hwbinder/IPCThreadState.h>
20#include <hwbinder/ProcessState.h>
21#include <utils/Looper.h>
22#include <utils/StrongPointer.h>
23
24#include "wifi.h"
25
26using android::hardware::hidl_version;
27using android::hardware::IPCThreadState;
28using android::hardware::ProcessState;
29using android::Looper;
30
31namespace {
32int OnBinderReadReady(int /*fd*/, int /*events*/, void* /*data*/) {
33  IPCThreadState::self()->handlePolledCommands();
34  return 1;  // continue receiving events
35}
36}
37
38int main(int /*argc*/, char** argv) {
39  android::base::InitLogging(argv,
40                             android::base::LogdLogger(android::base::SYSTEM));
41  LOG(INFO) << "wifi_hal_legacy is starting up...";
42
43  // Setup binder
44  int binder_fd = -1;
45  ProcessState::self()->setThreadPoolMaxThreadCount(0);
46  CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR)
47      << "Failed to initialize binder polling";
48  CHECK_GE(binder_fd, 0) << "Invalid binder FD: " << binder_fd;
49
50  // Setup looper
51  android::sp<Looper> looper = Looper::prepare(0 /* no options */);
52  CHECK(looper->addFd(
53      binder_fd, 0, Looper::EVENT_INPUT, OnBinderReadReady, nullptr))
54      << "Failed to watch binder FD";
55
56  // Setup hwbinder service
57  android::sp<android::hardware::wifi::V1_0::IWifi> service =
58      new android::hardware::wifi::V1_0::implementation::Wifi(looper);
59  CHECK_EQ(service->registerAsService("wifi"), android::NO_ERROR)
60      << "Failed to register wifi HAL";
61
62  // Loop
63  while (looper->pollAll(-1) != Looper::POLL_ERROR)
64    ;
65
66  LOG(INFO) << "wifi_hal_legacy is terminating...";
67  return 0;
68}
69