blob: 175173fc2c5b8f9ae0ca36874ad44037af8263bd [file] [log] [blame]
Kevin Schoedel89af70b2017-03-03 18:11:37 -05001#include "VirtualTouchpadClient.h"
2
3#include <android/dvr/IVirtualTouchpadService.h>
4#include <binder/IServiceManager.h>
5
6namespace android {
7namespace dvr {
8
9namespace {
10
11class VirtualTouchpadClientImpl : public VirtualTouchpadClient {
12 public:
13 VirtualTouchpadClientImpl(sp<IVirtualTouchpadService> service)
14 : service_(service) {}
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050015 ~VirtualTouchpadClientImpl() override {}
Kevin Schoedel89af70b2017-03-03 18:11:37 -050016
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050017 status_t Touch(int touchpad,
18 float x, float y, float pressure) override {
Kevin Schoedel89af70b2017-03-03 18:11:37 -050019 if (service_ == nullptr) {
20 return NO_INIT;
21 }
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050022 return service_->touch(touchpad, x, y, pressure).transactionError();
Kevin Schoedel89af70b2017-03-03 18:11:37 -050023 }
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050024 status_t ButtonState(int touchpad, int buttons) override {
Kevin Schoedel89af70b2017-03-03 18:11:37 -050025 if (service_ == nullptr) {
26 return NO_INIT;
27 }
Kevin Schoedel3002b8a2017-03-06 14:34:39 -050028 return service_->buttonState(touchpad, buttons).transactionError();
Kevin Schoedel89af70b2017-03-03 18:11:37 -050029 }
30
31 private:
32 sp<IVirtualTouchpadService> service_;
33};
34
35} // anonymous namespace
36
37sp<VirtualTouchpad> VirtualTouchpadClient::Create() {
38 sp<IServiceManager> sm = defaultServiceManager();
39 if (sm == nullptr) {
40 ALOGE("no service manager");
41 return sp<VirtualTouchpad>();
42 }
43 sp<IVirtualTouchpadService> service = interface_cast<IVirtualTouchpadService>(
44 sm->getService(IVirtualTouchpadService::SERVICE_NAME()));
45 if (service == nullptr) {
46 ALOGE("failed to get service");
47 return sp<VirtualTouchpad>();
48 }
49 return new VirtualTouchpadClientImpl(service);
50}
51
52} // namespace dvr
53} // namespace android