Steven Moreland | 6f4fbe1 | 2017-07-21 18:07:42 -0700 | [diff] [blame] | 1 | #ifndef ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H |
| 2 | #define ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 3 | |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 4 | #include <set> |
| 5 | |
Steven Moreland | 6f4fbe1 | 2017-07-21 18:07:42 -0700 | [diff] [blame] | 6 | #include <android/hidl/manager/1.1/IServiceManager.h> |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 7 | #include <hidl/Status.h> |
| 8 | #include <hidl/MQDescriptor.h> |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 9 | |
| 10 | namespace android { |
| 11 | namespace hidl { |
| 12 | namespace manager { |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 13 | namespace implementation { |
| 14 | |
| 15 | using ::android::hardware::hidl_vec; |
| 16 | using ::android::hardware::hidl_string; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 17 | using ::android::hardware::Return; |
| 18 | using ::android::hardware::Void; |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 19 | using ::android::hidl::base::V1_0::IBase; |
Steven Moreland | 6f4fbe1 | 2017-07-21 18:07:42 -0700 | [diff] [blame] | 20 | using ::android::hidl::manager::V1_0::IServiceNotification; |
| 21 | using ::android::hidl::manager::V1_1::IServiceManager; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 22 | using ::android::sp; |
| 23 | |
| 24 | struct HidlService { |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 25 | HidlService(const std::string &interfaceName, |
| 26 | const std::string &instanceName, |
Steven Moreland | cdf9472 | 2017-03-21 12:16:31 -0700 | [diff] [blame] | 27 | const sp<IBase> &service, |
| 28 | const pid_t pid); |
| 29 | HidlService(const std::string &interfaceName, |
| 30 | const std::string &instanceName) |
| 31 | : HidlService( |
| 32 | interfaceName, |
| 33 | instanceName, |
| 34 | nullptr, |
| 35 | static_cast<pid_t>(IServiceManager::PidConstant::NO_PID)) |
| 36 | {} |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Note, getService() can be nullptr. This is because you can have a HidlService |
| 40 | * with registered IServiceNotification objects but no service registered yet. |
| 41 | */ |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 42 | sp<IBase> getService() const; |
Steven Moreland | cdf9472 | 2017-03-21 12:16:31 -0700 | [diff] [blame] | 43 | void setService(sp<IBase> service, pid_t pid); |
Steven Moreland | e609036 | 2019-01-03 17:51:17 -0800 | [diff] [blame] | 44 | pid_t getDebugPid() const; |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 45 | const std::string &getInterfaceName() const; |
| 46 | const std::string &getInstanceName() const; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 47 | |
| 48 | void addListener(const sp<IServiceNotification> &listener); |
Martijn Coenen | 7fafc14 | 2017-03-06 16:17:51 +0100 | [diff] [blame] | 49 | bool removeListener(const wp<IBase> &listener); |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 50 | void registerPassthroughClient(pid_t pid); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 51 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 52 | std::string string() const; // e.x. "android.hidl.manager@1.0::IServiceManager/manager" |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 53 | const std::set<pid_t> &getPassthroughClients() const; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 54 | |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 55 | private: |
Martijn Coenen | 72103a0 | 2017-01-18 16:06:34 +0100 | [diff] [blame] | 56 | void sendRegistrationNotifications(); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 57 | |
Steven Moreland | 6f4fbe1 | 2017-07-21 18:07:42 -0700 | [diff] [blame] | 58 | const std::string mInterfaceName; // e.x. "android.hidl.manager@1.0::IServiceManager" |
Steven Moreland | d544cf6 | 2017-01-04 15:24:32 -0800 | [diff] [blame] | 59 | const std::string mInstanceName; // e.x. "manager" |
Yifan Hong | b3a90f0 | 2016-11-23 12:58:04 -0800 | [diff] [blame] | 60 | sp<IBase> mService; |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 61 | |
| 62 | std::vector<sp<IServiceNotification>> mListeners{}; |
Yifan Hong | ee531a8 | 2017-02-03 15:10:18 -0800 | [diff] [blame] | 63 | std::set<pid_t> mPassthroughClients{}; |
Steven Moreland | cdf9472 | 2017-03-21 12:16:31 -0700 | [diff] [blame] | 64 | pid_t mPid = static_cast<pid_t>(IServiceManager::PidConstant::NO_PID); |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace implementation |
Steven Moreland | 2173d3c | 2016-11-09 15:00:58 -0800 | [diff] [blame] | 68 | } // namespace manager |
| 69 | } // namespace hidl |
| 70 | } // namespace android |
| 71 | |
Steven Moreland | 6f4fbe1 | 2017-07-21 18:07:42 -0700 | [diff] [blame] | 72 | #endif // ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H |