Martijn Coenen | 7211016 | 2016-08-19 14:28:25 +0200 | [diff] [blame] | 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 | // |
| 18 | #ifndef ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 19 | #define ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 20 | |
| 21 | #include <hidl/HidlSupport.h> |
| 22 | #include <hwbinder/IInterface.h> |
| 23 | #include <hwbinder/Parcel.h> |
| 24 | #include <utils/String16.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | |
| 29 | class IServiceManager : public IInterface |
| 30 | { |
| 31 | public: |
| 32 | DECLARE_HWBINDER_META_INTERFACE(ServiceManager); |
| 33 | |
| 34 | /** |
| 35 | * Retrieve an existing service, blocking for a few seconds |
| 36 | * if it doesn't yet exist. |
| 37 | */ |
| 38 | virtual sp<IBinder> getService( const String16& name, |
| 39 | const android::hardware::hidl_version& version |
| 40 | ) const = 0; |
| 41 | |
| 42 | /** |
| 43 | * Retrieve an existing service, non-blocking. |
| 44 | */ |
| 45 | virtual sp<IBinder> checkService( const String16& name, |
| 46 | const android::hardware::hidl_version& version |
| 47 | ) const = 0; |
| 48 | |
| 49 | /** |
| 50 | * Register a service. |
| 51 | */ |
| 52 | virtual status_t addService( const String16& name, |
| 53 | const sp<IBinder>& service, |
| 54 | const android::hardware::hidl_version& version, |
| 55 | bool allowIsolated = false) = 0; |
| 56 | |
| 57 | enum { |
| 58 | GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, |
| 59 | CHECK_SERVICE_TRANSACTION, |
| 60 | ADD_SERVICE_TRANSACTION, |
| 61 | LIST_SERVICES_TRANSACTION, |
| 62 | }; |
| 63 | }; |
| 64 | |
| 65 | sp<IServiceManager> defaultServiceManager(); |
| 66 | |
| 67 | template<typename INTERFACE> |
| 68 | status_t getService(const String16& name, android::hardware::hidl_version version, |
| 69 | sp<INTERFACE>* outService) |
| 70 | { |
| 71 | const sp<IServiceManager> sm = defaultServiceManager(); |
| 72 | if (sm != NULL) { |
| 73 | *outService = interface_cast<INTERFACE>(sm->getService(name, version)); |
| 74 | if ((*outService) != NULL) return NO_ERROR; |
| 75 | } |
| 76 | return NAME_NOT_FOUND; |
| 77 | } |
| 78 | |
| 79 | }; // namespace hardware |
| 80 | }; // namespace android |
| 81 | |
| 82 | #endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H |
| 83 | |