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 #define LOG_TAG "android.hardware.usb@1.1-service.bonito"
18 
19 #include <hidl/HidlTransportSupport.h>
20 #include "Usb.h"
21 #include "UsbGadget.h"
22 
23 using android::sp;
24 
25 // libhwbinder:
26 using android::hardware::configureRpcThreadpool;
27 using android::hardware::joinRpcThreadpool;
28 
29 // Generated HIDL files
30 using android::hardware::usb::V1_1::IUsb;
31 using android::hardware::usb::gadget::V1_0::IUsbGadget;
32 using android::hardware::usb::V1_1::implementation::Usb;
33 using android::hardware::usb::gadget::V1_0::implementation::UsbGadget;
34 
35 using android::OK;
36 using android::status_t;
37 
main()38 int main() {
39     android::sp<IUsb> service = new Usb();
40     android::sp<IUsbGadget> service2 = new UsbGadget();
41 
42     configureRpcThreadpool(2, true /*callerWillJoin*/);
43     status_t status = service->registerAsService();
44 
45     if (status != OK) {
46         ALOGE("Cannot register USB HAL service");
47         return 1;
48     }
49 
50     status = service2->registerAsService();
51 
52     if (status != OK) {
53         ALOGE("Cannot register USB Gadget HAL service");
54         return 1;
55     }
56 
57     ALOGI("USB HAL Ready.");
58     joinRpcThreadpool();
59     // Under noraml cases, execution will not reach this line.
60     ALOGI("USB HAL failed to join thread pool.");
61     return 1;
62 
63 }
64