blob: 64fdabb706b78e422218ee799dfc235be04ac975 [file] [log] [blame]
Steven Moreland6f4fbe12017-07-21 18:07:42 -07001#ifndef ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H
2#define ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H
Steven Moreland2173d3c2016-11-09 15:00:58 -08003
Yifan Hongee531a82017-02-03 15:10:18 -08004#include <set>
5
Steven Moreland6f4fbe12017-07-21 18:07:42 -07006#include <android/hidl/manager/1.1/IServiceManager.h>
Steven Moreland2173d3c2016-11-09 15:00:58 -08007#include <hidl/Status.h>
8#include <hidl/MQDescriptor.h>
Steven Moreland2173d3c2016-11-09 15:00:58 -08009
10namespace android {
11namespace hidl {
12namespace manager {
Steven Moreland2173d3c2016-11-09 15:00:58 -080013namespace implementation {
14
15using ::android::hardware::hidl_vec;
16using ::android::hardware::hidl_string;
Steven Moreland2173d3c2016-11-09 15:00:58 -080017using ::android::hardware::Return;
18using ::android::hardware::Void;
Yifan Hongb3a90f02016-11-23 12:58:04 -080019using ::android::hidl::base::V1_0::IBase;
Steven Moreland6f4fbe12017-07-21 18:07:42 -070020using ::android::hidl::manager::V1_0::IServiceNotification;
21using ::android::hidl::manager::V1_1::IServiceManager;
Steven Moreland2173d3c2016-11-09 15:00:58 -080022using ::android::sp;
23
24struct HidlService {
Steven Morelandd544cf62017-01-04 15:24:32 -080025 HidlService(const std::string &interfaceName,
26 const std::string &instanceName,
Steven Morelandcdf94722017-03-21 12:16:31 -070027 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 Moreland2173d3c2016-11-09 15:00:58 -080037
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 Hongb3a90f02016-11-23 12:58:04 -080042 sp<IBase> getService() const;
Steven Morelandcdf94722017-03-21 12:16:31 -070043 void setService(sp<IBase> service, pid_t pid);
Steven Morelande6090362019-01-03 17:51:17 -080044 pid_t getDebugPid() const;
Steven Morelandd544cf62017-01-04 15:24:32 -080045 const std::string &getInterfaceName() const;
46 const std::string &getInstanceName() const;
Steven Moreland2173d3c2016-11-09 15:00:58 -080047
48 void addListener(const sp<IServiceNotification> &listener);
Martijn Coenen7fafc142017-03-06 16:17:51 +010049 bool removeListener(const wp<IBase> &listener);
Yifan Hongee531a82017-02-03 15:10:18 -080050 void registerPassthroughClient(pid_t pid);
Steven Moreland2173d3c2016-11-09 15:00:58 -080051
Steven Moreland2173d3c2016-11-09 15:00:58 -080052 std::string string() const; // e.x. "android.hidl.manager@1.0::IServiceManager/manager"
Yifan Hongee531a82017-02-03 15:10:18 -080053 const std::set<pid_t> &getPassthroughClients() const;
Steven Moreland2173d3c2016-11-09 15:00:58 -080054
Steven Moreland2173d3c2016-11-09 15:00:58 -080055private:
Martijn Coenen72103a02017-01-18 16:06:34 +010056 void sendRegistrationNotifications();
Steven Moreland2173d3c2016-11-09 15:00:58 -080057
Steven Moreland6f4fbe12017-07-21 18:07:42 -070058 const std::string mInterfaceName; // e.x. "android.hidl.manager@1.0::IServiceManager"
Steven Morelandd544cf62017-01-04 15:24:32 -080059 const std::string mInstanceName; // e.x. "manager"
Yifan Hongb3a90f02016-11-23 12:58:04 -080060 sp<IBase> mService;
Steven Moreland2173d3c2016-11-09 15:00:58 -080061
62 std::vector<sp<IServiceNotification>> mListeners{};
Yifan Hongee531a82017-02-03 15:10:18 -080063 std::set<pid_t> mPassthroughClients{};
Steven Morelandcdf94722017-03-21 12:16:31 -070064 pid_t mPid = static_cast<pid_t>(IServiceManager::PidConstant::NO_PID);
Steven Moreland2173d3c2016-11-09 15:00:58 -080065};
66
67} // namespace implementation
Steven Moreland2173d3c2016-11-09 15:00:58 -080068} // namespace manager
69} // namespace hidl
70} // namespace android
71
Steven Moreland6f4fbe12017-07-21 18:07:42 -070072#endif // ANDROID_HARDWARE_MANAGER_HIDLSERVICE_H