Home | History | Annotate | Download | only in libmediadrm
      1 /*
      2 **
      3 ** Copyright 2013, The Android Open Source Project
      4 **
      5 ** Licensed under the Apache License, Version 2.0 (the "License");
      6 ** you may not use this file except in compliance with the License.
      7 ** You may obtain a copy of the License at
      8 **
      9 **     http://www.apache.org/licenses/LICENSE-2.0
     10 **
     11 ** Unless required by applicable law or agreed to in writing, software
     12 ** distributed under the License is distributed on an "AS IS" BASIS,
     13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 ** See the License for the specific language governing permissions and
     15 ** limitations under the License.
     16 */
     17 
     18 //#define LOG_NDEBUG 0
     19 #define LOG_TAG "IDrmClient"
     20 #include <utils/Log.h>
     21 
     22 #include <utils/RefBase.h>
     23 #include <binder/IInterface.h>
     24 #include <binder/Parcel.h>
     25 
     26 #include <media/IMediaPlayerClient.h>
     27 #include <mediadrm/IDrmClient.h>
     28 
     29 namespace android {
     30 
     31 enum {
     32     NOTIFY = IBinder::FIRST_CALL_TRANSACTION,
     33 };
     34 
     35 class BpDrmClient: public BpInterface<IDrmClient>
     36 {
     37 public:
     38     explicit BpDrmClient(const sp<IBinder>& impl)
     39         : BpInterface<IDrmClient>(impl)
     40     {
     41     }
     42 
     43     virtual void notify(DrmPlugin::EventType eventType, int extra, const Parcel *obj)
     44     {
     45         Parcel data, reply;
     46         data.writeInterfaceToken(IDrmClient::getInterfaceDescriptor());
     47         data.writeInt32((int)eventType);
     48         data.writeInt32(extra);
     49         if (obj && obj->dataSize() > 0) {
     50             data.appendFrom(const_cast<Parcel *>(obj), 0, obj->dataSize());
     51         }
     52         remote()->transact(NOTIFY, data, &reply, IBinder::FLAG_ONEWAY);
     53     }
     54 };
     55 
     56 IMPLEMENT_META_INTERFACE(DrmClient, "android.media.IDrmClient");
     57 
     58 // ----------------------------------------------------------------------
     59 
     60 status_t BnDrmClient::onTransact(
     61     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     62 {
     63     switch (code) {
     64         case NOTIFY: {
     65             CHECK_INTERFACE(IDrmClient, data, reply);
     66             int eventType = data.readInt32();
     67             int extra = data.readInt32();
     68             Parcel obj;
     69             if (data.dataAvail() > 0) {
     70                 obj.appendFrom(const_cast<Parcel *>(&data), data.dataPosition(), data.dataAvail());
     71             }
     72 
     73             notify((DrmPlugin::EventType)eventType, extra, &obj);
     74             return NO_ERROR;
     75         } break;
     76         default:
     77             return BBinder::onTransact(code, data, reply, flags);
     78     }
     79 }
     80 
     81 } // namespace android
     82