summaryrefslogtreecommitdiff
path: root/transport/include/hidl/ServiceManagement.h
blob: a96203402cbd7e357ae46d1b100e7d4daee94bcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_HARDWARE_ISERVICE_MANAGER_H
#define ANDROID_HARDWARE_ISERVICE_MANAGER_H

#include <string>

#include <android/hidl/base/1.0/IBase.h>
#include <utils/StrongPointer.h>

namespace android {

namespace hidl {
namespace manager {
namespace V1_0 {
    struct IServiceManager;
}  // namespace V1_0
namespace V1_1 {
struct IServiceManager;
}  // namespace V1_1
namespace V1_2 {
struct IServiceManager;
}  // namespace V1_2
}  // namespace manager
}  // namespace hidl

namespace hardware {

namespace details {

// Will not attempt to start a lazy HAL
// e.x.: android.hardware.foo@1.0::IFoo, default
void waitForHwService(const std::string &interface, const std::string &instanceName);

void preloadPassthroughService(const std::string &descriptor);

// Returns a service with the following constraints:
// - retry => service is waited for and returned if available in this process
// - getStub => internal only. Forces to get the unwrapped (no BsFoo) if available.
// TODO(b/65843592)
// If the service is a remote service, this function returns BpBase. If the service is
// a passthrough service, this function returns the appropriately wrapped Bs child object.
sp<::android::hidl::base::V1_0::IBase> getRawServiceInternal(const std::string& descriptor,
                                                             const std::string& instance,
                                                             bool retry, bool getStub);

status_t registerAsServiceInternal(const sp<::android::hidl::base::V1_0::IBase>& service,
                                   const std::string& name);
}  // namespace details

// These functions are for internal use by hidl. If you want to get ahold
// of an interface, the best way to do this is by calling IFoo::getService()
sp<::android::hidl::manager::V1_0::IServiceManager> defaultServiceManager();
sp<::android::hidl::manager::V1_1::IServiceManager> defaultServiceManager1_1();
sp<::android::hidl::manager::V1_2::IServiceManager> defaultServiceManager1_2();
sp<::android::hidl::manager::V1_0::IServiceManager> getPassthroughServiceManager();
sp<::android::hidl::manager::V1_1::IServiceManager> getPassthroughServiceManager1_1();

/**
 * Given a service that is in passthrough mode, this function will go ahead and load the
 * required passthrough module library (but not call HIDL_FETCH_I* functions to instantiate it).
 *
 * E.x.: preloadPassthroughService<IFoo>();
 */
template<typename I>
static inline void preloadPassthroughService() {
    details::preloadPassthroughService(I::descriptor);
}

} // namespace hardware
} // namespace android

#endif // ANDROID_HARDWARE_ISERVICE_MANAGER_H