Zhanglong Xia | 24e5274 | 2023-06-14 05:25:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
Zhanglong Xia | 5c02701 | 2023-06-15 10:15:59 +0800 | [diff] [blame^] | 17 | #include <aidl/android/hardware/threadnetwork/IThreadChip.h> |
Zhanglong Xia | 24e5274 | 2023-06-14 05:25:55 +0000 | [diff] [blame] | 18 | #include <android-base/logging.h> |
Zhanglong Xia | 5c02701 | 2023-06-15 10:15:59 +0800 | [diff] [blame^] | 19 | #include <android/binder_manager.h> |
| 20 | #include <android/binder_process.h> |
| 21 | #include <utils/Log.h> |
Zhanglong Xia | 24e5274 | 2023-06-14 05:25:55 +0000 | [diff] [blame] | 22 | |
| 23 | #include "service.hpp" |
Zhanglong Xia | 5c02701 | 2023-06-15 10:15:59 +0800 | [diff] [blame^] | 24 | #include "thread_chip.hpp" |
| 25 | |
| 26 | using aidl::android::hardware::threadnetwork::IThreadChip; |
| 27 | using aidl::android::hardware::threadnetwork::ThreadChip; |
Zhanglong Xia | 24e5274 | 2023-06-14 05:25:55 +0000 | [diff] [blame] | 28 | |
| 29 | int main(int argc, char* argv[]) { |
| 30 | CHECK_GT(argc, 1); |
Zhanglong Xia | 5c02701 | 2023-06-15 10:15:59 +0800 | [diff] [blame^] | 31 | std::vector<std::shared_ptr<ThreadChip>> threadChips; |
| 32 | aidl::android::hardware::threadnetwork::Service service; |
| 33 | |
| 34 | for (int id = 0; id < argc - 1; id++) { |
| 35 | binder_status_t status; |
| 36 | const std::string serviceName(std::string() + IThreadChip::descriptor + "/chip" + |
| 37 | std::to_string(id)); |
| 38 | auto threadChip = ndk::SharedRefBase::make<ThreadChip>(argv[id + 1]); |
| 39 | |
| 40 | CHECK_NE(threadChip, nullptr); |
| 41 | |
| 42 | status = AServiceManager_addService(threadChip->asBinder().get(), serviceName.c_str()); |
| 43 | CHECK_EQ(status, STATUS_OK); |
| 44 | |
| 45 | ALOGI("ServiceName: %s, Url: %s", serviceName.c_str(), argv[id + 1]); |
| 46 | threadChips.push_back(std::move(threadChip)); |
| 47 | } |
Zhanglong Xia | 24e5274 | 2023-06-14 05:25:55 +0000 | [diff] [blame] | 48 | |
| 49 | ALOGI("Thread Network HAL is running"); |
| 50 | |
| 51 | service.startLoop(); |
| 52 | return EXIT_FAILURE; // should not reach |
| 53 | } |