Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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_NDEBUG 0 |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 18 | #ifdef LAZY_SERVICE |
| 19 | #define LOG_TAG "android.hardware.cas@1.0-service-lazy" |
| 20 | #else |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 21 | #define LOG_TAG "android.hardware.cas@1.0-service" |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 22 | #endif |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 23 | |
| 24 | #include <binder/ProcessState.h> |
| 25 | #include <hidl/HidlTransportSupport.h> |
| 26 | #include <hidl/LegacySupport.h> |
| 27 | |
| 28 | #include "MediaCasService.h" |
| 29 | |
| 30 | using android::hardware::configureRpcThreadpool; |
| 31 | using android::hardware::joinRpcThreadpool; |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 32 | using android::hardware::LazyServiceRegistrar; |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 33 | using android::hardware::cas::V1_0::IMediaCasService; |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 34 | using android::hardware::cas::V1_0::implementation::MediaCasService; |
| 35 | |
| 36 | #ifdef LAZY_SERVICE |
| 37 | const bool kLazyService = true; |
| 38 | #else |
| 39 | const bool kLazyService = false; |
| 40 | #endif |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 41 | |
| 42 | int main() { |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 43 | configureRpcThreadpool(8, true /* callerWillJoin */); |
| 44 | |
| 45 | // Setup hwbinder service |
| 46 | android::sp<IMediaCasService> service = new MediaCasService(); |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 47 | android::status_t status; |
| 48 | if (kLazyService) { |
| 49 | auto serviceRegistrar = std::make_shared<LazyServiceRegistrar>(); |
Peter Kalauskas | b4abef9 | 2019-01-03 15:23:12 -0800 | [diff] [blame] | 50 | status = serviceRegistrar->registerService(service); |
Peter Kalauskas | f646be0 | 2018-11-05 12:05:29 -0800 | [diff] [blame] | 51 | } else { |
| 52 | status = service->registerAsService(); |
| 53 | } |
| 54 | LOG_ALWAYS_FATAL_IF(status != android::OK, "Error while registering cas service: %d", status); |
| 55 | |
Chong Zhang | a4f6751 | 2017-04-24 17:18:25 -0700 | [diff] [blame] | 56 | joinRpcThreadpool(); |
| 57 | return 0; |
| 58 | } |