blob: 07e6c81e0d9e025e2f6dfdceb61a849636a72429 [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>
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) {
Roshan Pius79a99752016-10-04 13:03:58 -070039 android::base::InitLogging(argv,
40 android::base::LogdLogger(android::base::SYSTEM));
Roshan Pius3c4e8a32016-10-03 14:53:58 -070041 LOG(INFO) << "wifi_hal_legacy is starting up...";
42
43 // Setup binder
44 int binder_fd = -1;
45 ProcessState::self()->setThreadPoolMaxThreadCount(0);
Roshan Pius79a99752016-10-04 13:03:58 -070046 CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR)
47 << "Failed to initialize binder polling";
Roshan Pius3c4e8a32016-10-03 14:53:58 -070048 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
Roshan Pius79a99752016-10-04 13:03:58 -070057 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";
Roshan Pius3c4e8a32016-10-03 14:53:58 -070061
62 // Loop
Roshan Pius79a99752016-10-04 13:03:58 -070063 while (looper->pollAll(-1) != Looper::POLL_ERROR)
64 ;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070065
66 LOG(INFO) << "wifi_hal_legacy is terminating...";
67 return 0;
68}