| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 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 |  | 
|  | 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); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 16 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 17 | ALOGE("onVsync failed to readInt64: %d", result); | 
|  | 18 | return result; | 
|  | 19 | } | 
|  | 20 | onVsync(vsync_timestamp); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 21 | return OK; | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 22 | } | 
|  | 23 | default: { | 
|  | 24 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 25 | } | 
|  | 26 | } | 
|  | 27 | } | 
|  | 28 |  | 
|  | 29 | class BpVsyncCallback : public BpInterface<IVsyncCallback> { | 
|  | 30 | public: | 
|  | 31 | explicit BpVsyncCallback(const sp<IBinder>& impl) | 
|  | 32 | : BpInterface<IVsyncCallback>(impl) {} | 
|  | 33 | virtual ~BpVsyncCallback() {} | 
|  | 34 |  | 
|  | 35 | virtual status_t onVsync(int64_t vsync_timestamp) { | 
|  | 36 | Parcel data, reply; | 
|  | 37 | status_t result = data.writeInterfaceToken( | 
|  | 38 | IVsyncCallback::getInterfaceDescriptor()); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 39 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 40 | ALOGE("onVsync failed to writeInterfaceToken: %d", result); | 
|  | 41 | return result; | 
|  | 42 | } | 
|  | 43 | result = data.writeInt64(vsync_timestamp); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 44 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 45 | ALOGE("onVsync failed to writeInt64: %d", result); | 
|  | 46 | return result; | 
|  | 47 | } | 
|  | 48 | result = remote()->transact( | 
|  | 49 | BnVsyncCallback::ON_VSYNC, data, &reply, TF_ONE_WAY); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 50 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 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 |  | 
|  | 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); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 68 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 69 | ALOGE("registerCallback failed to readStrongBinder: %d", result); | 
|  | 70 | return result; | 
|  | 71 | } | 
|  | 72 | registerCallback(interface_cast<IVsyncCallback>(callback)); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 73 | return OK; | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 74 | } | 
|  | 75 | case UNREGISTER_CALLBACK: { | 
|  | 76 | CHECK_INTERFACE(IVsyncService, data, reply); | 
|  | 77 | sp<IBinder> callback; | 
|  | 78 | status_t result = data.readStrongBinder(&callback); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 79 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 80 | ALOGE("unregisterCallback failed to readStrongBinder: %d", result); | 
|  | 81 | return result; | 
|  | 82 | } | 
|  | 83 | unregisterCallback(interface_cast<IVsyncCallback>(callback)); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 84 | return OK; | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 85 | } | 
|  | 86 | default: { | 
|  | 87 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 88 | } | 
|  | 89 | } | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | class BpVsyncService : public BpInterface<IVsyncService> { | 
|  | 93 | public: | 
|  | 94 | explicit BpVsyncService(const sp<IBinder>& impl) | 
|  | 95 | : BpInterface<IVsyncService>(impl) {} | 
|  | 96 | virtual ~BpVsyncService() {} | 
|  | 97 |  | 
|  | 98 | virtual status_t registerCallback(const sp<IVsyncCallback> callback) { | 
|  | 99 | Parcel data, reply; | 
|  | 100 | status_t result = data.writeInterfaceToken( | 
|  | 101 | IVsyncService::getInterfaceDescriptor()); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 102 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 103 | ALOGE("registerCallback failed to writeInterfaceToken: %d", result); | 
|  | 104 | return result; | 
|  | 105 | } | 
|  | 106 | result = data.writeStrongBinder(IInterface::asBinder(callback)); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 107 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 108 | ALOGE("registerCallback failed to writeStrongBinder: %d", result); | 
|  | 109 | return result; | 
|  | 110 | } | 
|  | 111 | result = remote()->transact( | 
|  | 112 | BnVsyncService::REGISTER_CALLBACK, data, &reply); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 113 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 114 | ALOGE("registerCallback failed to transact: %d", result); | 
|  | 115 | return result; | 
|  | 116 | } | 
|  | 117 | return result; | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | virtual status_t unregisterCallback(const sp<IVsyncCallback> callback) { | 
|  | 121 | Parcel data, reply; | 
|  | 122 | status_t result = data.writeInterfaceToken( | 
|  | 123 | IVsyncService::getInterfaceDescriptor()); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 124 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 125 | ALOGE("unregisterCallback failed to writeInterfaceToken: %d", result); | 
|  | 126 | return result; | 
|  | 127 | } | 
|  | 128 | result = data.writeStrongBinder(IInterface::asBinder(callback)); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 129 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 130 | ALOGE("unregisterCallback failed to writeStrongBinder: %d", result); | 
|  | 131 | return result; | 
|  | 132 | } | 
|  | 133 | result = remote()->transact( | 
|  | 134 | BnVsyncService::UNREGISTER_CALLBACK, data, &reply); | 
| Tianyu Jiang | 932fb4f | 2018-11-15 11:09:58 -0800 | [diff] [blame] | 135 | if (result != OK) { | 
| Steven Thomas | dfde8fa | 2018-04-19 16:00:58 -0700 | [diff] [blame] | 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 |