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> |
| 7 | #include <map> |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame^] | 8 | #include <unordered_map> |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 9 | |
| 10 | namespace android { |
| 11 | namespace hidl { |
| 12 | namespace manager { |
| 13 | namespace V1_0 { |
| 14 | namespace implementation { |
| 15 | |
| 16 | using ::android::hardware::hidl_vec; |
| 17 | using ::android::hardware::hidl_string; |
| 18 | using ::android::hardware::hidl_version; |
| 19 | using ::android::hardware::IBinder; |
| 20 | using ::android::hardware::Return; |
| 21 | using ::android::hardware::Void; |
| 22 | using ::android::hidl::manager::V1_0::IServiceManager; |
| 23 | using ::android::sp; |
| 24 | |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 25 | struct ServiceManager : public IServiceManager { |
| 26 | // Methods from ::android::hidl::manager::V1_0::IServiceManager follow. |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame^] | 27 | Return<void> get(const hidl_string& fqName, |
| 28 | const hidl_string& name, |
| 29 | get_cb _hidl_cb) override; |
| 30 | Return<bool> add(const hidl_vec<hidl_string>& interfaceChain, |
| 31 | const hidl_string& name, |
| 32 | const sp<IBinder>& service) override; |
| 33 | |
| 34 | struct HidlService { |
| 35 | HidlService(const std::string &iface, |
| 36 | const std::string &name, |
| 37 | const hidl_version &version, |
| 38 | const sp<IBinder> &service); |
| 39 | |
| 40 | sp<IBinder> getService() const; |
| 41 | void setService(sp<IBinder> service); |
| 42 | const std::string &getIface() const; |
| 43 | const std::string &getName() const; |
| 44 | const hidl_version &getVersion() const; |
| 45 | |
| 46 | bool supportsVersion(const hidl_version &version) const; |
| 47 | |
| 48 | static std::unique_ptr<HidlService> make( |
| 49 | const std::string &fqName, |
| 50 | const std::string &name, |
| 51 | const sp<IBinder>& service = nullptr); |
| 52 | |
| 53 | private: |
| 54 | const std::string mIface; // e.x. "android.hidl.manager::IServiceManager" |
| 55 | const std::string mName; // e.x. "manager" |
| 56 | const hidl_version mVersion; // e.x. { 1, 0 } |
| 57 | sp<IBinder> mService; |
| 58 | }; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame^] | 62 | /** |
| 63 | * Access to this map doesn't need to be locked, since hwservicemanager |
| 64 | * is single-threaded. |
| 65 | * |
| 66 | * e.x. |
| 67 | * mServiceMap["android.hidl.manager::IServiceManager"]["manager"] |
| 68 | * -> HidlService object |
| 69 | */ |
| 70 | std::unordered_map< |
| 71 | std::string, // package::interface e.x. "android.hidl.manager::IServiceManager" |
| 72 | std::multimap< |
| 73 | std::string, // name e.x. "manager" |
| 74 | std::unique_ptr<HidlService> |
| 75 | > |
| 76 | > mServiceMap; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace implementation |
| 80 | } // namespace V1_0 |
| 81 | } // namespace manager |
| 82 | } // namespace hidl |
| 83 | } // namespace android |
| 84 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame^] | 85 | #endif // ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |