blob: 841904174d7c7dbc3c4106c29a02428f6c9331bd [file] [log] [blame]
Zhanglong Xia24e52742023-06-14 05:25:55 +00001/*
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 Xia5c027012023-06-15 10:15:59 +080017#include <aidl/android/hardware/threadnetwork/IThreadChip.h>
Zhanglong Xia24e52742023-06-14 05:25:55 +000018#include <android-base/logging.h>
Zhanglong Xia5c027012023-06-15 10:15:59 +080019#include <android/binder_manager.h>
20#include <android/binder_process.h>
21#include <utils/Log.h>
Zhanglong Xia24e52742023-06-14 05:25:55 +000022
23#include "service.hpp"
Zhanglong Xia5c027012023-06-15 10:15:59 +080024#include "thread_chip.hpp"
25
26using aidl::android::hardware::threadnetwork::IThreadChip;
27using aidl::android::hardware::threadnetwork::ThreadChip;
Zhanglong Xia24e52742023-06-14 05:25:55 +000028
29int main(int argc, char* argv[]) {
30 CHECK_GT(argc, 1);
Zhanglong Xia5c027012023-06-15 10:15:59 +080031 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 Xia24e52742023-06-14 05:25:55 +000048
49 ALOGI("Thread Network HAL is running");
50
51 service.startLoop();
52 return EXIT_FAILURE; // should not reach
53}