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> |
| 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 | |
| 26 | using android::hardware::hidl_version; |
| 27 | using android::hardware::IPCThreadState; |
| 28 | using android::hardware::ProcessState; |
| 29 | using android::Looper; |
| 30 | |
| 31 | namespace { |
| 32 | int OnBinderReadReady(int /*fd*/, int /*events*/, void* /*data*/) { |
| 33 | IPCThreadState::self()->handlePolledCommands(); |
| 34 | return 1; // continue receiving events |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | int main(int /*argc*/, char** argv) { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 39 | android::base::InitLogging(argv, |
| 40 | android::base::LogdLogger(android::base::SYSTEM)); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 41 | LOG(INFO) << "wifi_hal_legacy is starting up..."; |
| 42 | |
| 43 | // Setup binder |
| 44 | int binder_fd = -1; |
| 45 | ProcessState::self()->setThreadPoolMaxThreadCount(0); |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 46 | CHECK_EQ(IPCThreadState::self()->setupPolling(&binder_fd), android::NO_ERROR) |
| 47 | << "Failed to initialize binder polling"; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 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 |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 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"; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 61 | |
| 62 | // Loop |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame^] | 63 | while (looper->pollAll(-1) != Looper::POLL_ERROR) |
| 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 | } |