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 "EvsManager"
18
19 #include <unistd.h>
20
21 #include <hidl/HidlTransportSupport.h>
22 #include <utils/Errors.h>
23 #include <utils/StrongPointer.h>
24 #include <utils/Log.h>
25
26 #include "ServiceNames.h"
27 #include "Enumerator.h"
28
29
30 // libhidl:
31 using android::hardware::configureRpcThreadpool;
32 using android::hardware::joinRpcThreadpool;
33
34 // Generated HIDL files
35 using android::hardware::automotive::evs::V1_0::IEvsEnumerator;
36 using android::hardware::automotive::evs::V1_0::IEvsDisplay;
37
38 // The namespace in which all our implementation code lives
39 using namespace android::automotive::evs::V1_0::implementation;
40 using namespace android;
41
42
main()43 int main() {
44 // Prepare the RPC serving thread pool. We're configuring it with no additional
45 // threads beyond the main thread which will "join" the pool below.
46 configureRpcThreadpool(1, true /* callerWillJoin */);
47
48 ALOGI("EVS managed service connecting to hardware at %s", kHardwareEnumeratorName);
49 android::sp<Enumerator> service = new Enumerator();
50 if (!service->init(kHardwareEnumeratorName)) {
51 ALOGE("Failed to initialize");
52 return 1;
53 }
54
55 // Register our service -- if somebody is already registered by our name,
56 // they will be killed (their thread pool will throw an exception).
57 ALOGI("EVS managed service is starting as %s", kManagedEnumeratorName);
58 status_t status = service->registerAsService(kManagedEnumeratorName);
59 if (status == OK) {
60 ALOGD("Registration complete");
61
62 // Send this main thread to become a permanent part of the thread pool.
63 // This is not expected to return.
64 joinRpcThreadpool();
65 } else {
66 ALOGE("Could not register service %s (%d).", kManagedEnumeratorName, status);
67 }
68
69 // In normal operation, we don't expect the thread pool to exit
70 ALOGE("EVS Hardware Enumerator is shutting down");
71 return 1;
72 }
73