Home | History | Annotate | Download | only in libaudioclient
      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 
     25 namespace android {
     26 
     27 enum {
     28     CONTROL_STATUS_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
     29     ENABLE_STATUS_CHANGED,
     30     COMMAND_EXECUTED
     31 };
     32 
     33 class BpEffectClient: public BpInterface<IEffectClient>
     34 {
     35 public:
     36     explicit BpEffectClient(const sp<IBinder>& impl)
     37         : BpInterface<IEffectClient>(impl)
     38     {
     39     }
     40 
     41     void controlStatusChanged(bool controlGranted)
     42     {
     43         ALOGV("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         ALOGV("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(uint32_t cmdCode,
     60                          uint32_t cmdSize,
     61                          void *pCmdData,
     62                          uint32_t replySize,
     63                          void *pReplyData)
     64     {
     65         ALOGV("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 
     90 IMPLEMENT_META_INTERFACE(EffectClient, "android.media.IEffectClient");
     91 
     92 // ----------------------------------------------------------------------
     93 
     94 status_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             ALOGV("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             ALOGV("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             ALOGV("COMMAND_EXECUTED");
    114             CHECK_INTERFACE(IEffectClient, data, reply);
    115             uint32_t cmdCode = data.readInt32();
    116             uint32_t cmdSize = data.readInt32();
    117             char *cmd = NULL;
    118             if (cmdSize) {
    119                 cmd = (char *)malloc(cmdSize);
    120                 data.read(cmd, cmdSize);
    121             }
    122             uint32_t replySize = data.readInt32();
    123             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