1 #ifndef ANDROID_HARDWARE_MANAGER_V1_0_HIDLSERVICE_H 2 #define ANDROID_HARDWARE_MANAGER_V1_0_HIDLSERVICE_H 3 4 #include <set> 5 6 #include <android/hidl/manager/1.0/IServiceManager.h> 7 #include <hidl/Status.h> 8 #include <hidl/MQDescriptor.h> 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::Return; 19 using ::android::hardware::Void; 20 using ::android::hidl::base::V1_0::IBase; 21 using ::android::hidl::manager::V1_0::IServiceManager; 22 using ::android::sp; 23 24 struct HidlService { 25 HidlService(const std::string &interfaceName, 26 const std::string &instanceName, 27 const sp<IBase> &service, 28 const pid_t pid); HidlServiceHidlService29 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 {} 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 */ 42 sp<IBase> getService() const; 43 void setService(sp<IBase> service, pid_t pid); 44 pid_t getPid() const; 45 const std::string &getInterfaceName() const; 46 const std::string &getInstanceName() const; 47 48 void addListener(const sp<IServiceNotification> &listener); 49 bool removeListener(const wp<IBase> &listener); 50 void registerPassthroughClient(pid_t pid); 51 52 std::string string() const; // e.x. "android.hidl.manager@1.0::IServiceManager/manager" 53 const std::set<pid_t> &getPassthroughClients() const; 54 55 private: 56 void sendRegistrationNotifications(); 57 58 const std::string mInterfaceName; // e.x. "android.hardware.manager@1.0::IServiceManager" 59 const std::string mInstanceName; // e.x. "manager" 60 sp<IBase> mService; 61 62 std::vector<sp<IServiceNotification>> mListeners{}; 63 std::set<pid_t> mPassthroughClients{}; 64 pid_t mPid = static_cast<pid_t>(IServiceManager::PidConstant::NO_PID); 65 }; 66 67 } // namespace implementation 68 } // namespace V1_0 69 } // namespace manager 70 } // namespace hidl 71 } // namespace android 72 73 #endif // ANDROID_HARDWARE_MANAGER_V1_0_HIDLSERVICE_H 74