blob: a303a8fcd820d105c44efcf13106a095ac2b0ef6 [file] [log] [blame]
Eric Laurentc0f34382010-05-21 07:47:50 -07001/*
2**
3** Copyright 2010, 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 "IEffect"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <binder/Parcel.h>
24#include <media/IEffect.h>
25
26namespace android {
27
28enum {
29 ENABLE = IBinder::FIRST_CALL_TRANSACTION,
30 DISABLE,
31 COMMAND,
32 DISCONNECT,
33 GET_CBLK
34};
35
36class BpEffect: public BpInterface<IEffect>
37{
38public:
39 BpEffect(const sp<IBinder>& impl)
40 : BpInterface<IEffect>(impl)
41 {
42 }
43
44 status_t enable()
45 {
Steve Block71f2cf12011-10-20 11:56:00 +010046 ALOGV("enable");
Eric Laurentc0f34382010-05-21 07:47:50 -070047 Parcel data, reply;
48 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
49 remote()->transact(ENABLE, data, &reply);
50 return reply.readInt32();
51 }
52
53 status_t disable()
54 {
Steve Block71f2cf12011-10-20 11:56:00 +010055 ALOGV("disable");
Eric Laurentc0f34382010-05-21 07:47:50 -070056 Parcel data, reply;
57 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
58 remote()->transact(DISABLE, data, &reply);
59 return reply.readInt32();
60 }
61
Eric Laurenta4c72ac2010-07-28 05:40:18 -070062 status_t command(uint32_t cmdCode,
63 uint32_t cmdSize,
64 void *pCmdData,
65 uint32_t *pReplySize,
66 void *pReplyData)
Eric Laurentc0f34382010-05-21 07:47:50 -070067 {
Steve Block71f2cf12011-10-20 11:56:00 +010068 ALOGV("command");
Eric Laurentc0f34382010-05-21 07:47:50 -070069 Parcel data, reply;
70 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
71 data.writeInt32(cmdCode);
72 int size = cmdSize;
73 if (pCmdData == NULL) {
74 size = 0;
75 }
76 data.writeInt32(size);
77 if (size) {
78 data.write(pCmdData, size);
79 }
80 if (pReplySize == NULL) {
81 size = 0;
82 } else {
83 size = *pReplySize;
84 }
85 data.writeInt32(size);
John Grossman3540a012012-01-11 12:23:42 -080086
87 status_t status = remote()->transact(COMMAND, data, &reply);
88 if (status != NO_ERROR) {
89 if (pReplySize != NULL)
90 *pReplySize = 0;
91 return status;
92 }
93
94 status = reply.readInt32();
Eric Laurentc0f34382010-05-21 07:47:50 -070095 size = reply.readInt32();
96 if (size != 0 && pReplyData != NULL && pReplySize != NULL) {
97 reply.read(pReplyData, size);
98 *pReplySize = size;
99 }
100 return status;
101 }
102
103 void disconnect()
104 {
Steve Block71f2cf12011-10-20 11:56:00 +0100105 ALOGV("disconnect");
Eric Laurentc0f34382010-05-21 07:47:50 -0700106 Parcel data, reply;
107 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
108 remote()->transact(DISCONNECT, data, &reply);
109 return;
110 }
111
112 virtual sp<IMemory> getCblk() const
113 {
114 Parcel data, reply;
115 sp<IMemory> cblk;
116 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
117 status_t status = remote()->transact(GET_CBLK, data, &reply);
118 if (status == NO_ERROR) {
119 cblk = interface_cast<IMemory>(reply.readStrongBinder());
120 }
121 return cblk;
122 }
123 };
124
125IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect");
126
127// ----------------------------------------------------------------------
128
129status_t BnEffect::onTransact(
130 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
131{
Glenn Kasten18db49a2012-03-12 16:29:55 -0700132 switch (code) {
Eric Laurentc0f34382010-05-21 07:47:50 -0700133 case ENABLE: {
Steve Block71f2cf12011-10-20 11:56:00 +0100134 ALOGV("ENABLE");
Eric Laurentc0f34382010-05-21 07:47:50 -0700135 CHECK_INTERFACE(IEffect, data, reply);
136 reply->writeInt32(enable());
137 return NO_ERROR;
138 } break;
139
140 case DISABLE: {
Steve Block71f2cf12011-10-20 11:56:00 +0100141 ALOGV("DISABLE");
Eric Laurentc0f34382010-05-21 07:47:50 -0700142 CHECK_INTERFACE(IEffect, data, reply);
143 reply->writeInt32(disable());
144 return NO_ERROR;
145 } break;
146
147 case COMMAND: {
Steve Block71f2cf12011-10-20 11:56:00 +0100148 ALOGV("COMMAND");
Eric Laurentc0f34382010-05-21 07:47:50 -0700149 CHECK_INTERFACE(IEffect, data, reply);
Eric Laurenta4c72ac2010-07-28 05:40:18 -0700150 uint32_t cmdCode = data.readInt32();
151 uint32_t cmdSize = data.readInt32();
Eric Laurentc0f34382010-05-21 07:47:50 -0700152 char *cmd = NULL;
153 if (cmdSize) {
154 cmd = (char *)malloc(cmdSize);
155 data.read(cmd, cmdSize);
156 }
Eric Laurenta4c72ac2010-07-28 05:40:18 -0700157 uint32_t replySize = data.readInt32();
158 uint32_t replySz = replySize;
Eric Laurentc0f34382010-05-21 07:47:50 -0700159 char *resp = NULL;
160 if (replySize) {
161 resp = (char *)malloc(replySize);
162 }
163 status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp);
164 reply->writeInt32(status);
165 if (replySz < replySize) {
166 replySize = replySz;
167 }
168 reply->writeInt32(replySize);
169 if (replySize) {
170 reply->write(resp, replySize);
171 }
172 if (cmd) {
173 free(cmd);
174 }
175 if (resp) {
176 free(resp);
177 }
178 return NO_ERROR;
179 } break;
180
181 case DISCONNECT: {
Steve Block71f2cf12011-10-20 11:56:00 +0100182 ALOGV("DISCONNECT");
Eric Laurentc0f34382010-05-21 07:47:50 -0700183 CHECK_INTERFACE(IEffect, data, reply);
184 disconnect();
185 return NO_ERROR;
186 } break;
187
188 case GET_CBLK: {
Glenn Kasten18db49a2012-03-12 16:29:55 -0700189 CHECK_INTERFACE(IEffect, data, reply);
190 reply->writeStrongBinder(getCblk()->asBinder());
191 return NO_ERROR;
192 } break;
Eric Laurentc0f34382010-05-21 07:47:50 -0700193
194 default:
195 return BBinder::onTransact(code, data, reply, flags);
196 }
197}
198
199// ----------------------------------------------------------------------------
200
201}; // namespace android