blob: 1fa9cbea7eba18f24b0dd9d33b8129ae867a7806 [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 {
43 LOGV("controlStatusChanged");
44 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 {
52 LOGV("enableStatusChanged");
53 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 {
65 LOGV("commandExecuted");
66 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{
97 switch(code) {
98 case CONTROL_STATUS_CHANGED: {
99 LOGV("CONTROL_STATUS_CHANGED");
100 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: {
106 LOGV("ENABLE_STATUS_CHANGED");
107 CHECK_INTERFACE(IEffectClient, data, reply);
108 bool enabled = (bool)data.readInt32();
109 enableStatusChanged(enabled);
110 return NO_ERROR;
111 } break;
112 case COMMAND_EXECUTED: {
113 LOGV("COMMAND_EXECUTED");
114 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
145