blob: 185425e11cc673a5e1feb4e2bdae345e495502ba [file] [log] [blame]
Steven Morelandd83d1102016-10-25 15:01:47 -07001#ifndef HIDL_GENERATED_android_hardware_manager_V1_0_ServiceManager_H_
2#define HIDL_GENERATED_android_hardware_manager_V1_0_ServiceManager_H_
3
4#include <android/hidl/manager/1.0/IServiceManager.h>
5#include <hidl/Status.h>
6#include <hidl/MQDescriptor.h>
7#include <map>
8
9namespace android {
10namespace hidl {
11namespace manager {
12namespace V1_0 {
13namespace implementation {
14
15using ::android::hardware::hidl_vec;
16using ::android::hardware::hidl_string;
17using ::android::hardware::hidl_version;
18using ::android::hardware::IBinder;
19using ::android::hardware::Return;
20using ::android::hardware::Void;
21using ::android::hidl::manager::V1_0::IServiceManager;
22using ::android::sp;
23
24using Version = ::android::hidl::manager::V1_0::IServiceManager::Version;
25
26struct HidlService {
27 HidlService(const std::string &name,
28 const sp<IBinder>& service,
29 const Version& version,
30 const std::string &metaVersion)
31 : mName(name),
32 mVersion(version.major, version.minor),
33 mMetaVersion(metaVersion),
34 mService(service) {}
35
36 sp<IBinder> getService() const {
37 return mService;
38 }
39
40 void setService(const sp<IBinder>& service) {
41 mService = service;
42 }
43
44 const hidl_version& getVersion() const {
45 return mVersion;
46 }
47
48 bool supportsVersion(hidl_version version) {
49 if (version.get_major() == mVersion.get_major() &&
50 version.get_minor() <= mVersion.get_minor()) {
51 return true;
52 }
53 // TODO remove log
54 ALOGE("Service doesn't support version %u.%u", version.get_major(), version.get_minor());
55 return false;
56 }
57
58private:
59 const std::string mName;
60 const hidl_version mVersion;
61 const std::string mMetaVersion;
62 sp<IBinder> mService;
63};
64
65struct ServiceManager : public IServiceManager {
66 // Methods from ::android::hidl::manager::V1_0::IServiceManager follow.
67 Return<void> get(const hidl_string& name, const Version& version, get_cb _hidl_cb) override;
68 Return<bool> add(const hidl_string& name, const sp<IBinder>& service, const Version& version) override;
69
70private:
71
72 // Access to this map doesn't need to be locked, since hwservicemanager
73 // is single-threaded.
74 std::multimap<std::string, std::unique_ptr<HidlService>> mServiceMap;
75};
76
77} // namespace implementation
78} // namespace V1_0
79} // namespace manager
80} // namespace hidl
81} // namespace android
82
83#endif // HIDL_GENERATED_android_hardware_manager_V1_0_ServiceManager_H_