1/*
2 * Copyright 2016 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/IMediaResourceMonitor.h>
18#include <binder/Parcel.h>
19#include <utils/Errors.h>
20#include <sys/types.h>
21
22namespace android {
23
24// ----------------------------------------------------------------------
25
26class BpMediaResourceMonitor : public BpInterface<IMediaResourceMonitor> {
27public:
28    BpMediaResourceMonitor(const sp<IBinder>& impl)
29        : BpInterface<IMediaResourceMonitor>(impl) {}
30
31    virtual void notifyResourceGranted(/*in*/ int32_t pid, /*in*/ const int32_t type)
32    {
33        Parcel data, reply;
34        data.writeInterfaceToken(IMediaResourceMonitor::getInterfaceDescriptor());
35        data.writeInt32(pid);
36        data.writeInt32(type);
37        remote()->transact(NOTIFY_RESOURCE_GRANTED, data, &reply, IBinder::FLAG_ONEWAY);
38    }
39};
40
41IMPLEMENT_META_INTERFACE(MediaResourceMonitor, "android.media.IMediaResourceMonitor");
42
43// ----------------------------------------------------------------------
44
45status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, Parcel* reply,
46        uint32_t flags) {
47    switch(code) {
48        case NOTIFY_RESOURCE_GRANTED: {
49            CHECK_INTERFACE(IMediaResourceMonitor, data, reply);
50            int32_t pid = data.readInt32();
51            const int32_t type = data.readInt32();
52            notifyResourceGranted(/*in*/ pid, /*in*/ type);
53            return NO_ERROR;
54        } break;
55        default:
56            return BBinder::onTransact(code, data, reply, flags);
57    }
58}
59
60// ----------------------------------------------------------------------
61
62}; // namespace android
63