Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 1 | #ifndef ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |
| 2 | #define ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 3 | |
| 4 | #include <android/hidl/manager/1.0/IServiceManager.h> |
| 5 | #include <hidl/Status.h> |
| 6 | #include <hidl/MQDescriptor.h> |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 7 | #include <map> |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 8 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 9 | #include "HidlService.h" |
| 10 | |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 11 | namespace android { |
| 12 | namespace hidl { |
| 13 | namespace manager { |
| 14 | namespace V1_0 { |
| 15 | namespace implementation { |
| 16 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 17 | using ::android::hardware::hidl_death_recipient; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 18 | using ::android::hardware::hidl_vec; |
| 19 | using ::android::hardware::hidl_string; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 20 | using ::android::hardware::Return; |
| 21 | using ::android::hardware::Void; |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 22 | using ::android::hidl::base::V1_0::IBase; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 23 | using ::android::hidl::manager::V1_0::IServiceManager; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 24 | using ::android::hidl::manager::V1_0::IServiceNotification; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 25 | using ::android::sp; |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 26 | using ::android::wp; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 27 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 28 | struct ServiceManager : public IServiceManager, hidl_death_recipient { |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 29 | // Methods from ::android::hidl::manager::V1_0::IServiceManager follow. |
Martijn Coenen | 7b02bf9 | 2017-01-02 15:17:58 +0100 | [diff] [blame] | 30 | Return<sp<IBase>> get(const hidl_string& fqName, |
Steven Moreland | 37aed80 | 2017-04-06 09:16:42 -0700 | [diff] [blame^] | 31 | const hidl_string& name) override; |
Martijn Coenen | 1a5da1c | 2017-03-06 13:05:39 +0100 | [diff] [blame] | 32 | Return<bool> add(const hidl_string& name, |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 33 | const sp<IBase>& service) override; |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 34 | |
Steven Moreland | 37aed80 | 2017-04-06 09:16:42 -0700 | [diff] [blame^] | 35 | Return<Transport> getTransport(const hidl_string& fqName, |
| 36 | const hidl_string& name); |
| 37 | |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame] | 38 | Return<void> list(list_cb _hidl_cb) override; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 39 | Return<void> listByInterface(const hidl_string& fqInstanceName, |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame] | 40 | listByInterface_cb _hidl_cb) override; |
| 41 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 42 | Return<bool> registerForNotifications(const hidl_string& fqName, |
| 43 | const hidl_string& name, |
| 44 | const sp<IServiceNotification>& callback) override; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 45 | |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 46 | Return<void> debugDump(debugDump_cb _cb) override; |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 47 | Return<void> registerPassthroughClient(const hidl_string &fqName, |
| 48 | const hidl_string &name, int32_t pid) override; |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 49 | |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 50 | virtual void serviceDied(uint64_t cookie, const wp<IBase>& who); |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 51 | private: |
Martijn Coenen | 46847a6 | 2016-12-19 05:36:12 +0100 | [diff] [blame] | 52 | bool remove(const wp<IBase>& who); |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 53 | bool removePackageListener(const wp<IBase>& who); |
| 54 | bool removeServiceListener(const wp<IBase>& who); |
Yifan Hong | 83c49f6 | 2017-01-25 14:16:34 -0800 | [diff] [blame] | 55 | size_t countExistingService() const; |
| 56 | void forEachExistingService(std::function<void(const HidlService *)> f) const; |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 57 | void forEachServiceEntry(std::function<void(const HidlService *)> f) const; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 58 | |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 59 | using InstanceMap = std::map< |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 60 | std::string, // instance name e.x. "manager" |
| 61 | std::unique_ptr<HidlService> |
| 62 | >; |
| 63 | |
| 64 | struct PackageInterfaceMap { |
| 65 | InstanceMap &getInstanceMap(); |
| 66 | const InstanceMap &getInstanceMap() const; |
| 67 | |
| 68 | /** |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 69 | * Finds a HidlService with the desired name. If none, |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 70 | * returns nullptr. HidlService::getService() might also be nullptr |
| 71 | * if there are registered IServiceNotification objects for it. Return |
| 72 | * value should be treated as a temporary reference. |
| 73 | */ |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 74 | HidlService *lookup( |
| 75 | const std::string &name); |
| 76 | const HidlService *lookup( |
| 77 | const std::string &name) const; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 78 | |
| 79 | void insertService(std::unique_ptr<HidlService> &&service); |
| 80 | |
| 81 | void addPackageListener(sp<IServiceNotification> listener); |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 82 | bool removePackageListener(const wp<IBase>& who); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 83 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 84 | void sendPackageRegistrationNotification( |
| 85 | const hidl_string &fqName, |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 86 | const hidl_string &instanceName); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 87 | |
Steven Moreland | 978473f | 2016-11-28 14:51:07 -0800 | [diff] [blame] | 88 | private: |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 89 | InstanceMap mInstanceMap{}; |
| 90 | |
| 91 | std::vector<sp<IServiceNotification>> mPackageListeners{}; |
| 92 | }; |
| 93 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 94 | /** |
| 95 | * Access to this map doesn't need to be locked, since hwservicemanager |
| 96 | * is single-threaded. |
| 97 | * |
| 98 | * e.x. |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 99 | * mServiceMap["android.hidl.manager@1.0::IServiceManager"]["manager"] |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 100 | * -> HidlService object |
| 101 | */ |
Steven Moreland | 6d7e500 | 2017-01-20 15:21:48 -0800 | [diff] [blame] | 102 | std::map< |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 103 | std::string, // package::interface e.x. "android.hidl.manager@1.0::IServiceManager" |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 104 | PackageInterfaceMap |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 105 | > mServiceMap; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | } // namespace implementation |
| 109 | } // namespace V1_0 |
| 110 | } // namespace manager |
| 111 | } // namespace hidl |
| 112 | } // namespace android |
| 113 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 114 | #endif // ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |