Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 18 | #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 | |
| 25 | using android::hardware::hidl_version; |
| 26 | using android::hardware::IPCThreadState; |
| 27 | using android::hardware::ProcessState; |
| 28 | using android::Looper; |
| 29 | |
| 30 | namespace { |
| 31 | int OnBinderReadReady(int /*fd*/, int /*events*/, void* /*data*/) { |
| 32 | IPCThreadState::self()->handlePolledCommands(); |
| 33 | return 1; // continue receiving events |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | int main(int /*argc*/, char** argv) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 38 | android::base::InitLogging(argv, |
| 39 | android::base::LogdLogger(android::base::SYSTEM)); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 40 | LOG(INFO) << "wifi_hal_legacy is starting up..."; |
| 41 | |
| 42 | // Setup binder |
| 43 | int binder_fd = -1; |
| 44 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 45 | CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR) |
| 46 | << "Failed to initialize binder polling"; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 47 | 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 Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 56 | android::sp<android::hardware::wifi::V1_0::IWifi> service = |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 57 | new android::hardware::wifi::V1_0::implementation::Wifi(); |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 58 | CHECK_EQ(service->registerAsService("wifi"), android::NO_ERROR) |
| 59 | << "Failed to register wifi HAL"; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 60 | |
| 61 | // Loop |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 62 | while (looper->pollAll(-1) != Looper::POLL_ERROR) { |
| 63 | // Keep polling until failure. |
| 64 | } |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 65 | |
| 66 | LOG(INFO) << "wifi_hal_legacy is terminating..."; |
| 67 | return 0; |
| 68 | } |