1/* 2 * Copyright (C) 2013 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 <stdint.h> 18#include <sys/types.h> 19 20#include <binder/IInterface.h> 21#include <binder/Parcel.h> 22 23#include <gui/IConsumerListener.h> 24#include <gui/BufferItem.h> 25 26// --------------------------------------------------------------------------- 27namespace android { 28// --------------------------------------------------------------------------- 29 30enum { 31 ON_FRAME_AVAILABLE = IBinder::FIRST_CALL_TRANSACTION, 32 ON_BUFFER_RELEASED, 33 ON_SIDEBAND_STREAM_CHANGED, 34}; 35 36class BpConsumerListener : public BpInterface<IConsumerListener> 37{ 38public: 39 BpConsumerListener(const sp<IBinder>& impl) 40 : BpInterface<IConsumerListener>(impl) { 41 } 42 43 virtual ~BpConsumerListener(); 44 45 virtual void onFrameAvailable(const BufferItem& item) { 46 Parcel data, reply; 47 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor()); 48 data.write(item); 49 remote()->transact(ON_FRAME_AVAILABLE, data, &reply, IBinder::FLAG_ONEWAY); 50 } 51 52 virtual void onBuffersReleased() { 53 Parcel data, reply; 54 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor()); 55 remote()->transact(ON_BUFFER_RELEASED, data, &reply, IBinder::FLAG_ONEWAY); 56 } 57 58 virtual void onSidebandStreamChanged() { 59 Parcel data, reply; 60 data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor()); 61 remote()->transact(ON_SIDEBAND_STREAM_CHANGED, data, &reply, IBinder::FLAG_ONEWAY); 62 } 63}; 64 65// Out-of-line virtual method definition to trigger vtable emission in this 66// translation unit (see clang warning -Wweak-vtables) 67BpConsumerListener::~BpConsumerListener() {} 68 69IMPLEMENT_META_INTERFACE(ConsumerListener, "android.gui.IConsumerListener"); 70 71// ---------------------------------------------------------------------- 72 73status_t BnConsumerListener::onTransact( 74 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) 75{ 76 switch(code) { 77 case ON_FRAME_AVAILABLE: { 78 CHECK_INTERFACE(IConsumerListener, data, reply); 79 BufferItem item; 80 data.read(item); 81 onFrameAvailable(item); 82 return NO_ERROR; } 83 case ON_BUFFER_RELEASED: { 84 CHECK_INTERFACE(IConsumerListener, data, reply); 85 onBuffersReleased(); 86 return NO_ERROR; } 87 case ON_SIDEBAND_STREAM_CHANGED: { 88 CHECK_INTERFACE(IConsumerListener, data, reply); 89 onSidebandStreamChanged(); 90 return NO_ERROR; } 91 } 92 return BBinder::onTransact(code, data, reply, flags); 93} 94 95 96// --------------------------------------------------------------------------- 97}; // namespace android 98// --------------------------------------------------------------------------- 99