IEffectClient.cpp revision d71a1be83ff31cdb6599c351f9832cefc8d447ba
1d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent/*
2d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent**
3d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Copyright 2010, The Android Open Source Project
4d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent**
5d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Licensed under the Apache License, Version 2.0 (the "License");
6d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** you may not use this file except in compliance with the License.
7d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** You may obtain a copy of the License at
8d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent**
9d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent**     http://www.apache.org/licenses/LICENSE-2.0
10d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent**
11d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** Unless required by applicable law or agreed to in writing, software
12d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** distributed under the License is distributed on an "AS IS" BASIS,
13d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** See the License for the specific language governing permissions and
15d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent** limitations under the License.
16d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent*/
17d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
18d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent//#define LOG_NDEBUG 0
19d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#define LOG_TAG "IEffectClient"
20d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <utils/Log.h>
21d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <stdint.h>
22d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <sys/types.h>
23d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent#include <media/IEffectClient.h>
24d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
25d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentnamespace android {
26d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
27d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentenum {
28d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    CONTROL_STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
29d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    ENABLE_STATUS_CHANGED,
30d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    COMMAND_EXECUTED
31d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent};
32d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
33d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentclass BpEffectClient: public BpInterface<IEffectClient>
34d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent{
35d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentpublic:
36d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    BpEffectClient(const sp<IBinder>& impl)
37d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        : BpInterface<IEffectClient>(impl)
38d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    {
39d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    }
40d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
41d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    void controlStatusChanged(bool controlGranted)
42d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    {
43d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        LOGV("controlStatusChanged");
44d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        Parcel data, reply;
45d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
46d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInt32((uint32_t)controlGranted);
47d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        remote()->transact(CONTROL_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
48d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    }
49d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
50d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    void enableStatusChanged(bool enabled)
51d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    {
52d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        LOGV("enableStatusChanged");
53d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        Parcel data, reply;
54d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
55d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInt32((uint32_t)enabled);
56d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        remote()->transact(ENABLE_STATUS_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
57d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    }
58d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
59d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    void commandExecuted(int cmdCode, int cmdSize, void *pCmdData, int replySize, void *pReplyData)
60d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    {
61d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        LOGV("commandExecuted");
62d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        Parcel data, reply;
63d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInterfaceToken(IEffectClient::getInterfaceDescriptor());
64d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInt32(cmdCode);
65d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        int size = cmdSize;
66d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        if (pCmdData == NULL) {
67d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            size = 0;
68d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        }
69d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInt32(size);
70d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        if (size) {
71d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            data.write(pCmdData, size);
72d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        }
73d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        size = replySize;
74d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        if (pReplyData == NULL) {
75d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            size = 0;
76d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        }
77d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        data.writeInt32(size);
78d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        if (size) {
79d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            data.write(pReplyData, size);
80d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        }
81d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        remote()->transact(COMMAND_EXECUTED, data, &reply, IBinder::FLAG_ONEWAY);
82d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    }
83d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
84d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent};
85d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
86d71a1be83ff31cdb6599c351f9832cefc8d447baEric LaurentIMPLEMENT_META_INTERFACE(EffectClient, "android.media.IEffectClient");
87d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
88d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ----------------------------------------------------------------------
89d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
90d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurentstatus_t BnEffectClient::onTransact(
91d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
92d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent{
93d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    switch(code) {
94d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        case CONTROL_STATUS_CHANGED: {
95d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            LOGV("CONTROL_STATUS_CHANGED");
96d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            CHECK_INTERFACE(IEffectClient, data, reply);
97d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            bool hasControl = (bool)data.readInt32();
98d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            controlStatusChanged(hasControl);
99d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            return NO_ERROR;
100d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        } break;
101d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        case ENABLE_STATUS_CHANGED: {
102d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            LOGV("ENABLE_STATUS_CHANGED");
103d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            CHECK_INTERFACE(IEffectClient, data, reply);
104d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            bool enabled = (bool)data.readInt32();
105d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            enableStatusChanged(enabled);
106d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            return NO_ERROR;
107d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        } break;
108d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        case COMMAND_EXECUTED: {
109d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            LOGV("COMMAND_EXECUTED");
110d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            CHECK_INTERFACE(IEffectClient, data, reply);
111d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            int cmdCode = data.readInt32();
112d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            int cmdSize = data.readInt32();
113d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            char *cmd = NULL;
114d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            if (cmdSize) {
115d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                cmd = (char *)malloc(cmdSize);
116d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                data.read(cmd, cmdSize);
117d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            }
118d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            int replySize = data.readInt32();
119d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            char *resp = NULL;
120d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            if (replySize) {
121d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                resp = (char *)malloc(replySize);
122d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                data.read(resp, replySize);
123d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            }
124d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            commandExecuted(cmdCode, cmdSize, cmd, replySize, resp);
125d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            if (cmd) {
126d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                free(cmd);
127d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            }
128d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            if (resp) {
129d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent                free(resp);
130d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            }
131d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            return NO_ERROR;
132d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        } break;
133d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent        default:
134d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent            return BBinder::onTransact(code, data, reply, flags);
135d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent    }
136d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent}
137d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
138d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent// ----------------------------------------------------------------------------
139d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
140d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent}; // namespace android
141d71a1be83ff31cdb6599c351f9832cefc8d447baEric Laurent
142