blob: 758384caf3e7950372c6bfd7e00acd42726b4fad [file] [log] [blame]
Martijn Coenen72110162016-08-19 14:28:25 +02001/*
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
26namespace android {
27namespace hardware {
28
Martijn Coenenc28f1152016-08-22 14:06:56 +020029class IServiceManager : virtual public RefBase
Martijn Coenen72110162016-08-19 14:28:25 +020030{
31public:
Martijn Coenen72110162016-08-19 14:28:25 +020032 /**
33 * Retrieve an existing service, blocking for a few seconds
34 * if it doesn't yet exist.
35 */
36 virtual sp<IBinder> getService( const String16& name,
37 const android::hardware::hidl_version& version
38 ) const = 0;
39
40 /**
41 * Retrieve an existing service, non-blocking.
42 */
43 virtual sp<IBinder> checkService( const String16& name,
44 const android::hardware::hidl_version& version
45 ) const = 0;
46
47 /**
48 * Register a service.
49 */
50 virtual status_t addService( const String16& name,
51 const sp<IBinder>& service,
52 const android::hardware::hidl_version& version,
53 bool allowIsolated = false) = 0;
54
Martijn Coenenc28f1152016-08-22 14:06:56 +020055};
56
57struct IHwServiceManager : public IServiceManager, public IInterface {
58 DECLARE_HWBINDER_META_INTERFACE(ServiceManager);
59
60 enum Call {
Martijn Coenen72110162016-08-19 14:28:25 +020061 GET_SERVICE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
62 CHECK_SERVICE_TRANSACTION,
63 ADD_SERVICE_TRANSACTION,
64 LIST_SERVICES_TRANSACTION,
65 };
66};
67
68sp<IServiceManager> defaultServiceManager();
69
70template<typename INTERFACE>
71status_t getService(const String16& name, android::hardware::hidl_version version,
72 sp<INTERFACE>* outService)
73{
74 const sp<IServiceManager> sm = defaultServiceManager();
75 if (sm != NULL) {
76 *outService = interface_cast<INTERFACE>(sm->getService(name, version));
77 if ((*outService) != NULL) return NO_ERROR;
78 }
79 return NAME_NOT_FOUND;
80}
81
82}; // namespace hardware
83}; // namespace android
84
85#endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H
86