The Android Open Source Project | e09fd9e | 2008-12-17 18:05:43 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdint.h> |
| 19 | #include <sys/types.h> |
| 20 | |
| 21 | #include <utils/Parcel.h> |
| 22 | #include <utils/IInterface.h> |
| 23 | |
| 24 | #include <ui/IOverlay.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | enum { |
| 29 | DESTROY = IBinder::FIRST_CALL_TRANSACTION, // one-way transaction |
| 30 | SWAP_BUFFERS, |
| 31 | }; |
| 32 | |
| 33 | class BpOverlay : public BpInterface<IOverlay> |
| 34 | { |
| 35 | public: |
| 36 | BpOverlay(const sp<IBinder>& impl) |
| 37 | : BpInterface<IOverlay>(impl) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | virtual void destroy() |
| 42 | { |
| 43 | Parcel data, reply; |
| 44 | data.writeInterfaceToken(IOverlay::getInterfaceDescriptor()); |
| 45 | remote()->transact(DESTROY, data, &reply, IBinder::FLAG_ONEWAY); |
| 46 | } |
| 47 | |
| 48 | virtual ssize_t swapBuffers() |
| 49 | { |
| 50 | Parcel data, reply; |
| 51 | data.writeInterfaceToken(IOverlay::getInterfaceDescriptor()); |
| 52 | remote()->transact(SWAP_BUFFERS, data, &reply); |
| 53 | return reply.readInt32(); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | IMPLEMENT_META_INTERFACE(Overlay, "android.ui.IOverlay"); |
| 58 | |
| 59 | // ---------------------------------------------------------------------- |
| 60 | |
| 61 | #define CHECK_INTERFACE(interface, data, reply) \ |
| 62 | do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \ |
| 63 | LOGW("Call incorrectly routed to " #interface); \ |
| 64 | return PERMISSION_DENIED; \ |
| 65 | } } while (0) |
| 66 | |
| 67 | status_t BnOverlay::onTransact( |
| 68 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 69 | { |
| 70 | switch(code) { |
| 71 | case DESTROY: { |
| 72 | CHECK_INTERFACE(IOverlay, data, reply); |
| 73 | destroy(); |
| 74 | return NO_ERROR; |
| 75 | } break; |
| 76 | case SWAP_BUFFERS: { |
| 77 | CHECK_INTERFACE(IOverlay, data, reply); |
| 78 | ssize_t offset = swapBuffers(); |
| 79 | reply->writeInt32(offset); |
| 80 | return NO_ERROR; |
| 81 | } break; |
| 82 | default: |
| 83 | return BBinder::onTransact(code, data, reply, flags); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | }; // namespace android |