Home | History | Annotate | Download | only in gui
      1 /*
      2  * Copyright 2014 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 <binder/Parcel.h>
     18 
     19 #include <gui/IProducerListener.h>
     20 
     21 namespace android {
     22 
     23 enum {
     24     ON_BUFFER_RELEASED = IBinder::FIRST_CALL_TRANSACTION,
     25     NEEDS_RELEASE_NOTIFY,
     26 };
     27 
     28 class BpProducerListener : public BpInterface<IProducerListener>
     29 {
     30 public:
     31     explicit BpProducerListener(const sp<IBinder>& impl)
     32         : BpInterface<IProducerListener>(impl) {}
     33 
     34     virtual ~BpProducerListener();
     35 
     36     virtual void onBufferReleased() {
     37         Parcel data, reply;
     38         data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
     39         remote()->transact(ON_BUFFER_RELEASED, data, &reply, IBinder::FLAG_ONEWAY);
     40     }
     41 
     42     virtual bool needsReleaseNotify() {
     43         bool result;
     44         Parcel data, reply;
     45         data.writeInterfaceToken(IProducerListener::getInterfaceDescriptor());
     46         status_t err = remote()->transact(NEEDS_RELEASE_NOTIFY, data, &reply);
     47         if (err != NO_ERROR) {
     48             ALOGE("IProducerListener: binder call \'needsReleaseNotify\' failed");
     49             return true;
     50         }
     51         err = reply.readBool(&result);
     52         if (err != NO_ERROR) {
     53             ALOGE("IProducerListener: malformed binder reply");
     54             return true;
     55         }
     56         return result;
     57     }
     58 };
     59 
     60 // Out-of-line virtual method definition to trigger vtable emission in this
     61 // translation unit (see clang warning -Wweak-vtables)
     62 BpProducerListener::~BpProducerListener() {}
     63 
     64 IMPLEMENT_META_INTERFACE(ProducerListener, "android.gui.IProducerListener")
     65 
     66 status_t BnProducerListener::onTransact(uint32_t code, const Parcel& data,
     67         Parcel* reply, uint32_t flags) {
     68     switch (code) {
     69         case ON_BUFFER_RELEASED:
     70             CHECK_INTERFACE(IProducerListener, data, reply);
     71             onBufferReleased();
     72             return NO_ERROR;
     73         case NEEDS_RELEASE_NOTIFY:
     74             CHECK_INTERFACE(IProducerListener, data, reply);
     75             reply->writeBool(needsReleaseNotify());
     76             return NO_ERROR;
     77     }
     78     return BBinder::onTransact(code, data, reply, flags);
     79 }
     80 
     81 ProducerListener::~ProducerListener() = default;
     82 
     83 DummyProducerListener::~DummyProducerListener() = default;
     84 
     85 bool BnProducerListener::needsReleaseNotify() {
     86     return true;
     87 }
     88 
     89 } // namespace android
     90