IConsumerListener.cpp revision a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0b
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
25// ---------------------------------------------------------------------------
26namespace android {
27// ---------------------------------------------------------------------------
28
29enum {
30    ON_FRAME_AVAILABLE = IBinder::FIRST_CALL_TRANSACTION,
31    ON_BUFFER_RELEASED
32};
33
34class BpConsumerListener : public BpInterface<IConsumerListener>
35{
36public:
37    BpConsumerListener(const sp<IBinder>& impl)
38        : BpInterface<IConsumerListener>(impl) {
39    }
40
41    virtual void onFrameAvailable() {
42        Parcel data, reply;
43        data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor());
44        remote()->transact(ON_FRAME_AVAILABLE, data, &reply, IBinder::FLAG_ONEWAY);
45    }
46
47    virtual void onBuffersReleased() {
48        Parcel data, reply;
49        data.writeInterfaceToken(IConsumerListener::getInterfaceDescriptor());
50        remote()->transact(ON_BUFFER_RELEASED, data, &reply, IBinder::FLAG_ONEWAY);
51    }
52};
53
54IMPLEMENT_META_INTERFACE(ConsumerListener, "android.gui.IConsumerListener");
55
56// ----------------------------------------------------------------------
57
58status_t BnConsumerListener::onTransact(
59    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
60{
61    switch(code) {
62        case ON_FRAME_AVAILABLE:
63            CHECK_INTERFACE(IConsumerListener, data, reply);
64            onFrameAvailable();
65            return NO_ERROR;
66        case ON_BUFFER_RELEASED:
67            CHECK_INTERFACE(IConsumerListener, data, reply);
68            onBuffersReleased();
69            return NO_ERROR;
70    }
71    return BBinder::onTransact(code, data, reply, flags);
72}
73
74
75// ---------------------------------------------------------------------------
76}; // namespace android
77// ---------------------------------------------------------------------------
78