blob: 751e8f6c0fda8780d044a76d95f6574c086d7c5a [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -07001/*
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>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070018#include <hwbinder/IPCThreadState.h>
19#include <hwbinder/ProcessState.h>
20#include <utils/Looper.h>
21#include <utils/StrongPointer.h>
22
23#include "wifi.h"
24
25using android::hardware::hidl_version;
26using android::hardware::IPCThreadState;
27using android::hardware::ProcessState;
28using android::Looper;
29
30namespace {
31int OnBinderReadReady(int /*fd*/, int /*events*/, void* /*data*/) {
32 IPCThreadState::self()->handlePolledCommands();
33 return 1; // continue receiving events
34}
35}
36
37int main(int /*argc*/, char** argv) {
Roshan Pius79a99752016-10-04 13:03:58 -070038 android::base::InitLogging(argv,
39 android::base::LogdLogger(android::base::SYSTEM));
Roshan Pius3c4e8a32016-10-03 14:53:58 -070040 LOG(INFO) << "wifi_hal_legacy is starting up...";
41
42 // Setup binder
43 int binder_fd = -1;
44 ProcessState::self()->setThreadPoolMaxThreadCount(0);
Roshan Pius79a99752016-10-04 13:03:58 -070045 CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR)
46 << "Failed to initialize binder polling";
Roshan Pius3c4e8a32016-10-03 14:53:58 -070047 CHECK_GE(binder_fd, 0) << "Invalid binder FD: " << binder_fd;
48
49 // Setup looper
50 android::sp<Looper> looper = Looper::prepare(0 /* no options */);
51 CHECK(looper->addFd(
52 binder_fd, 0, Looper::EVENT_INPUT, OnBinderReadReady, nullptr))
53 << "Failed to watch binder FD";
54
55 // Setup hwbinder service
Roshan Pius79a99752016-10-04 13:03:58 -070056 android::sp<android::hardware::wifi::V1_0::IWifi> service =
Roshan Piusaabe5752016-09-29 09:03:59 -070057 new android::hardware::wifi::V1_0::implementation::Wifi();
Roshan Pius79a99752016-10-04 13:03:58 -070058 CHECK_EQ(service->registerAsService("wifi"), android::NO_ERROR)
59 << "Failed to register wifi HAL";
Roshan Pius3c4e8a32016-10-03 14:53:58 -070060
61 // Loop
Roshan Piusaabe5752016-09-29 09:03:59 -070062 while (looper->pollAll(-1) != Looper::POLL_ERROR) {
63 // Keep polling until failure.
64 }
Roshan Pius3c4e8a32016-10-03 14:53:58 -070065
66 LOG(INFO) << "wifi_hal_legacy is terminating...";
67 return 0;
68}