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 | |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame^] | 34 | Return<void> list(list_cb _hidl_cb) override; |
| 35 | Return<void> listByInterface(const hidl_string& fqName, |
| 36 | listByInterface_cb _hidl_cb) override; |
| 37 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 38 | struct HidlService { |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame^] | 39 | HidlService(const std::string &package, |
| 40 | const std::string &interface, |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 41 | const std::string &name, |
| 42 | const hidl_version &version, |
| 43 | const sp<IBinder> &service); |
| 44 | |
| 45 | sp<IBinder> getService() const; |
| 46 | void setService(sp<IBinder> service); |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame^] | 47 | const std::string &getPackage() const; |
| 48 | const std::string &getInterface() const; |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 49 | const std::string &getName() const; |
| 50 | const hidl_version &getVersion() const; |
| 51 | |
| 52 | bool supportsVersion(const hidl_version &version) const; |
| 53 | |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame^] | 54 | std::string iface() const; // e.x. "android.hidl.manager::IServiceManager" |
| 55 | std::string string() const; // e.x. "android.hidl.manager@1.0::IServiceManager/manager" |
| 56 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 57 | static std::unique_ptr<HidlService> make( |
| 58 | const std::string &fqName, |
| 59 | const std::string &name, |
| 60 | const sp<IBinder>& service = nullptr); |
| 61 | |
| 62 | private: |
Steven Moreland | 7623781 | 2016-11-08 15:59:04 -0800 | [diff] [blame^] | 63 | const std::string mPackage; // e.x. "android.hidl.manager" |
| 64 | const std::string mInterface; // e.x. "IServiceManager" |
| 65 | const std::string mName; // e.x. "manager" |
| 66 | const hidl_version mVersion; // e.x. { 1, 0 } |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 67 | sp<IBinder> mService; |
| 68 | }; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 69 | |
| 70 | private: |
| 71 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 72 | /** |
| 73 | * Access to this map doesn't need to be locked, since hwservicemanager |
| 74 | * is single-threaded. |
| 75 | * |
| 76 | * e.x. |
| 77 | * mServiceMap["android.hidl.manager::IServiceManager"]["manager"] |
| 78 | * -> HidlService object |
| 79 | */ |
| 80 | std::unordered_map< |
| 81 | std::string, // package::interface e.x. "android.hidl.manager::IServiceManager" |
| 82 | std::multimap< |
| 83 | std::string, // name e.x. "manager" |
| 84 | std::unique_ptr<HidlService> |
| 85 | > |
| 86 | > mServiceMap; |
Steven Moreland | d83d110 | 2016-10-25 15:01:47 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // namespace implementation |
| 90 | } // namespace V1_0 |
| 91 | } // namespace manager |
| 92 | } // namespace hidl |
| 93 | } // namespace android |
| 94 | |
Steven Moreland | 5fb3d65 | 2016-11-03 13:45:18 -0700 | [diff] [blame] | 95 | #endif // ANDROID_HARDWARE_MANAGER_V1_0_SERVICEMANAGER_H |