blob: aef4371d2912dfddfa1c50b3814b11370bff126c [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 "IEffectClient"
20#include <utils/Log.h>
21#include <stdint.h>
22#include <sys/types.h>
23#include <media/IEffectClient.h>
24
25namespace android {
26
27enum {
28 CONTROL_STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
29 ENABLE_STATUS_CHANGED,
30 COMMAND_EXECUTED
31};
32
33class BpEffectClient: public BpInterface<IEffectClient>
34{
35public:
36 BpEffectClient(const sp<IBinder>& impl)
37 : BpInterface<IEffectClient>(impl)
38 {
39 }
40
41 void controlStatusChanged(bool controlGranted)
42 {
Steve Block71f2cf12011-10-20 11:56:00 +010043 ALOGV("controlStatusChanged");
Eric Laurentc0f34382010-05-21 07:47:50 -070044 Parcel data, reply;
45 data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
46 data.writeInt32((uint32_t)controlGranted);
47 remote()->transact(CONTROL_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
48 }
49
50 void enableStatusChanged(bool enabled)
51 {
Steve Block71f2cf12011-10-20 11:56:00 +010052 ALOGV("enableStatusChanged");
Eric Laurentc0f34382010-05-21 07:47:50 -070053 Parcel data, reply;
54 data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
55 data.writeInt32((uint32_t)enabled);
56 remote()->transact(ENABLE_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
57 }
58
Eric Laurenta4c72ac2010-07-28 05:40:18 -070059 void commandExecuted(uint32_t cmdCode,
60 uint32_t cmdSize,
61 void *pCmdData,
62 uint32_t replySize,
63 void *pReplyData)
Eric Laurentc0f34382010-05-21 07:47:50 -070064 {
Steve Block71f2cf12011-10-20 11:56:00 +010065 ALOGV("commandExecuted");
Eric Laurentc0f34382010-05-21 07:47:50 -070066 Parcel data, reply;
67 data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
68 data.writeInt32(cmdCode);
69 int size = cmdSize;
70 if (pCmdData == NULL) {
71 size = 0;
72 }
73 data.writeInt32(size);
74 if (size) {
75 data.write(pCmdData, size);
76 }
77 size = replySize;
78 if (pReplyData == NULL) {
79 size = 0;
80 }
81 data.writeInt32(size);
82 if (size) {
83 data.write(pReplyData, size);
84 }
85 remote()->transact(COMMAND_EXECUTED, data, &reply, IBinder::FLAG_ONEWAY);
86 }
87
88};
89
90IMPLEMENT_META_INTERFACE(EffectClient, "android.media.IEffectClient");
91
92// ----------------------------------------------------------------------
93
94status_t BnEffectClient::onTransact(
95 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
96{
Glenn Kasten18db49a2012-03-12 16:29:55 -070097 switch (code) {
Eric Laurentc0f34382010-05-21 07:47:50 -070098 case CONTROL_STATUS_CHANGED: {
Steve Block71f2cf12011-10-20 11:56:00 +010099 ALOGV("CONTROL_STATUS_CHANGED");
Eric Laurentc0f34382010-05-21 07:47:50 -0700100 CHECK_INTERFACE(IEffectClient, data, reply);
101 bool hasControl = (bool)data.readInt32();
102 controlStatusChanged(hasControl);
103 return NO_ERROR;
104 } break;
105 case ENABLE_STATUS_CHANGED: {
Steve Block71f2cf12011-10-20 11:56:00 +0100106 ALOGV("ENABLE_STATUS_CHANGED");
Eric Laurentc0f34382010-05-21 07:47:50 -0700107 CHECK_INTERFACE(IEffectClient, data, reply);
108 bool enabled = (bool)data.readInt32();
109 enableStatusChanged(enabled);
110 return NO_ERROR;
111 } break;
112 case COMMAND_EXECUTED: {
Steve Block71f2cf12011-10-20 11:56:00 +0100113 ALOGV("COMMAND_EXECUTED");
Eric Laurentc0f34382010-05-21 07:47:50 -0700114 CHECK_INTERFACE(IEffectClient, data, reply);
Eric Laurenta4c72ac2010-07-28 05:40:18 -0700115 uint32_t cmdCode = data.readInt32();
116 uint32_t cmdSize = data.readInt32();
Eric Laurentc0f34382010-05-21 07:47:50 -0700117 char *cmd = NULL;
118 if (cmdSize) {
119 cmd = (char *)malloc(cmdSize);
120 data.read(cmd, cmdSize);
121 }
Eric Laurenta4c72ac2010-07-28 05:40:18 -0700122 uint32_t replySize = data.readInt32();
Eric Laurentc0f34382010-05-21 07:47:50 -0700123 char *resp = NULL;
124 if (replySize) {
125 resp = (char *)malloc(replySize);
126 data.read(resp, replySize);
127 }
128 commandExecuted(cmdCode, cmdSize, cmd, replySize, resp);
129 if (cmd) {
130 free(cmd);
131 }
132 if (resp) {
133 free(resp);
134 }
135 return NO_ERROR;
136 } break;
137 default:
138 return BBinder::onTransact(code, data, reply, flags);
139 }
140}
141
142// ----------------------------------------------------------------------------
143
144}; // namespace android