Home | History | Annotate | Download | only in binding
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "AAudio"
     18 //#define LOG_NDEBUG 0
     19 #include <utils/Log.h>
     20 
     21 #include <stdint.h>
     22 
     23 #include <sys/mman.h>
     24 #include <binder/Parcel.h>
     25 #include <binder/Parcelable.h>
     26 
     27 #include <aaudio/AAudio.h>
     28 
     29 #include "binding/AAudioStreamConfiguration.h"
     30 #include "binding/AAudioStreamRequest.h"
     31 
     32 using android::NO_ERROR;
     33 using android::status_t;
     34 using android::Parcel;
     35 using android::Parcelable;
     36 
     37 using namespace aaudio;
     38 
     39 AAudioStreamRequest::AAudioStreamRequest()
     40     : mConfiguration()
     41     {}
     42 
     43 AAudioStreamRequest::~AAudioStreamRequest() {}
     44 
     45 status_t AAudioStreamRequest::writeToParcel(Parcel* parcel) const {
     46     status_t status = parcel->writeInt32((int32_t) mUserId);
     47     if (status != NO_ERROR) goto error;
     48 
     49     status = parcel->writeBool(mSharingModeMatchRequired);
     50     if (status != NO_ERROR) goto error;
     51 
     52     status = parcel->writeBool(mInService);
     53     if (status != NO_ERROR) goto error;
     54 
     55     status = mConfiguration.writeToParcel(parcel);
     56     if (status != NO_ERROR) goto error;
     57 
     58     return NO_ERROR;
     59 
     60 error:
     61     ALOGE("AAudioStreamRequest.writeToParcel(): write failed = %d", status);
     62     return status;
     63 }
     64 
     65 status_t AAudioStreamRequest::readFromParcel(const Parcel* parcel) {
     66     int32_t temp;
     67     status_t status = parcel->readInt32(&temp);
     68     if (status != NO_ERROR) goto error;
     69     mUserId = (uid_t) temp;
     70 
     71     status = parcel->readBool(&mSharingModeMatchRequired);
     72     if (status != NO_ERROR) goto error;
     73 
     74     status = parcel->readBool(&mInService);
     75     if (status != NO_ERROR) goto error;
     76 
     77     status = mConfiguration.readFromParcel(parcel);
     78     if (status != NO_ERROR) goto error;
     79 
     80     return NO_ERROR;
     81 
     82 error:
     83     ALOGE("AAudioStreamRequest.readFromParcel(): read failed = %d", status);
     84     return status;
     85 }
     86 
     87 aaudio_result_t AAudioStreamRequest::validate() const {
     88     return mConfiguration.validate();
     89 }
     90 
     91 void AAudioStreamRequest::dump() const {
     92     ALOGD("AAudioStreamRequest mUserId    = %d", mUserId);
     93     ALOGD("AAudioStreamRequest mProcessId = %d", mProcessId);
     94     ALOGD("AAudioStreamRequest mSharingModeMatchRequired = %d", mSharingModeMatchRequired);
     95     ALOGD("AAudioStreamRequest mInService = %d", mInService);
     96     mConfiguration.dump();
     97 }
     98