1 /******************************************************************************
2 *
3 * Copyright 2020, 2022 NXP
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18 #define LOG_TAG "weaver@1.0-service"
19 #include <log/log.h>
20 #include <android/hardware/weaver/1.0/IWeaver.h>
21 #include <android/hardware/weaver/1.0/types.h>
22
23 #include <hidl/LegacySupport.h>
24 #include <android/binder_process.h>
25
26 #include <string.h>
27 #include "Weaver.h"
28
29 // Generated HIDL files
30 using android::hardware::weaver::V1_0::IWeaver;
31 using android::hardware::weaver::V1_0::implementation::Weaver;
32 using android::hardware::defaultPassthroughServiceImplementation;
33 using android::OK;
34 using android::hardware::registerPassthroughServiceImplementation;
35
36 using android::sp;
37 using android::status_t;
38 using android::OK;
39
main()40 int main() {
41 try {
42 status_t status;
43
44 android::sp<IWeaver> weaver_service = nullptr;
45 ALOGI("Weaver HAL Service 1.0 is starting.");
46 weaver_service = new Weaver();
47 if (weaver_service == nullptr) {
48 ALOGE("Can not create an instance of Weaver HAL Interface, exiting.");
49 goto shutdown;
50 }
51 ABinderProcess_setThreadPoolMaxThreadCount(0);
52 status = weaver_service->registerAsService();
53
54 if (status != OK) {
55 ALOGE("Could not register service for Weaver HAL Interface (%d)", status);
56 goto shutdown;
57 }
58 ALOGI("Weaver Service is ready");
59 ABinderProcess_joinThreadPool();
60 } catch (std::length_error& e) {
61 ALOGE("Length Exception occurred = %s ", e.what());
62 } catch (std::__1::ios_base::failure& e) {
63 ALOGE("ios failure Exception occurred = %s ", e.what());
64 } catch (std::__1::system_error& e) {
65 ALOGE("system error Exception occurred = %s ", e.what());
66 }
67 // Should not pass this line
68 shutdown:
69 // In normal operation, we don't expect the thread pool to exit
70 ALOGE("Weaver Service is shutting down");
71 return 1;
72 }
73