blob: 6e42dac9e2a0603f46a3c8dae062a05842230e0d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2**
3** Copyright 2007, 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#include <stdint.h>
19#include <sys/types.h>
20
21#include <utils/Parcel.h>
22
23#include <media/IAudioRecord.h>
24
25namespace android {
26
27enum {
28 GET_CBLK = IBinder::FIRST_CALL_TRANSACTION,
29 START,
30 STOP
31};
32
33class BpAudioRecord : public BpInterface<IAudioRecord>
34{
35public:
36 BpAudioRecord(const sp<IBinder>& impl)
37 : BpInterface<IAudioRecord>(impl)
38 {
39 }
40
41 virtual status_t start()
42 {
43 Parcel data, reply;
44 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
45 remote()->transact(START, data, &reply);
46 return reply.readInt32();
47 }
48
49 virtual void stop()
50 {
51 Parcel data, reply;
52 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
53 remote()->transact(STOP, data, &reply);
54 }
55
56 virtual sp<IMemory> getCblk() const
57 {
58 Parcel data, reply;
59 data.writeInterfaceToken(IAudioRecord::getInterfaceDescriptor());
60 remote()->transact(GET_CBLK, data, &reply);
61 return interface_cast<IMemory>(reply.readStrongBinder());
62 }
63};
64
65IMPLEMENT_META_INTERFACE(AudioRecord, "android.media.IAudioRecord");
66
67// ----------------------------------------------------------------------
68
69#define CHECK_INTERFACE(interface, data, reply) \
70 do { if (!data.enforceInterface(interface::getInterfaceDescriptor())) { \
71 LOGW("Call incorrectly routed to " #interface); \
72 return PERMISSION_DENIED; \
73 } } while (0)
74
75status_t BnAudioRecord::onTransact(
76 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
77{
78 switch(code) {
79 case GET_CBLK: {
80 CHECK_INTERFACE(IAudioRecord, data, reply);
81 reply->writeStrongBinder(getCblk()->asBinder());
82 return NO_ERROR;
83 } break;
84 case START: {
85 CHECK_INTERFACE(IAudioRecord, data, reply);
86 reply->writeInt32(start());
87 return NO_ERROR;
88 } break;
89 case STOP: {
90 CHECK_INTERFACE(IAudioRecord, data, reply);
91 stop();
92 return NO_ERROR;
93 } break;
94 default:
95 return BBinder::onTransact(code, data, reply, flags);
96 }
97}
98
99}; // namespace android
100