1 #include "include/private/dvr/vsync_service.h"
2
3 #include <binder/Parcel.h>
4 #include <log/log.h>
5
6 namespace android {
7 namespace dvr {
8
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)9 status_t BnVsyncCallback::onTransact(
10 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
11 switch (code) {
12 case ON_VSYNC: {
13 CHECK_INTERFACE(IVsyncCallback, data, reply);
14 int64_t vsync_timestamp = 0;
15 status_t result = data.readInt64(&vsync_timestamp);
16 if (result != OK) {
17 ALOGE("onVsync failed to readInt64: %d", result);
18 return result;
19 }
20 onVsync(vsync_timestamp);
21 return OK;
22 }
23 default: {
24 return BBinder::onTransact(code, data, reply, flags);
25 }
26 }
27 }
28
29 class BpVsyncCallback : public BpInterface<IVsyncCallback> {
30 public:
BpVsyncCallback(const sp<IBinder> & impl)31 explicit BpVsyncCallback(const sp<IBinder>& impl)
32 : BpInterface<IVsyncCallback>(impl) {}
~BpVsyncCallback()33 virtual ~BpVsyncCallback() {}
34
onVsync(int64_t vsync_timestamp)35 virtual status_t onVsync(int64_t vsync_timestamp) {
36 Parcel data, reply;
37 status_t result = data.writeInterfaceToken(
38 IVsyncCallback::getInterfaceDescriptor());
39 if (result != OK) {
40 ALOGE("onVsync failed to writeInterfaceToken: %d", result);
41 return result;
42 }
43 result = data.writeInt64(vsync_timestamp);
44 if (result != OK) {
45 ALOGE("onVsync failed to writeInt64: %d", result);
46 return result;
47 }
48 result = remote()->transact(BnVsyncCallback::ON_VSYNC, data, &reply,
49 IBinder::FLAG_ONEWAY);
50 if (result != OK) {
51 ALOGE("onVsync failed to transact: %d", result);
52 return result;
53 }
54 return result;
55 }
56 };
57
58 IMPLEMENT_META_INTERFACE(VsyncCallback, "android.dvr.IVsyncCallback");
59
60
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)61 status_t BnVsyncService::onTransact(
62 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
63 switch (code) {
64 case REGISTER_CALLBACK: {
65 CHECK_INTERFACE(IVsyncService, data, reply);
66 sp<IBinder> callback;
67 status_t result = data.readStrongBinder(&callback);
68 if (result != OK) {
69 ALOGE("registerCallback failed to readStrongBinder: %d", result);
70 return result;
71 }
72 registerCallback(interface_cast<IVsyncCallback>(callback));
73 return OK;
74 }
75 case UNREGISTER_CALLBACK: {
76 CHECK_INTERFACE(IVsyncService, data, reply);
77 sp<IBinder> callback;
78 status_t result = data.readStrongBinder(&callback);
79 if (result != OK) {
80 ALOGE("unregisterCallback failed to readStrongBinder: %d", result);
81 return result;
82 }
83 unregisterCallback(interface_cast<IVsyncCallback>(callback));
84 return OK;
85 }
86 default: {
87 return BBinder::onTransact(code, data, reply, flags);
88 }
89 }
90 }
91
92 class BpVsyncService : public BpInterface<IVsyncService> {
93 public:
BpVsyncService(const sp<IBinder> & impl)94 explicit BpVsyncService(const sp<IBinder>& impl)
95 : BpInterface<IVsyncService>(impl) {}
~BpVsyncService()96 virtual ~BpVsyncService() {}
97
registerCallback(const sp<IVsyncCallback> callback)98 virtual status_t registerCallback(const sp<IVsyncCallback> callback) {
99 Parcel data, reply;
100 status_t result = data.writeInterfaceToken(
101 IVsyncService::getInterfaceDescriptor());
102 if (result != OK) {
103 ALOGE("registerCallback failed to writeInterfaceToken: %d", result);
104 return result;
105 }
106 result = data.writeStrongBinder(IInterface::asBinder(callback));
107 if (result != OK) {
108 ALOGE("registerCallback failed to writeStrongBinder: %d", result);
109 return result;
110 }
111 result = remote()->transact(
112 BnVsyncService::REGISTER_CALLBACK, data, &reply);
113 if (result != OK) {
114 ALOGE("registerCallback failed to transact: %d", result);
115 return result;
116 }
117 return result;
118 }
119
unregisterCallback(const sp<IVsyncCallback> callback)120 virtual status_t unregisterCallback(const sp<IVsyncCallback> callback) {
121 Parcel data, reply;
122 status_t result = data.writeInterfaceToken(
123 IVsyncService::getInterfaceDescriptor());
124 if (result != OK) {
125 ALOGE("unregisterCallback failed to writeInterfaceToken: %d", result);
126 return result;
127 }
128 result = data.writeStrongBinder(IInterface::asBinder(callback));
129 if (result != OK) {
130 ALOGE("unregisterCallback failed to writeStrongBinder: %d", result);
131 return result;
132 }
133 result = remote()->transact(
134 BnVsyncService::UNREGISTER_CALLBACK, data, &reply);
135 if (result != OK) {
136 ALOGE("unregisterCallback failed to transact: %d", result);
137 return result;
138 }
139 return result;
140 }
141 };
142
143 IMPLEMENT_META_INTERFACE(VsyncService, "android.dvr.IVsyncService");
144
145 } // namespace dvr
146 } // namespace android
147