IEffectClient.cpp revision d71a1be83ff31cdb6599c351f9832cefc8d447ba
1/*
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
59    void commandExecuted(int cmdCode, int cmdSize, void *pCmdData, int replySize, void *pReplyData)
60    {
61        LOGV("commandExecuted");
62        Parcel data, reply;
63        data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
64        data.writeInt32(cmdCode);
65        int size = cmdSize;
66        if (pCmdData == NULL) {
67            size = 0;
68        }
69        data.writeInt32(size);
70        if (size) {
71            data.write(pCmdData, size);
72        }
73        size = replySize;
74        if (pReplyData == NULL) {
75            size = 0;
76        }
77        data.writeInt32(size);
78        if (size) {
79            data.write(pReplyData, size);
80        }
81        remote()->transact(COMMAND_EXECUTED, data, &reply, IBinder::FLAG_ONEWAY);
82    }
83
84};
85
86IMPLEMENT_META_INTERFACE(EffectClient, "android.media.IEffectClient");
87
88// ----------------------------------------------------------------------
89
90status_t BnEffectClient::onTransact(
91    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
92{
93    switch(code) {
94        case CONTROL_STATUS_CHANGED: {
95            LOGV("CONTROL_STATUS_CHANGED");
96            CHECK_INTERFACE(IEffectClient, data, reply);
97            bool hasControl = (bool)data.readInt32();
98            controlStatusChanged(hasControl);
99            return NO_ERROR;
100        } break;
101        case ENABLE_STATUS_CHANGED: {
102            LOGV("ENABLE_STATUS_CHANGED");
103            CHECK_INTERFACE(IEffectClient, data, reply);
104            bool enabled = (bool)data.readInt32();
105            enableStatusChanged(enabled);
106            return NO_ERROR;
107        } break;
108        case COMMAND_EXECUTED: {
109            LOGV("COMMAND_EXECUTED");
110            CHECK_INTERFACE(IEffectClient, data, reply);
111            int cmdCode = data.readInt32();
112            int cmdSize = data.readInt32();
113            char *cmd = NULL;
114            if (cmdSize) {
115                cmd = (char *)malloc(cmdSize);
116                data.read(cmd, cmdSize);
117            }
118            int replySize = data.readInt32();
119            char *resp = NULL;
120            if (replySize) {
121                resp = (char *)malloc(replySize);
122                data.read(resp, replySize);
123            }
124            commandExecuted(cmdCode, cmdSize, cmd, replySize, resp);
125            if (cmd) {
126                free(cmd);
127            }
128            if (resp) {
129                free(resp);
130            }
131            return NO_ERROR;
132        } break;
133        default:
134            return BBinder::onTransact(code, data, reply, flags);
135    }
136}
137
138// ----------------------------------------------------------------------------
139
140}; // namespace android
141
142