blob: 115ca7520220b0420619bebcae44f1119ec96870 [file] [log] [blame]
Eric Laurentd71a1be2010-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:
Chih-Hung Hsieh090ef602016-04-27 10:39:54 -070039 explicit BpEffect(const sp<IBinder>& impl)
Eric Laurentd71a1be2010-05-21 07:47:50 -070040 : BpInterface<IEffect>(impl)
41 {
42 }
43
44 status_t enable()
45 {
Steve Block3856b092011-10-20 11:56:00 +010046 ALOGV("enable");
Eric Laurentd71a1be2010-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 Block3856b092011-10-20 11:56:00 +010055 ALOGV("disable");
Eric Laurentd71a1be2010-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 Laurent25f43952010-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 Laurentd71a1be2010-05-21 07:47:50 -070067 {
Steve Block3856b092011-10-20 11:56:00 +010068 ALOGV("command");
Eric Laurentd71a1be2010-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 Grossmanaf7d8182012-01-11 12:23:42 -080086
87 status_t status = remote()->transact(COMMAND, data, &reply);
Andy Hung25a63442015-09-01 20:07:56 +000088 if (status == NO_ERROR) {
89 status = reply.readInt32();
90 }
John Grossmanaf7d8182012-01-11 12:23:42 -080091 if (status != NO_ERROR) {
92 if (pReplySize != NULL)
93 *pReplySize = 0;
94 return status;
95 }
96
Eric Laurentd71a1be2010-05-21 07:47:50 -070097 size = reply.readInt32();
98 if (size != 0 && pReplyData != NULL && pReplySize != NULL) {
99 reply.read(pReplyData, size);
100 *pReplySize = size;
101 }
102 return status;
103 }
104
105 void disconnect()
106 {
Steve Block3856b092011-10-20 11:56:00 +0100107 ALOGV("disconnect");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700108 Parcel data, reply;
109 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
110 remote()->transact(DISCONNECT, data, &reply);
111 return;
112 }
113
114 virtual sp<IMemory> getCblk() const
115 {
116 Parcel data, reply;
117 sp<IMemory> cblk;
118 data.writeInterfaceToken(IEffect::getInterfaceDescriptor());
119 status_t status = remote()->transact(GET_CBLK, data, &reply);
120 if (status == NO_ERROR) {
121 cblk = interface_cast<IMemory>(reply.readStrongBinder());
Glenn Kastena1d401d2013-11-20 14:37:13 -0800122 if (cblk != 0 && cblk->pointer() == NULL) {
123 cblk.clear();
124 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700125 }
126 return cblk;
127 }
128 };
129
130IMPLEMENT_META_INTERFACE(Effect, "android.media.IEffect");
131
132// ----------------------------------------------------------------------
133
134status_t BnEffect::onTransact(
135 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
136{
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700137 switch (code) {
Eric Laurentd71a1be2010-05-21 07:47:50 -0700138 case ENABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100139 ALOGV("ENABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700140 CHECK_INTERFACE(IEffect, data, reply);
141 reply->writeInt32(enable());
142 return NO_ERROR;
143 } break;
144
145 case DISABLE: {
Steve Block3856b092011-10-20 11:56:00 +0100146 ALOGV("DISABLE");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700147 CHECK_INTERFACE(IEffect, data, reply);
148 reply->writeInt32(disable());
149 return NO_ERROR;
150 } break;
151
152 case COMMAND: {
Steve Block3856b092011-10-20 11:56:00 +0100153 ALOGV("COMMAND");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700154 CHECK_INTERFACE(IEffect, data, reply);
Eric Laurent25f43952010-07-28 05:40:18 -0700155 uint32_t cmdCode = data.readInt32();
156 uint32_t cmdSize = data.readInt32();
Eric Laurentd71a1be2010-05-21 07:47:50 -0700157 char *cmd = NULL;
158 if (cmdSize) {
Andy Hungd0b59102015-08-26 16:34:33 -0700159 cmd = (char *)calloc(cmdSize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000160 if (cmd == NULL) {
161 reply->writeInt32(NO_MEMORY);
162 return NO_ERROR;
163 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700164 data.read(cmd, cmdSize);
165 }
Eric Laurent25f43952010-07-28 05:40:18 -0700166 uint32_t replySize = data.readInt32();
167 uint32_t replySz = replySize;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700168 char *resp = NULL;
169 if (replySize) {
Andy Hungd0b59102015-08-26 16:34:33 -0700170 resp = (char *)calloc(replySize, 1);
Andy Hung25a63442015-09-01 20:07:56 +0000171 if (resp == NULL) {
172 free(cmd);
173 reply->writeInt32(NO_MEMORY);
174 return NO_ERROR;
175 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700176 }
177 status_t status = command(cmdCode, cmdSize, cmd, &replySz, resp);
178 reply->writeInt32(status);
Andy Hung25a63442015-09-01 20:07:56 +0000179 if (status == NO_ERROR) {
180 if (replySz < replySize) {
181 replySize = replySz;
182 }
183 reply->writeInt32(replySize);
184 if (replySize) {
185 reply->write(resp, replySize);
186 }
Eric Laurentd71a1be2010-05-21 07:47:50 -0700187 }
188 if (cmd) {
189 free(cmd);
190 }
191 if (resp) {
192 free(resp);
193 }
194 return NO_ERROR;
195 } break;
196
197 case DISCONNECT: {
Steve Block3856b092011-10-20 11:56:00 +0100198 ALOGV("DISCONNECT");
Eric Laurentd71a1be2010-05-21 07:47:50 -0700199 CHECK_INTERFACE(IEffect, data, reply);
200 disconnect();
201 return NO_ERROR;
202 } break;
203
204 case GET_CBLK: {
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700205 CHECK_INTERFACE(IEffect, data, reply);
Marco Nelissen06b46062014-11-14 07:58:25 -0800206 reply->writeStrongBinder(IInterface::asBinder(getCblk()));
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700207 return NO_ERROR;
208 } break;
Eric Laurentd71a1be2010-05-21 07:47:50 -0700209
210 default:
211 return BBinder::onTransact(code, data, reply, flags);
212 }
213}
214
215// ----------------------------------------------------------------------------
216
Glenn Kasten40bc9062015-03-20 09:09:33 -0700217} // namespace android