1 /*
2  * Copyright (C) 2020 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 #include <unistd.h>
17 
18 #include <android-base/logging.h>
19 #include <hidl/HidlTransportSupport.h>
20 #include <utils/Errors.h>
21 #include <utils/StrongPointer.h>
22 
23 #include "AudioControl.h"
24 
25 // libhidl:
26 using android::hardware::configureRpcThreadpool;
27 using android::hardware::joinRpcThreadpool;
28 
29 // Generated HIDL files
30 using android::hardware::automotive::audiocontrol::V2_0::IAudioControl;
31 
32 // The namespace in which all our implementation code lives
33 using namespace android::hardware::automotive::audiocontrol::V2_0::implementation;
34 using namespace android;
35 
36 // Main service entry point
main()37 int main() {
38     // Create an instance of our service class
39     android::sp<IAudioControl> service = new AudioControl();
40     configureRpcThreadpool(1, true /*callerWillJoin*/);
41 
42     if (service->registerAsService() != OK) {
43         LOG(ERROR) << "registerAsService failed";
44         return 1;
45     }
46 
47     // Join (forever) the thread pool we created for the service above
48     joinRpcThreadpool();
49 
50     // We don't ever actually expect to return, so return an error if we do get here
51     return 2;
52 }